Example #1
0
        private void CTPOnRspUserLogin(ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            //避免登录错误后不断重连
            if (pRspInfo.ErrorID != 0)
            {
                _t.SetOnFrontDisconnected(null);
            }
            //else //正常登录时注册连接事件(后续自动重连时可自行登录)
            //_t.SetOnFrontConnected(CTPOnFrontConnected);

            if (pRspInfo.ErrorID == 0)
            {
                //IsLogin = true; //position中完成
                this.TradingDay = pRspUserLogin.TradingDay; // Marshal.PtrToStringAnsi(_t.GetTradingDay());
                _session        = pRspUserLogin.SessionID;
                _front          = pRspUserLogin.FrontID;
                //_orderref = pRspUserLogin.MaxOrderRef;
                _broker   = pRspUserLogin.BrokerID;
                _investor = pRspUserLogin.UserID;

                _t.ReqSettlementInfoConfirm(_broker, _investor);
            }
            else
            {
                _OnRspUserLogin?.Invoke(this, new IntEventArgs {
                    Value = pRspInfo.ErrorID
                });
            }
        }
Example #2
0
 private void OnConnect_callback(object sender, IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
 {
     if (null != OnConnect)
     {
         OnConnect(this, new OnConnectArgs(pApi, ref pRspUserLogin, result));
     }
 }
Example #3
0
        //public fnOnRtnForQuoteRsp OnRtnForQuoteRsp
        //{
        //    set
        //    {
        //        OnRtnForQuoteRsp_1 = value;
        //        OnRtnForQuoteRsp_2 = OnRtnForQuoteRsp_3;
        //        MdApi.CTP_RegOnRtnForQuoteRsp(_MsgQueue.Queue, OnRtnForQuoteRsp_2);
        //    }
        //}

        //private void OnRtnForQuoteRsp_3(IntPtr pMdUserApi, ref CThostFtdcForQuoteRspField pForQuoteRsp)
        //{
        //    OnRtnForQuoteRsp_1(this, pMdUserApi, ref pForQuoteRsp);
        //}

        protected override void OnConnect_3(IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
        {
            IsConnected = false;
            if (result == ConnectionStatus.Logined)
            {
                IsConnected = true;
            }
            OnConnect_1(this, pApi, ref pRspUserLogin, result);
        }
Example #4
0
 protected override void OnConnect_3(IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
 {
     IsConnected = false;
     if (result == ConnectionStatus.Confirmed)
     {
         IsConnected = true;
     }
     OnConnect_1(this, pApi, ref pRspUserLogin, result);
 }
Example #5
0
        private void OnConnect_callback(IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
        {
            _bMdConnected = (ConnectionStatus.E_logined == result);

            if (null != OnConnect)
            {
                OnConnect(this, new OnConnectArgs(pApi, ref pRspUserLogin, result));
            }
        }
Example #6
0
 private void CMdApi_OnRspUserLogin(ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (bIsLast && pRspInfo.ErrorID == 0)
     {
         _connStatus     = ConnectionStatus.Logined;
         this._sessionID = pRspUserLogin.SessionID;
         this._frontID   = pRspUserLogin.FrontID;
     }
 }
Example #7
0
 public static void onRspUserLoginMethod(ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     Console.WriteLine(pRspInfo.ErrorMsg);
     if (pRspInfo.ErrorID == 0)
     {
         isConnected = true;
     }
     Console.WriteLine("rsp login end");
 }
Example #8
0
 public virtual void OnRspUserLogin(CThostFtdcRspUserLoginField pRspUserLogin, CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (SwigDerivedClassHasMethod("OnRspUserLogin", swigMethodTypes3))
     {
         thostmdapiPINVOKE.CThostFtdcMdSpi_OnRspUserLoginSwigExplicitCThostFtdcMdSpi(swigCPtr, CThostFtdcRspUserLoginField.getCPtr(pRspUserLogin), CThostFtdcRspInfoField.getCPtr(pRspInfo), nRequestID, bIsLast);
     }
     else
     {
         thostmdapiPINVOKE.CThostFtdcMdSpi_OnRspUserLogin(swigCPtr, CThostFtdcRspUserLoginField.getCPtr(pRspUserLogin), CThostFtdcRspInfoField.getCPtr(pRspInfo), nRequestID, bIsLast);
     }
 }
Example #9
0
 /// <summary>
 /// 登录回报
 /// </summary>
 /// <param name="pRspUserLogin"></param>
 /// <param name="pRspInfo"></param>
 /// <param name="nRequestID"></param>
 /// <param name="bIsLast"></param>
 private void CTradeApi_OnRspUserLogin(ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (bIsLast && pRspInfo.ErrorID == 0)
     {
         this._connStatus  = ConnectionStatus.Logined;
         this._frontID     = pRspUserLogin.FrontID;
         this._sessionID   = pRspUserLogin.SessionID;
         this._maxOrderRef = int.Parse(pRspUserLogin.MaxOrderRef);
         this._OnConnectionStatusChanged?.Invoke(this._connStatus);
     }
 }
Example #10
0
 private static void OnRspUserLogin(
     ref CThostFtdcRspUserLoginField rspUserLogin, ref CThostFtdcRspInfoField rspInfo, int requestId, bool isLast)
 {
     if (isLast)
     {
         Console.WriteLine("User Login=========");
         Console.WriteLine("LoginTime: " + rspUserLogin.LoginTime);
         Console.WriteLine("SHFETime: " + rspUserLogin.SHFETime);
         Console.WriteLine("MaxOrderRef: " + rspUserLogin.MaxOrderRef);
         Console.WriteLine("Info:" + rspInfo.ErrorMsg);
     }
 }
Example #11
0
 public void OnRspUserLogin(CThostFtdcRspUserLoginField pRspUserLogin, CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo.ErrorID != 0)
     {
         Console.WriteLine("OnRspUserLogin Error: {0}", pRspInfo.ErrorMsg);
     }
     else
     {
         Console.WriteLine("OnRspUserLogin");
         _isReady = _isConnected;
     }
 }
Example #12
0
        private void OnConnect(IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
        {
            if (m_pMdApi == pApi)//行情
            {
                _bMdConnected = false;
                if (ConnectionStatus.E_logined == result)
                {
                    _bMdConnected = true;
                }
                //这也有个时间,但取出的时间无效
                Console.WriteLine(string.Format("MdApi:{0},{1},{2}", Clock.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), result, pRspUserLogin.LoginTime));
            }
            else if (m_pTdApi == pApi)//交易
            {
                _bTdConnected = false;

                if (ConnectionStatus.E_logined == result)
                {
                    _RspUserLogin = pRspUserLogin;

                    //用于行情记算时简化时间解码
                    _yyyyMMdd = int.Parse(pRspUserLogin.TradingDay);
                    _yyyy     = _yyyyMMdd / 10000;
                    _MM       = (_yyyyMMdd % 10000) / 100;
                    _dd       = _yyyyMMdd % 100;
                }
                else if (ConnectionStatus.E_confirmed == result)
                {
                    _bTdConnected = true;
                    //请求查询资金
                    TraderApi.TD_ReqQryTradingAccount(m_pTdApi);

                    //请求查询全部持仓
                    TraderApi.TD_ReqQryInvestorPosition(m_pTdApi, null);

                    //请求查询合约
                    _dictInstruments.Clear();
                    TraderApi.TD_ReqQryInstrument(m_pTdApi, null);
                }
                Console.WriteLine(string.Format("TdApi:{0},{1},{2}", Clock.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), result, pRspUserLogin.LoginTime));
            }

            if (
                (_bMdConnected && _bTdConnected) ||//都连上
                (!_bWantMdConnect && _bTdConnected) ||//只用分析交易连上
                (!_bWantTdConnect && _bMdConnected)   //只用分析行情连上
                )
            {
                ChangeStatus(ProviderStatus.LoggedIn);
                EmitConnectedEvent();
            }
        }
        private void UpdateLocalTime(SetTimeMode _SetLocalTimeMode, CThostFtdcRspUserLoginField pRspUserLogin)
        {
            string strNewTime;

            switch (_SetLocalTimeMode)
            {
            case SetTimeMode.None:
                return;

            case SetTimeMode.LoginTime:
                strNewTime = pRspUserLogin.LoginTime;
                break;

            case SetTimeMode.SHFETime:
                strNewTime = pRspUserLogin.SHFETime;
                break;

            case SetTimeMode.DCETime:
                strNewTime = pRspUserLogin.DCETime;
                break;

            case SetTimeMode.CZCETime:
                strNewTime = pRspUserLogin.CZCETime;
                break;

            case SetTimeMode.FFEXTime:
                strNewTime = pRspUserLogin.FFEXTime;
                break;

            default:
                return;
            }

            try
            {
                int HH = int.Parse(strNewTime.Substring(0, 2));
                int mm = int.Parse(strNewTime.Substring(3, 2));
                int ss = int.Parse(strNewTime.Substring(6, 2));

                DateTime _dateTime    = new DateTime(_yyyy, _MM, _dd, HH, mm, ss);
                DateTime _newDateTime = _dateTime.AddMilliseconds(AddMilliseconds);
                tdlog.Info("SetLocalTime:Return:{0},{1}",
                           WinAPI.SetLocalTime(_newDateTime),
                           _newDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            }
            catch (Exception)
            {
                tdlog.Warn("{0}不能解析成时间", strNewTime);
            }
        }
 private void OnConnect_callback(object sender, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
 {
     if (null != OnConnect)
     {
         try
         {
             OnConnect(this, new OnConnectArgs(ref pRspUserLogin, result));
         }
         catch (System.Exception ex)
         {
             MessageBox.Show("TraderApiWrapper::OnConnect_callback:" + ex.ToString());
         }
     }
 }
Example #15
0
 private void CTPOnRspUserLogin(ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     //避免登录错误后不断重连
     if (pRspInfo.ErrorID != 0)
     {
         _q.SetOnFrontConnected(null);
     }
     else             //正常登录时注册连接事件(后续自动重连时可自行登录)
     {
         this.IsLogin = true;
         _q.SetOnFrontConnected(CTPOnFrontConnected);
     }
     _OnRspUserLogin?.Invoke(this, new IntEventArgs {
         Value = pRspInfo.ErrorID
     });
 }
Example #16
0
        /// <summary>
        /// 登录回调
        /// </summary>
        /// <param name="pRspUserLogin">登录返回结果</param>
        /// <param name="pRspInfo">错误信息</param>
        /// <param name="nRequestID">请求编号</param>
        /// <param name="bIsLast">是否为最后一条数据</param>
        private void OnRspUserLogin(ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo,
                                    int nRequestID, byte bIsLast)
        {
            DataResult result = new DataResult();

            if (pRspInfo.ErrorID > 0)
            {
                SetError(result, pRspInfo);
            }
            else
            {
                _api.FrontID     = pRspUserLogin.FrontID;
                _api.SessionID   = pRspUserLogin.SessionID;
                _api.MaxOrderRef = pRspUserLogin.MaxOrderRef;
                result.IsSuccess = true;
            }
            ExecuteCallback(-3, result);
        }
Example #17
0
        private unsafe void CTPOnRspUserLogin(ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            //Console.WriteLine("on CTPOnRspUserLogin    result");

            //Console.WriteLine("CThostFtdcRspUserLoginField    {0}", Marshal.SizeOf(pRspUserLogin));
            //Console.WriteLine("CThostFtdcRspInfoField    {0}", Marshal.SizeOf(pRspInfo));

            //避免登录错误后不断重连
            if (pRspInfo.ErrorID != 0)
            {
                _t.SetOnFrontDisconnected(null);
            }
            //else //正常登录时注册连接事件(后续自动重连时可自行登录)
            //_t.SetOnFrontConnected(CTPOnFrontConnected);

            if (pRspInfo.ErrorID == 0)
            {
                //IsLogin = true; //position中完成
                this.TradingDay = pRspUserLogin.TradingDay; // Marshal.PtrToStringAnsi(_t.GetTradingDay());
                _session        = pRspUserLogin.SessionID;
                _front          = pRspUserLogin.FrontID;
                //_orderref = pRspUserLogin.MaxOrderRef;
                _broker   = pRspUserLogin.BrokerID;
                _investor = pRspUserLogin.UserID;

                //Console.WriteLine("_session: " + _session);
                //Console.WriteLine("_front: " + _front);
                //Console.WriteLine("_broker: " + _broker);
                //Console.WriteLine("_investor: " + _investor);
                //Console.WriteLine("_session: " + _session);
                //Console.WriteLine("TradingDay: " + TradingDay);

                //Console.WriteLine("ErrorMsg" + pRspInfo.ErrorMsg);

                _t.ReqSettlementInfoConfirm(_broker, _investor);
                // _t.ReqQryInstrument();
            }
            else
            {
                _OnRspUserLogin?.Invoke(this, new IntEventArgs {
                    Value = pRspInfo.ErrorID
                });
            }
        }
        public override void OnRspLogin(int errorCode, TapAPIQuotLoginRspInfo info)
        {
            var rspLoginField = new CThostFtdcRspUserLoginField()
            {
                TradingDay = info.TradeDate,
                LoginTime  = info.StartTime,
                BrokerID   = "",
                UserID     = info.UserNo,
                SystemName = "esunny",
                FrontID    = 0,
                SessionID  = 0
            };

            var rspInfoField = new CThostFtdcRspInfoField()
            {
                ErrorID = errorCode
            };

            _callbackApi.OnRspUserLogin(rspLoginField, rspInfoField, 0, true);
        }
Example #19
0
 protected virtual void OnConnect_3(IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
 {
     OnConnect_1(this, pApi, ref pRspUserLogin, result);
 }
Example #20
0
        private void OnConnect_callback(IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
        {
            _bMdConnected = (ConnectionStatus.E_logined == result);

            if (null != OnConnect)
            {
                OnConnect(this, new OnConnectArgs(pApi, ref pRspUserLogin, result));
            }
        }
Example #21
0
 public OnConnectArgs(IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
 {
     this.pApi          = pApi;
     this.pRspUserLogin = pRspUserLogin;
     this.result        = result;
 }
 public void OnRspUserLogin(CThostFtdcRspUserLoginField pRspUserLogin, CThostFtdcRspInfoField pRspInfo, int nRequestID,
                            bool bIsLast)
 {
     Console.WriteLine("OnRspUserLogin");
     _isReady = true;
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(CThostFtdcRspUserLoginField obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Example #24
0
 private static void t_login(ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     Console.WriteLine("t:" + pRspInfo.ErrorMsg);
     t.ReqAuthenticate("9999", "", "client", "", "");
 }
Example #25
0
 public OnConnectArgs(IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
 {
     this.pApi = pApi;
     this.pRspUserLogin = pRspUserLogin;
     this.result = result;
 }
        private void OnConnect(IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
        {
            //用于行情记算时简化时间解码
            // 在夜盘,这个TradingDay就不靠谱了,所以不用了
            //try
            //{
            //    int _yyyyMMdd = int.Parse(pRspUserLogin.TradingDay);
            //    _yyyy = _yyyyMMdd / 10000;
            //    _MM = (_yyyyMMdd % 10000) / 100;
            //    _dd = _yyyyMMdd % 100;
            //}
            //catch (Exception)
            {
                _yyyy = DateTime.Now.Year;
                _MM   = DateTime.Now.Month;
                _dd   = DateTime.Now.Day;
            }

            if (m_pMdApi == pApi)//行情
            {
                _bMdConnected = false;
                if (ConnectionStatus.Logined == result)
                {
                    _bMdConnected = true;

                    mdlog.Info("TradingDay:{0},LoginTime:{1},SHFETime:{2},DCETime:{3},CZCETime:{4},FFEXTime:{5},FrontID:{6},SessionID:{7}",
                               pRspUserLogin.TradingDay, pRspUserLogin.LoginTime, pRspUserLogin.SHFETime,
                               pRspUserLogin.DCETime, pRspUserLogin.CZCETime, pRspUserLogin.FFEXTime,
                               pRspUserLogin.FrontID, pRspUserLogin.SessionID);

                    // 如果断线重连是使用的重新新建对象的方式,则要重新订阅
                    if (_dictAltSymbol2Instrument.Count > 0)
                    {
                        mdlog.Info("行情列表数{0},全部重新订阅", _dictAltSymbol2Instrument.Count);
                        foreach (DataRecord record in _dictAltSymbol2Instrument.Values)
                        {
                            MdApi.MD_Subscribe(m_pMdApi, record.Symbol, record.Exchange);
                        }
                    }
                }
                //这也有个时间,但取出的时间无效
                mdlog.Info("{0},{1}", result, pRspUserLogin.LoginTime);
            }
            else if (m_pTdApi == pApi)//交易
            {
                _bTdConnected = false;
                if (ConnectionStatus.Logined == result)
                {
                    _RspUserLogin = pRspUserLogin;

                    tdlog.Info("TradingDay:{0},LoginTime:{1},SHFETime:{2},DCETime:{3},CZCETime:{4},FFEXTime:{5},FrontID:{6},SessionID:{7}",
                               pRspUserLogin.TradingDay, pRspUserLogin.LoginTime, pRspUserLogin.SHFETime,
                               pRspUserLogin.DCETime, pRspUserLogin.CZCETime, pRspUserLogin.FFEXTime,
                               pRspUserLogin.FrontID, pRspUserLogin.SessionID);

                    UpdateLocalTime(SetLocalTimeMode, pRspUserLogin);
#if CTP
                }
                else if (ConnectionStatus.Confirmed == result)
                {
#endif
                    _bTdConnected = true;
                    //请求查询资金
                    TraderApi.TD_ReqQryTradingAccount(m_pTdApi);

                    //请求查询全部持仓
                    _dictPositions.Clear();
                    TraderApi.TD_ReqQryInvestorPosition(m_pTdApi, null);

                    //请求查询合约
                    _dictInstruments.Clear();
                    TraderApi.TD_ReqQryInstrument(m_pTdApi, null);

                    _dictCommissionRate.Clear();
                    _dictMarginRate.Clear();

                    timerAccount.Enabled  = true;
                    timerPonstion.Enabled = true;
                }

                tdlog.Info("{0},{1}", result, pRspUserLogin.LoginTime);
            }

            if (
                (_bMdConnected && _bTdConnected) ||//都连上
                (!_bWantMdConnect && _bTdConnected) ||//只用分析交易连上
                (!_bWantTdConnect && _bMdConnected)   //只用分析行情连上
                )
            {
                timerConnect.Enabled    = true;
                timerDisconnect.Enabled = false;//都连接上了,用不着定时断
                ChangeStatus(ProviderStatus.LoggedIn);
                isConnected = true;
                EmitConnectedEvent();
            }
        }
 public override void OnRspUserLogin(CThostFtdcRspUserLoginField pRspUserLogin, CThostFtdcRspInfoField pRspInfo, int nRequestID,
                                     bool bIsLast)
 {
     _callbackApi.OnRspUserLogin(pRspUserLogin, pRspInfo, nRequestID, bIsLast);
 }
Example #28
0
 private static void login(ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     Console.WriteLine(pRspInfo.ErrorMsg);
 }
Example #29
0
 public static void OnConnect(ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
 {
     Console.WriteLine("{0}", result);
 }
Example #30
0
 protected virtual void OnConnect_3(IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
 {
     OnConnect_1(this, pApi, ref pRspUserLogin, result);
 }
Example #31
0
        protected override void ProcessBusinessResponse(CTPResponseType responseType, IntPtr pData, CTPResponseInfo rspInfo, int requestID)
        {
            try
            {
                switch (responseType)
                {
                    #region 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
                case CTPResponseType.FrontConnectedResponse:
                {
                    this.isConnect = true;
                    if (this.isLogin == false)
                    {
                        if (this.canLogin)
                        {
                            this.canLogin = false;
                            this.UserLogin();
                            this.reconnectedCount++;
                            //if (this.reconnectedCount < this.reconnectMaxCount)
                            //{
                            //    this.canLogin = false;
                            //    this.UserLogin();
                            //    this.reconnectedCount++;
                            //}
                        }
                        else
                        {
                            //this.canLogin = true;
                            this.needLogin = true;
                        }
                    }

                    //调用事件
                    OnEventHandler(CTPResponseType.FrontConnectedResponse, new CTPEventArgs());

                    break;
                }
                    #endregion

                    #region 错误返回
                case CTPResponseType.ErrorResponse:
                {
                    CTPEventArgs obj = new CTPEventArgs();
                    obj.RequestID    = requestID;
                    obj.ResponseInfo = rspInfo;
                    //调用事件
                    OnEventHandler(CTPResponseType.ErrorResponse, obj);
                    break;
                }
                    #endregion

                    #region 连接断开返回
                case CTPResponseType.FrontDisconnectedResponse:
                {
                    this.isConnect = false;
                    this.isLogin   = false;
                    this.needLogin = false;
                    //this.canLogin = true;
                    CTPEventArgs obj = new CTPEventArgs();
                    obj.RequestID    = requestID;
                    obj.ResponseInfo = rspInfo;
                    //调用事件
                    OnEventHandler(CTPResponseType.FrontDisconnectedResponse, obj);
                    break;
                }
                    #endregion

                    #region 心跳警告返回
                case CTPResponseType.HeartBeatWarningResponse:
                {
                    CTPEventArgs obj = new CTPEventArgs();
                    obj.RequestID    = requestID;
                    obj.ResponseInfo = rspInfo;
                    //调用事件
                    OnEventHandler(CTPResponseType.HeartBeatWarningResponse, obj);
                    break;
                }
                    #endregion

                    #region 客户端认证响应
                case CTPResponseType.AuthenticateResponse:
                {
                    CTPEventArgs <CThostFtdcRspAuthenticateField> args = CreateEventArgs <CThostFtdcRspAuthenticateField>(requestID, rspInfo);

                    this.OnEventHandler(CTPResponseType.AuthenticateResponse, args);

                    break;
                }
                    #endregion

                    #region 登出返回
                case CTPResponseType.UserLogoutResponse:
                {
                    this.isLogin = false;
                    CTPEventArgs obj = new CTPEventArgs();
                    obj.RequestID    = requestID;
                    obj.ResponseInfo = rspInfo;
                    //调用事件
                    OnEventHandler(CTPResponseType.UserLogoutResponse, obj);
                    break;
                }
                    #endregion

                    #region 用户登录
                case CTPResponseType.UserLoginResponse:
                {
                    CTPEventArgs <CThostFtdcRspUserLoginField> args = CreateEventArgs <CThostFtdcRspUserLoginField>(pData, rspInfo);
                    CThostFtdcRspUserLoginField userLogin           = args.Value;


                    if (rspInfo.ErrorID == 0)
                    {
                        this.BrokerID         = userLogin.BrokerID;
                        this.FrontID          = userLogin.FrontID;
                        this.SessionID        = userLogin.SessionID;
                        this.isLogin          = true;
                        this.needLogin        = false;
                        this.canLogin         = true;
                        this.reconnectedCount = 0;
                        //this.loginTime = userLogin.LoginTime;
                    }
                    else
                    {
                        //this.canLogin = true;
                    }
                    this.OnEventHandler(CTPResponseType.UserLoginResponse, args);
                }
                break;
                    #endregion

                    #region 接收到行情数据返回
                case CTPResponseType.DepthMarketDataResponse:
                {
                    if (this == null || this.isDispose == true)
                    {
                        return;
                    }

                    CTPEventArgs <CThostFtdcDepthMarketDataField> args = CreateEventArgs <CThostFtdcDepthMarketDataField>(pData, rspInfo);

                    OnEventHandler(CTPResponseType.DepthMarketDataResponse, args);

                    break;
                }
                    #endregion

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                try
                {
                    CTPEventArgs obj = new CTPEventArgs();
                    obj.RequestID             = requestID;
                    obj.ResponseInfo          = rspInfo;
                    obj.ResponseInfo.Message += ex.StackTrace;
                    //调用事件
                    OnEventHandler(CTPResponseType.ErrorResponse, obj);
                }
                catch (Exception e)
                {
                }
            }
        }
Example #32
0
 /// <summary>
 /// 登录响应
 /// </summary>
 /// <param name="pRspUserLogin"></param>
 /// <param name="pRspInfo"></param>
 /// <param name="nRequestID"></param>
 /// <param name="bIsLast"></param>
 public virtual void OnRspUserLogin(ref CThostFtdcRspUserLoginField pRspUserLogin, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
 }
Example #33
0
 private void OnConnect_callback(object sender, IntPtr pApi, ref CThostFtdcRspUserLoginField pRspUserLogin, ConnectionStatus result)
 {
     if (null != OnConnect)
     {
         OnConnect(this, new OnConnectArgs(pApi, ref pRspUserLogin, result));
     }
 }