Exemplo n.º 1
0
        /// <summary>
        /// 启动行情接收。
        /// </summary>
        /// <param name="monitorMarketes">监控市场。</param>
        public void Start(List <USeMarket> monitorMarketes)
        {
            List <USeInstrument> subList = null;

            try
            {
                subList           = GetSubscribeInstruments(monitorMarketes);
                m_instrumentCount = subList.Count;
                m_instrumentDic.Clear();
                foreach (USeInstrument instrument in subList)
                {
                    m_instrumentDic.Add(instrument.InstrumentCode, instrument.Market);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("获取合约列表失败," + ex.Message);
            }

            CtpQuoteDriver quoteDriver = null;

            try
            {
                quoteDriver = new CtpQuoteDriver(m_config.QuoteAddress, m_config.QuotePort);
                quoteDriver.ConnectServer();
                quoteDriver.Login(m_config.BrokerID, m_config.Account, m_config.PassWord);
                quoteDriver.OnMarketDataChanged  += QuoteDriver_OnMarketDataChanged;
                quoteDriver.OnDriverStateChanged += QuoteDriver_OnDriverStateChanged;
                //quoteDriver.Notify += QuoteDriver_Notify;

                quoteDriver.Subscribe(subList);
                //quoteDriver.Subscribe(new List<USeInstrument>() {
                //    new USeInstrument("p1711", "p1707", USeMarket.DCE) });

                m_quoteDriver = quoteDriver;
            }
            catch (Exception ex)
            {
                if (quoteDriver != null)
                {
                    //quoteDriver.Logout();
                    quoteDriver.DisConnectServer();
                }


                throw new Exception("订阅行情失败," + ex.Message);
            }
        }
Exemplo n.º 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;
        }