Beispiel #1
0
        private void QuoteDriver_OnMarketDataChanged(object sender, USe.TradeDriver.Common.USeMarketDataChangedEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new EventHandler <USeMarketDataChangedEventArgs>(QuoteDriver_OnMarketDataChanged), sender, e);
                return;
            }

            MarketDataViewModel marketModel = m_dataSource.FirstOrDefault(p => p.Instrument == e.MarketData.Instrument);

            if (marketModel != null)
            {
                marketModel.Update(e.MarketData);
                CalculateIndex();
            }
        }
Beispiel #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            Dictionary <string, List <USeInstrument> > productDic = QueryAllInstrument();
            string varieties = this.txtVarieties.Text;

            if (productDic.ContainsKey(varieties) == false)
            {
                MessageBox.Show(string.Format("品种{0}不存在", varieties));
                return;
            }

            m_dataSource.Clear();
            List <USeInstrument> subList = productDic[varieties];

            foreach (USeInstrument instrument in subList)
            {
                MarketDataViewModel marketModel = new MarketDataViewModel(instrument, false);
                m_dataSource.Add(marketModel);
            }

            USeInstrument       indexInstrument = new USeInstrument(varieties + "88888", "指数", USeMarket.SHFE);
            MarketDataViewModel indexModel      = new MarketDataViewModel(indexInstrument, true);

            m_dataSource.Add(indexModel);
            m_indexModel = indexModel;

            string address  = "180.166.11.33";
            int    port     = 41213;
            string brokerId = "4200";
            string account  = "13100110";
            string password = "******";

            CtpQuoteDriver quoteDriver = new CtpQuoteDriver(address, port);

            quoteDriver.OnMarketDataChanged += QuoteDriver_OnMarketDataChanged;
            quoteDriver.ConnectServer();
            quoteDriver.Login(brokerId, account, password);
            quoteDriver.Subscribe(subList);

            m_quoteDriver = quoteDriver;
        }