Пример #1
0
        public void Initialize()
        {
            _api             = new MarketApi(_brokerID, _frontAddr);
            _api.OnRspError += new MarketApi.RspError((ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) =>
            {
                Console.WriteLine("ErrorID: {0}, ErrorMsg: {1}", pRspInfo.ErrorID, pRspInfo.ErrorMsg);
            });
            _api.OnFrontConnected += new MarketApi.FrontConnected(() =>
            {
                _isConnected = true;
                _api.UserLogin(-3, _investor, _password);
            });
            _api.OnRspUserLogin += new MarketApi.RspUserLogin((ref CThostFtdcRspUserLoginField pRspUserLogin,
                                                               ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) =>
            {
                _isLogin = true;
            });
            _api.OnRspUserLogout += new MarketApi.RspUserLogout((ref CThostFtdcUserLogoutField pRspUserLogout,
                                                                 ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) =>
            {
                _isLogin = false;
                _api.Disconnect();
            });
            _api.OnFrontDisconnected += new MarketApi.FrontDisconnected((int nReasion) =>
            {
                _isConnected = false;
            });

            _api.Connect();
            Thread.Sleep(200);
        }
Пример #2
0
 public void Cleanup()
 {
     if (_isLogin)
     {
         _api.UserLogout(-4);
     }
     else if (_isConnected)
     {
         _api.Disconnect();
     }
     Thread.Sleep(100);
 }
Пример #3
0
        public void Initialize()
        {
            Console.WriteLine("CTP行情订阅初始化");
            _api             = new MarketApi(_brokerID, _frontAddr);
            _api.OnRspError += new MarketApi.RspError((ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) =>
            {
                Console.WriteLine("ErrorID: {0}, ErrorMsg: {1}", pRspInfo.ErrorID, pRspInfo.ErrorMsg);
            });

            _api.OnFrontConnected += new MarketApi.FrontConnected(() =>
            {
                Console.WriteLine("连接成功");
                _api.UserLogin(-3, _investor, _password);
            });

            _api.OnRspUserLogin += new MarketApi.RspUserLogin((ref CThostFtdcRspUserLoginField pRspUserLogin,
                                                               ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) =>
            {
                if (_isLogin == false)
                {
                    _isLogin = true;
                    _api.SubscribeMarketData(this._codeList);
                    Console.WriteLine("   ");
                    Console.WriteLine("***********************************************");
                    Console.WriteLine("*****  CTP行情接收中,请勿关闭窗口!!!  *****");
                    Console.WriteLine("*****  CTP行情接收中,请勿关闭窗口!!!  *****");
                    Console.WriteLine("*****  CTP行情接收中,请勿关闭窗口!!!  *****");
                    Console.WriteLine("***********************************************");
                    Console.WriteLine("   ");
                }
            });

            _api.OnRspUserLogout += new MarketApi.RspUserLogout((ref CThostFtdcUserLogoutField pRspUserLogout,
                                                                 ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) =>
            {
                _isLogin = false;
                _api.Disconnect();
            });

            _api.OnFrontDisconnected += new MarketApi.FrontDisconnected((int nReasion) =>
            {
                _isLogin = false;
            });

            _api.OnHeartBeatWarning += new MarketApi.HeartBeatWarning((int nTimeLapse) =>
            {
                Console.WriteLine(DateTime.Now.ToString());
                _api.Connect();
            });

            _api.OnRspSubMarketData += new MarketApi.RspSubMarketData((ref CThostFtdcSpecificInstrumentField pSpecificInstrument,
                                                                       ref CThostFtdcRspInfoField pRspInfo, int nRequestID, byte bIsLast) =>
            {
                Console.WriteLine("订阅{0}成功", pSpecificInstrument.InstrumentID);
                Thread.Sleep(10);
            });

            _api.OnRtnDepthMarketData += new MarketApi.RtnDepthMarketData((ref CThostFtdcDepthMarketDataField pDepthMarketData) =>
            {
                try
                {
                    OnReceiveHQ(pDepthMarketData);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            });

            _api.Connect();
            Console.WriteLine("初始化完成");
        }
Пример #4
0
 /// <summary>
 /// 断开连接
 /// </summary>
 /// <param name="callback">断开连接回调</param>
 public void Disconnect(DataCallback callback)
 {
     AddCallback(callback, -2);
     _isConnected = false;
     _api.Disconnect();
 }
Пример #5
0
 /// <summary>
 /// 断开连接
 /// </summary>
 /// <param name="callback">断开连接回调</param>
 public void Disconnect(DataCallback callback)
 {
     AddCallback(callback, -2);
     _api.Disconnect();
 }