Esempio n. 1
0
        private void ContextMenu_Loaded(object sender, RoutedEventArgs e)
        {
            ContextMenu item = sender as ContextMenu;

            if (item == null)
            {
                return;
            }
            FuturesViewModel stock = item.DataContext as FuturesViewModel;

            if (stock == null)
            {
                return;
            }
            var model = TradeInfoHelper.OptionalModelList.FirstOrDefault(o => string.Equals(o.contract_id, stock.ContractCode));

            if (model == null)
            {
                stock.IsOptionalStock = false;
            }
            else
            {
                stock.IsOptionalStock      = true;
                stock.OptionalSerialNumber = model.serial_number;
            }
        }
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            if (_futuresServices.FuturesViewModelExists((Guid)id))
            {
                FuturesViewModel futuresViewModel = await _futuresServices.GetFuture(id);

                return(View(futuresViewModel));
            }
            return(NotFound());
        }
Esempio n. 3
0
        private async Task <int> UpdateRefeerFuture(FuturesViewModel futures, decimal gain)
        {
            decimal refeerPerc = (decimal)1.01;

            if (futures.FinalResult == (decimal)0.00)
            {
                futures.FinalResult = futures.Capital + (gain * refeerPerc);
            }
            else
            {
                futures.FinalResult += (gain * refeerPerc);
            }
            _context.Futures.Update(futures);
            return(await _context.SaveChangesAsync());
        }
Esempio n. 4
0
        public async Task <bool> CreateFuture(FuturesViewModel model)
        {
            try
            {
                var usd = await _context.BankAccounts.FirstOrDefaultAsync(b => b.Currency == "USD");

                usd.Amount += model.Capital;
                _context.BankAccounts.Update(usd);
                _context.Futures.Add(model);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public async Task <IActionResult> Create(FuturesViewModel futuresViewModel)
        {
            if (ModelState.IsValid)
            {
                futuresViewModel.Id = Guid.NewGuid();
                var client = _clientServices.ClientExistByDni(futuresViewModel.Client.Dni);
                if (futuresViewModel.RefeerCode != null)
                {
                    var refeer = await _clientServices.GetClient(futuresViewModel.RefeerCode);

                    futuresViewModel.Refeer = refeer.Id;
                }
                if (!client)
                {
                    await _clientServices.CreateClient(futuresViewModel.Client);
                }
                else
                {
                    await _clientServices.UpdateClient(futuresViewModel.Client);
                }

                if (futuresViewModel.FixRent)
                {
                    futuresViewModel.ParticipationId = null;
                }

                if (!NoLimitclient(futuresViewModel.ContractNumber))
                {
                    futuresViewModel.FinishDate = futuresViewModel.StartDate.AddMonths(6);
                }
                else
                {
                    futuresViewModel.FinishDate = futuresViewModel.StartDate.AddYears(99);
                }

                await _futuresServices.CreateFuture(futuresViewModel);

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(Problem(ModelState.IsValid.ToString(), null, 400));
            }
        }
        public void ScrollIntoView(SysCodeModel stock)
        {
            int i = 0;

            foreach (var item in CommHelper.ContractModelGroupList)
            {
                FuturesViewModel hkexmodel = item.Value.FirstOrDefault(o => string.Equals(o.ContractCode, stock.SystemName));
                if (hkexmodel != null)
                {
                    _viewModel.SelectedIndex = i;
                    TabItem tabItem  = AllFuturesQuota.Items[i] as TabItem;
                    var     dataGrid = (tabItem.Content as QuotesDataGrid).quotesDataGrid;
                    dataGrid.ScrollIntoView(hkexmodel);
                    dataGrid.SelectedItem = hkexmodel;
                    break;
                }
                i++;
            }
        }
Esempio n. 7
0
        public async Task <decimal> GetResult(FuturesViewModel futuresViewModel)
        {
            var contracts = await CountContracts();

            if (!futuresViewModel.FixRent)
            {
                futuresViewModel.FuturesUpdates = new List <FuturesUpdateViewModel>();
                List <FuturesUpdateViewModel> futuresUpdates = await GetFuturesUpdates(futuresViewModel.StartDate);

                if (futuresUpdates.Count > 0)
                {
                    foreach (var fu in futuresUpdates)
                    {
                        var gain = fu.Gain / contracts;
                        fu.GainFinal = ((futuresViewModel.Capital + gain) / (futuresViewModel.Participation.Percentage / 100));
                        futuresViewModel.FuturesUpdates.Add(fu);
                    }

                    decimal fuGain = 0;

                    foreach (var fu in futuresUpdates)
                    {
                        var gain = fu.Gain / contracts;
                        fuGain += ((futuresViewModel.Capital + gain) / (futuresViewModel.Participation.Percentage / 100));
                    }

                    futuresViewModel.FinalResult += fuGain;

                    if (futuresViewModel.ContractNumber == (int)SpecialClients.Uno)
                    {
                        var futuresWithFixed = await GetContracts(true);

                        futuresViewModel.FinalResult = FinalResult(futuresWithFixed, futuresViewModel.FinalResult);
                    }
                }
                else
                {
                    return(futuresViewModel.Capital);
                }
            }
            return(futuresViewModel.FinalResult);
        }
Esempio n. 8
0
        //    /// <summary>
        //    /// 后退
        //    /// </summary>
        //    public ICommand BackCommand { get { return new RelayCommand(BackExecuteChanged, BackCanExecuteChanged); } }
        //    public void BackExecuteChanged()
        //    {
        //        BackButtonAction();
        //    }
        //    public bool BackCanExecuteChanged()
        //    {
        //        return true;
        //    }
        //    /// <summary>
        //    /// 起始页
        //    /// </summary>
        //    public ICommand HomeCommand { get { return new RelayCommand(HomeExecuteChanged, HomeCanExecuteChanged); } }
        //    public void HomeExecuteChanged()
        //    {
        //        IsInternationalCheck = true;

        //    }
        //    public bool HomeCanExecuteChanged()
        //    {
        //        return true;
        //    }
        //    /// <summary>
        //    /// 放大
        //    /// </summary>
        //    public ICommand EnlargeCommand { get { return new RelayCommand(EnlargeExecuteChanged, EnlargeCanExecuteChanged); } }
        //    public void EnlargeExecuteChanged()
        //    {
        //        SetDataGridStyle(1);
        //    }
        //    public bool EnlargeCanExecuteChanged()
        //    {
        //        return true;
        //    }
        //    /// <summary>
        //    /// 缩小
        //    /// </summary>
        //    public ICommand NarrowCommand { get { return new RelayCommand(NarrowExecuteChanged, NarrowCanExecuteChanged); } }
        //    public void NarrowExecuteChanged()
        //    {
        //        SetDataGridStyle(2);
        //    }
        //    public bool NarrowCanExecuteChanged()
        //    {
        //        return true;
        //    }

        public void AddOptionalData(OptionalContractModel item)
        {
            int seq       = TradeInfoHelper.OptionalModelList.Count;
            var datamodel = TradeInfoHelper.ContractModelList.FirstOrDefault(o => string.Equals(o.contractCode, item.contract_id));

            if (datamodel != null)
            {
                var viewModel = new FuturesViewModel(datamodel);
                viewModel.Seq                  = seq;
                viewModel.IsOptionalStock      = true;
                viewModel.OptionalSerialNumber = item.serial_number;
                QuotationEntity quotesmodel = null;
                lock (TradeInfoHelper.SubscribedContractList)
                {
                    quotesmodel = TradeInfoHelper.SubscribedContractList.FirstOrDefault(o => string.Equals(o.cd, item.contract_id));
                }
                if (quotesmodel != null)
                {
                    //  ScoketManager.GetInstance().UpdateModelInfo(viewModel, quotesmodel);
                }
                OptionalList.Add(viewModel);
                SetOptionalList();
            }
        }
Esempio n. 9
0
 public async Task <int> RetireFuture(FuturesViewModel model)
 {
     _context.Futures.Update(model);
     return(await _context.SaveChangesAsync());
 }
Esempio n. 10
0
 private void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     try
     {
         var trademodel = viewModel.TradeQuotesViewModel;
         if (trademodel.IsOptionalCheck && trademodel.OptionalList.Count > 0)
         {
             int rowIndex = -1;
             //int i = 0;
             List <string> subList  = new List <string>();
             List <string> viewList = new List <string>();
             this.Optional.Dispatcher.Invoke(new Action(() =>
             {
                 #region 自选
                 if (Optional.quotesDataGrid.Items.Count > 0)
                 {
                     for (int a = 0; a < Optional.quotesDataGrid.Items.Count; a++)
                     {
                         var item = Optional.quotesDataGrid.Items[a];
                         var Row  = (DataGridRow)Optional.quotesDataGrid.ItemContainerGenerator.ContainerFromItem(item);
                         if (Row != null)
                         {
                             if (Row.TransformToVisual(Optional.quotesDataGrid).Transform(new Point(0, 0)).Y + Row.ActualHeight >= Optional.quotesDataGrid.ActualHeight)
                             {
                                 rowIndex = a;
                                 break;
                             }
                         }
                     }
                     if (rowIndex == -1)
                     {
                         rowIndex = Optional.quotesDataGrid.Items.Count - 1;
                         if (rowIndex == -1)
                         {
                             return;
                         }
                     }
                     int j = 0;
                     do
                     {
                         if (rowIndex < 0)
                         {
                             break;
                         }
                         var Row = (DataGridRow)Optional.quotesDataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);
                         if (Row != null)
                         {
                             FuturesViewModel stock = Row.DataContext as FuturesViewModel;
                             if (stock != null)
                             {
                                 if (!viewModel.QuotesSubscribed.Contains(stock.ContractCode) && !viewModel.SubscribedStocks.Contains(stock.ContractCode))
                                 {
                                     subList.Add(stock.ContractCode);
                                     viewModel.QuotesSubscribed.Add(stock.ContractCode);
                                 }
                                 viewList.Add(stock.ContractCode);
                             }
                         }
                         rowIndex--;
                         j++;
                     } while (j < 28);
                 }
                 #endregion
             }));
             if (subList.Count > 0)
             {
                 LogHelper.Info("自选股订阅:" + string.Join(",", subList));
                 _scoketManager.SendSubscribeInfo(7, subList);
             }
             FuturesViewModel selectModel = viewModel.SelectItemViewModel;
             List <string>    unSubList   = new List <string>();
             List <string>    tempList    = viewModel.QuotesSubscribed.ToList();
             if (tempList.Count > 0)
             {
                 foreach (var item in tempList)
                 {
                     if (!string.IsNullOrEmpty(item) && !viewList.Contains(item) && !viewModel.SubscribedStocks.Contains(item) && (selectModel == null || !string.Equals(selectModel.ContractCode, item)))
                     {
                         viewModel.QuotesSubscribed.Remove(item);
                         unSubList.Add(item);
                     }
                 }
             }
             if (unSubList.Count > 0)
             {
                 LogHelper.Info("自选股反订阅:" + string.Join(",", unSubList));
                 _scoketManager.SendSubscribeInfo(8, unSubList);
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.Info("Optional:myTimer_Elapsed" + ex.ToString());
     }
 }
        private void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                var trademodel = TradeQuotesViewModel.GetInstance(null);
                if (ServerStatusInfoHelper.Instace().IsReattached)
                {
                    #region 行情重连之后执行
                    ServerStatusInfoHelper.Instace().IsReattached = false;
                    var mainViewModel = MainViewModel.GetInstance();
                    if (mainViewModel.SelectItemViewModel != null)
                    {
                        if (Application.Current != null) //判断不为空
                        {
                            Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                                                                      () =>
                            {
                                mainViewModel.SelectItemViewModel.Tick.EachDealList.Clear();
                            }));
                        }
                        _scoketManager.SendSubscribeInfo(7, mainViewModel.SelectItemViewModel.ContractCode);
                    }
                    var clearDealList = mainViewModel.QuotesSubscribed.ToList();
                    foreach (var item in clearDealList)
                    {
                        var futuresModel = _viewModel.FuturesViewModelList.FirstOrDefault(o => !string.IsNullOrEmpty(o.ExchangeDisplay) && string.Equals(o.ContractCode, item));
                        if (futuresModel != null)
                        {
                            if (futuresModel.Tick.EachDealList.Count == 0)
                            {
                                continue;
                            }
                            if (Application.Current != null) //判断不为空
                            {
                                Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                                                                          () =>
                                {
                                    futuresModel.Tick.EachDealList.Clear();
                                }));
                            }
                        }
                    }
                    mainViewModel.QuotesSubscribed.Clear();

                    LogHelper.Info("重连之后行情订阅:" + string.Join(",", mainViewModel.SubscribedStocks));
                    _scoketManager.SendSubscribeInfo(7, mainViewModel.SubscribedStocks);
                    if (mainViewModel.SelectItemViewModel != null)
                    {
                        if (Application.Current != null) //判断不为空
                        {
                            Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                                                                      () =>
                            {
                                //if (trademodel.RealTimeVisibility == Visibility.Visible || trademodel.KLineVisibility == Visibility.Visible)
                                //{
                                //    mainViewModel.SelectItemViewModel.Tick.SetEachDealList();
                                //}
                            }));
                        }
                    }
                    #endregion
                }

                if (trademodel.IsInternationalCheck)
                {
                    int rowIndex = -1;
                    //int i = 0;
                    List <string> subList       = new List <string>();
                    List <string> viewList      = new List <string>();
                    var           mainViewModel = MainViewModel.GetInstance();
                    this.AllFuturesQuota.Dispatcher.Invoke(new Action(() =>
                    {
                        TabItem tabItem = AllFuturesQuota.Items[_viewModel.SelectedIndex] as TabItem;
                        var dataGrid    = (tabItem.Content as QuotesDataGrid).quotesDataGrid;
                        if (dataGrid.Items.Count > 0)
                        {
                            for (int a = 0; a < dataGrid.Items.Count; a++)
                            {
                                var item = dataGrid.Items[a];
                                var Row  = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(item);
                                if (Row != null)
                                {
                                    if (Row.TransformToVisual(dataGrid).Transform(new Point(0, 0)).Y + Row.ActualHeight >= dataGrid.ActualHeight)
                                    {
                                        rowIndex = a;
                                        break;
                                    }
                                }
                            }
                            if (rowIndex == -1)
                            {
                                rowIndex = dataGrid.Items.Count - 1;
                                if (rowIndex == -1)
                                {
                                    return;
                                }
                            }
                            int j = 0;
                            do
                            {
                                if (rowIndex < 0)
                                {
                                    break;
                                }
                                var Row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);
                                if (Row != null)
                                {
                                    FuturesViewModel stock = Row.DataContext as FuturesViewModel;
                                    if (stock != null)
                                    {
                                        if (!mainViewModel.QuotesSubscribed.Contains(stock.ContractCode) && !mainViewModel.SubscribedStocks.Contains(stock.ContractCode))
                                        {
                                            subList.Add(stock.ContractCode);
                                            mainViewModel.QuotesSubscribed.Add(stock.ContractCode);
                                        }
                                        viewList.Add(stock.ContractCode);
                                    }
                                }
                                rowIndex--;
                                j++;
                            } while (j < 28);
                        }
                    }));
                    if (subList.Count > 0)
                    {
                        LogHelper.Info("行情订阅:" + string.Join(",", subList));
                        _scoketManager.SendSubscribeInfo(7, subList);
                    }
                    FuturesViewModel selectModel = mainViewModel.SelectItemViewModel;
                    List <string>    unSubList   = new List <string>();
                    List <string>    tempList    = mainViewModel.QuotesSubscribed.ToList();
                    if (tempList.Count > 0)
                    {
                        foreach (var item in tempList)
                        {
                            if (!string.IsNullOrEmpty(item) && !viewList.Contains(item) && !mainViewModel.SubscribedStocks.Contains(item) && (selectModel == null || !string.Equals(selectModel.ContractCode, item)))
                            {
                                mainViewModel.QuotesSubscribed.Remove(item);
                                unSubList.Add(item);
                            }
                        }
                    }
                    if (unSubList.Count > 0)
                    {
                        LogHelper.Info("行情反订阅:" + string.Join(",", unSubList));
                        _scoketManager.SendSubscribeInfo(8, unSubList);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Info("StockQuota:myTimer_Elapsed" + ex.ToString());
            }
        }