private async void AddQuote()
        {
            string quote = contractTextBox.SelectedItem == null ? contractTextBox.Filter : contractTextBox.SelectedItem.ToString();

            if (!FutureOptionList.Any((c) => string.Compare(c.Contract, quote, true) == 0))
            {
                MessageBox.Show("输入合约" + quote + "不存在");
                contractTextBox.Filter = string.Empty;
                return;
            }

            ClientDbContext.SaveMarketContract(MarketDataHandler.MessageWrapper.User.Id,
                                               quote, FilterSettingsWin.FilterId);

            var item = QuoteVMCollection.FirstOrDefault(c => c.Contract == quote);

            if (item != null)
            {
                quoteListView.SelectedItem = item;
            }
            else
            {
                var mktDataVM = await MarketDataHandler.SubMarketDataAsync(quote);

                if (mktDataVM != null)
                {
                    QuoteVMCollection.Add(mktDataVM);
                }
            }
        }
        public virtual async void LoadUserContracts()
        {
            var userId = MarketDataHandler.MessageWrapper?.User?.Id;

            if (userId == null)
            {
                return;
            }

            var contracts = ClientDbContext.GetUserContracts(userId, FilterSettingsWin.FilterId).Select(c => new ContractKeyVM(string.Empty, c));

            if (contracts.Any())
            {
                try
                {
                    var list = await MarketDataHandler.SubMarketDataAsync(contracts);

                    foreach (var mktVM in list)
                    {
                        Dispatcher.Invoke(() => QuoteVMCollection.Add(mktVM));
                    }
                }
                catch
                { }
            }
        }
예제 #3
0
 private async void LoadMarketData(string contract)
 {
     if (MarketDataHandler.MessageWrapper.HasSignIn)
     {
         _marketDataList.Add(await MarketDataHandler.SubMarketDataAsync(contract));
         //await Task.Run(async () =>
         // {
         //     _marketDataList.Add(await MarketDataHandler.SubMarketDataAsync(contract));
         // });
     }
 }
예제 #4
0
        public static void Subscribe(string symbol, MarketDataHandler handler)
        {
            bool subscribe = false;

            if (s_Subscriptions.TryGetValue(symbol, out var data) == false)
            {
                data    = new SubscriptionData();
                data.ID = AllocateID();
                s_Subscriptions.Add(symbol, data);

                subscribe = true;
            }

            data.Handlers.Add(handler);

            if (subscribe)
            {
                MarketData_Subscribe(symbol, data.ID, s_MarketDataPrintHandlerPtr);
            }
        }
        private async void LoadContract()
        {
            if (FastOrderContract.SelectedItem == null)
            {
                FastOrderContract.SelectedItem = FastOrderContract.Filter ?? string.Empty;
            }

            var contract = FastOrderContract.SelectedItem.ToString();

            if (FutureContractList.Any(c => c.Contract == contract))
            {
                OrderVM.Contract = contract;
                var quote = OrderVM.Contract;
                var item  = await MarketDataHandler.SubMarketDataAsync(quote);

                if (item != null)
                {
                    stackPanelPrices.DataContext = item;
                    var contractInfo = ClientDbContext.FindContract(quote);
                    LimitTxt.Increment       = contractInfo == null ? 1 : contractInfo.PriceTick;
                    checkBox.IsEnabled       = true;
                    radioButtonBuy.IsChecked = true;
                    //radioButtonSell.IsChecked = false;
                    RadioA.IsChecked = true;
                    //RadioB.IsChecked = false;
                    //RadioC.IsChecked = false;
                    LimitTxt.SetBinding(DoubleUpDown.ValueProperty, new Binding("AskPrice.Value")
                    {
                        Mode = BindingMode.OneWay
                    });
                }
            }
            else
            {
                checkBox.IsChecked = false;
                checkBox.IsEnabled = false;
            }
        }
        public void OnPositionSelected(PositionVM positionVM)
        {
            if (positionVM != null)
            {
                portofolioCB.Text = positionVM.Portfolio;
                if (positionVM.Direction == PositionDirectionType.PD_SHORT)
                {
                    radioButtonBuy.IsChecked = true;
                    //OrderVM.Direction = DirectionType.BUY;
                }
                else
                {
                    radioButtonSell.IsChecked = true;
                    //OrderVM.Direction = DirectionType.SELL;
                }
                if (positionVM.Position != 0)
                {
                    if (positionVM.Exchange == "SHFE")
                    {
                        if (positionVM.TodayPosition != 0)
                        {
                            RadioC.IsChecked = true;
                            SizeTxt.Value    = positionVM.TodayPosition;
                        }
                        else
                        {
                            RadioB.IsChecked = true;
                            SizeTxt.Value    = positionVM.YdPosition;
                        }
                    }
                    else
                    {
                        RadioB.IsChecked = true;
                        SizeTxt.Value    = positionVM.Position;
                    }
                }
                OrderVM.Contract = positionVM.Contract;
                var quote = OrderVM.Contract;
                if (quote != null)
                {
                    checkBox.IsEnabled = true;
                    //radioButtonBuy.IsChecked = true;
                    //radioButtonSell.IsChecked = false;
                    //RadioA.IsChecked = true;
                    //RadioB.IsChecked = false;
                    //RadioC.IsChecked = false;
                    FastOrderContract.SelectedItem = quote;
                    //OrderVM.Volume = positionVM.Position;
                    Task.Run(async() =>
                    {
                        var item = await MarketDataHandler.SubMarketDataAsync(quote);
                        if (item != null)
                        {
                            Dispatcher.Invoke(() =>
                            {
                                stackPanelPrices.DataContext = item;
                                var contractInfo             = ClientDbContext.FindContract(quote);
                                LimitTxt.Increment           = contractInfo == null ? 1 : contractInfo.PriceTick;
                                if (radioButtonBuy.IsChecked.Value)
                                {
                                    if (LabelAskPrice.Content != null)
                                    {
                                        LimitTxt.Value = double.Parse(LabelAskPrice.Content.ToString());
                                    }
                                }
                                else if (radioButtonSell.IsChecked.Value)
                                {
                                    if (LabelBidPrice.Content != null)
                                    {
                                        LimitTxt.Value = double.Parse(LabelBidPrice.Content.ToString());
                                    }
                                }
                                if (checkBox.IsChecked.Value)
                                {
                                    LimitTxt.Increment = null;
                                }
                            });
                        }
                    });

                    //else
                    //{
                    //    MessageHandlerContainer.DefaultInstance.Get<MarketDataHandler>().SubMarketData(quote);
                    //}

                    //OrderVM.OpenClose = OrderOpenCloseType.CLOSE;

                    //if (positionVM.Direction == PositionDirectionType.PD_SHORT)
                    //{
                    //    OrderVM.Direction = DirectionType.BUY;
                    //}
                    //else
                    //{
                    //    OrderVM.Direction = DirectionType.SELL;
                    //}
                }
            }
        }