Exemplo n.º 1
0
 public void Stop()
 {
     if (m_quoteDriver != null)
     {
         m_quoteDriver.Logout();
         m_quoteDriver.DisConnectServer();
     }
 }
Exemplo n.º 2
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);
            }
        }