Example #1
0
        private void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            __DEBUGPF__();

            if (bIsLast)
            {
                // 保存会话参数
                FRONT_ID   = pRspUserLogin.FrontID;
                SESSION_ID = pRspUserLogin.SessionID;
                QUOTE_REF  = "1";
                int iNextOrderRef = 0;
                if (!string.IsNullOrEmpty(pRspUserLogin.MaxOrderRef))
                {
                    iNextOrderRef = Convert.ToInt32(pRspUserLogin.MaxOrderRef);
                }
                iNextOrderRef++;
                iOrderRef = iNextOrderRef;

                ///获取当前交易日
                HandleStatusInternal("CTP获取当前交易日 = " + trader.GetTradingDay());

                ///投资者结算结果确认
                ReqSettlementInfoConfirm();

                // 通知登录结果
                if (HandleLoginDel != null)
                {
                    HandleLoginDel(true);
                }
            }
        }
        private void ReaderOnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            this.IsLogin = true;
            Console.WriteLine(string.Format("CTP行情服务登录成功。{0}", AccountInfo.MarketDataAddress));

            SubscribeMarketData();
        }
Example #3
0
 public override void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo.ErrorID != 0)
     {
         LogCenter.Error("交易登录失败:" + pRspInfo.ErrorMsg);
         return;
     }
     LogCenter.Log("交易登录成功");
     AccountCenter.Instance.IsTDLogin = true;
     this.instruments.Clear();
     LogCenter.Log("请求查询合约");
     int i = this.ReqQryInstrument(new ThostFtdcQryInstrumentField(), 0);
     if (i != 0)
     {
         LogCenter.Error("请求查询合约错误:" + CTPErrorHelper.GetError(i));
     }
     var field = new ThostFtdcSettlementInfoConfirmField
     {
         BrokerID = AccountCenter.Instance.Account.BrokerID,
         InvestorID = AccountCenter.Instance.Account.InvestorID,
         ConfirmDate = DateTime.Today.ToString(),
         ConfirmTime = DateTime.Now.ToLongTimeString()
     };
     LogCenter.Log("投资者结算结果确认");
     i = this.ReqSettlementInfoConfirm(field, 0);
     if (i != 0)
     {
         LogCenter.Error("投资者结算结果确认错误:" + CTPErrorHelper.GetError(i));
     }
 }
Example #4
0
        void _trade_OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (pRspInfo.ErrorID != 0)
            {
                this.OnLog(string.Format("交易登录失败: 代码: {0}, 消息: {1}", pRspInfo.ErrorID, pRspInfo.ErrorMsg));
            }
            else
            {
                this.OnLog("交易登录成功");
                this._session.FrontID   = pRspUserLogin.FrontID;
                this._session.SessionID = pRspUserLogin.SessionID;
                if (!string.IsNullOrEmpty(pRspUserLogin.MaxOrderRef))
                {
                    this._session.OrderRef = Convert.ToInt32(pRspUserLogin.MaxOrderRef);
                }
                var orderRef = this._session.NextOrderRef();
                this._trade.ReqSettlementInfoConfirm(new ThostFtdcSettlementInfoConfirmField {
                    BrokerID = this._config.BrokerId, InvestorID = this._config.Account, ConfirmDate = DateTime.Now.ToString("yyyyMMdd"), ConfirmTime = DateTime.Now.ToString("HH:mm:ss")
                }, this._session.NextRequestID());

                this.QueryOrders();
                this.QueryAccount();
                this.QueryPositions();
            }
            this._asyncWaiter.Set();
        }
Example #5
0
        public override void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (pRspInfo.ErrorID != 0)
            {
                LogCenter.Error("交易登录失败:" + pRspInfo.ErrorMsg);
                return;
            }
            LogCenter.Log("交易登录成功");
            AccountCenter.Instance.IsTDLogin = true;
            this.instruments.Clear();
            LogCenter.Log("请求查询合约");
            int i = this.ReqQryInstrument(new ThostFtdcQryInstrumentField(), 0);

            if (i != 0)
            {
                LogCenter.Error("请求查询合约错误:" + CTPErrorHelper.GetError(i));
            }
            var field = new ThostFtdcSettlementInfoConfirmField
            {
                BrokerID    = AccountCenter.Instance.Account.BrokerID,
                InvestorID  = AccountCenter.Instance.Account.InvestorID,
                ConfirmDate = DateTime.Today.ToString(),
                ConfirmTime = DateTime.Now.ToLongTimeString()
            };

            LogCenter.Log("投资者结算结果确认");
            i = this.ReqSettlementInfoConfirm(field, 0);
            if (i != 0)
            {
                LogCenter.Error("投资者结算结果确认错误:" + CTPErrorHelper.GetError(i));
            }
        }
Example #6
0
 private void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (bIsLast && !IsErrorRspInfo(pRspInfo))
     {
         ///获取当前交易日
         _logger.Info("--->>> 获取当前交易日 = " + api.GetTradingDay());
         // 请求订阅行情
         SubscribeMarketData();
     }
 }
Example #7
0
 void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     __DEBUGPF__();
     if (bIsLast && !IsErrorRspInfo(pRspInfo))
     {
         ///获取当前交易日
         Console.WriteLine("--->>> 获取当前交易日 = " + api.GetTradingDay());
         // 请求订阅行情
         SubscribeMarketData();
     }
 }
Example #8
0
 void _market_OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo.ErrorID != 0)
     {
         this.OnLog(string.Format("行情登录失败: 代码: {0}, 消息: {1}", pRspInfo.ErrorID, pRspInfo.ErrorMsg));
     }
     else
     {
         this.OnLog("行情登录成功");
     }
     this._asyncWaiter.Set();
 }
Example #9
0
        public override void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (pRspInfo.ErrorID != 0)
            {
                LogCenter.Error("行情登录失败:" + pRspInfo.ErrorMsg);
                return;
            }
            LogCenter.Log("行情登录成功");
            AccountCenter.Instance.IsMDLogin = true;
            int i = this.SubscribeMarketData(subscribeSet.ToArray());

            if (i != 0)
            {
                LogCenter.Error("订阅行情错误:" + CTPErrorHelper.GetError(i));
            }
        }
Example #10
0
        private void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            __DEBUGPF__();
            if (bIsLast)
            {
                bool isLogin = !IsErrorRspInfo(pRspInfo);
                if (isLogin)
                {   // 订阅
                    Subscribe();
                }

                // 通知登录结果
                if (HandleLoginDel != null)
                {
                    HandleLoginDel(isLogin);
                }
            }
        }
Example #11
0
 void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     DebugPrintFunc(new StackTrace());
     if (bIsLast && !IsErrorRspInfo(pRspInfo))
     {
         // 保存会话参数
         FRONT_ID   = pRspUserLogin.FrontID;
         SESSION_ID = pRspUserLogin.SessionID;
         int iNextOrderRef = 0;
         if (!string.IsNullOrEmpty(pRspUserLogin.MaxOrderRef))
         {
             iNextOrderRef = Convert.ToInt32(pRspUserLogin.MaxOrderRef);
         }
         iNextOrderRef++;
         ORDER_REF = Convert.ToString(iNextOrderRef);
         ///获取当前交易日
         Console.WriteLine("--->>> 获取当前交易日 = " + api.GetTradingDay());
         ///投资者结算结果确认
         ReqSettlementInfoConfirm();
     }
 }
        public void QuoteAdapter_OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin,
                                                ThostFtdcRspInfoField pRspInfo, int nRequestId, bool bIsLast)
        {
            try
            {
                Utils.ReportError(pRspInfo, "行情登录回报错误");

                if (bIsLast && Utils.IsCorrectRspInfo(pRspInfo))
                {
                    _isReady = true;
                    var temp =
                        string.Format(
                            "行情登录回报:经纪公司代码:{0},郑商所时间:{1},大商所时间:{2},中金所时间:{3},前置编号:{4},登录成功时间:{5},最大报单引用:{6},会话编号:{7},上期所时间:{8},交易系统名称:{9},交易日:{10},用户代码:{11}",
                            pRspUserLogin.BrokerID, pRspUserLogin.CZCETime, pRspUserLogin.DCETime,
                            pRspUserLogin.FFEXTime,
                            pRspUserLogin.FrontID, pRspUserLogin.LoginTime, pRspUserLogin.MaxOrderRef,
                            pRspUserLogin.SessionID, pRspUserLogin.SHFETime, pRspUserLogin.SystemName,
                            pRspUserLogin.TradingDay, pRspUserLogin.UserID);

                    Utils.WriteLine(temp, true);

                    _frontId   = pRspUserLogin.FrontID;
                    _sessionId = pRspUserLogin.SessionID;

                    //行情重连的时候,重新订阅需要的行情
                    if (SubscribedQuotes.Count > 0)
                    {
                        SubscribeMarketData(SubscribedQuotes.ToArray());
                    }
                }
                else
                {
                    Utils.WriteLine("行情登录失败", true);
                }
            }
            catch (Exception ex)
            {
                Utils.WriteException(ex);
            }
        }
Example #13
0
        void _trade_OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (pRspInfo.ErrorID != 0)
            {
                this.OnLog(string.Format("交易登录失败: 代码: {0}, 消息: {1}", pRspInfo.ErrorID, pRspInfo.ErrorMsg));
            }
            else
            {
                this.OnLog("交易登录成功");
                this._session.FrontID   = pRspUserLogin.FrontID;
                this._session.SessionID = pRspUserLogin.SessionID;
                if (!string.IsNullOrEmpty(pRspUserLogin.MaxOrderRef))
                {
                    this._session.OrderRef = Convert.ToInt32(pRspUserLogin.MaxOrderRef);
                }
                var orderRef = this._session.NextOrderRef();

                this.QueryOrders();
                this.QueryAccount();
                this.QueryPositions();
            }
            this._asyncWaiter.Set();
        }
Example #14
0
 public void QuoteAdapter_OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin,
                                         ThostFtdcRspInfoField pRspInfo, int nRequestId, bool bIsLast)
 {
     _isReady = true;
 }
Example #15
0
 public override void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.SubscribeMarketData(this.instrumentIDs);
 }
Example #16
0
 /// <summary>
 /// 登入应答
 /// </summary>
 /// <param name="pRspUserLogin"></param>
 /// <param name="pRspInfo"></param>
 /// <param name="nRequestID"></param>
 /// <param name="bIsLast"></param>
 void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     DebugPrintFunc(new StackTrace());
     if (bIsLast && !IsErrorRspInfo(pRspInfo))
     {
         //获取当前交易日
         Console.WriteLine("--->>> 获取当前交易日 = " + api.GetTradingDay());
         // 请求订阅行情
         SubscribeMarketData();
     }
 }
Example #17
0
        private void TraderAdapter_OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin,
                                                  ThostFtdcRspInfoField pRspInfo, int nRequestId, bool bIsLast)
        {
            try
            {
                if (MyUtils.IsWrongRspInfo(pRspInfo))
                {
                    MyUtils.ReportError(pRspInfo, "登录回报错误");
                    return;
                }

                if (bIsLast)
                {
                    var temp =
                        string.Format(
                            "登录回报:经纪公司代码:{0},郑商所时间:{1},大商所时间:{2},中金所时间:{3},前置编号:{4},登录成功时间:{5},最大报单引用:{6},会话编号:{7},上期所时间:{8},交易系统名称:{9},交易日:{10},用户代码:{11}",
                            pRspUserLogin.BrokerID, pRspUserLogin.CZCETime, pRspUserLogin.DCETime,
                            pRspUserLogin.FFEXTime,
                            pRspUserLogin.FrontID, pRspUserLogin.LoginTime, pRspUserLogin.MaxOrderRef,
                            pRspUserLogin.SessionID, pRspUserLogin.SHFETime, pRspUserLogin.SystemName,
                            pRspUserLogin.TradingDay, pRspUserLogin.UserID);

                    _frontId    = pRspUserLogin.FrontID;
                    _sessionId  = pRspUserLogin.SessionID;
                    _tradingDay = pRspUserLogin.TradingDay;

                    if (string.IsNullOrEmpty(pRspUserLogin.MaxOrderRef))
                    {
                        CurrentOrderRef = 0;
                    }
                    else
                    {
                        CurrentOrderRef = Convert.ToInt32(pRspUserLogin.MaxOrderRef);
                    }

                    //比较交易所时间和本地时间的偏移值
                    DateTime shfeTime;
                    try
                    {
                        shfeTime = Convert.ToDateTime(pRspUserLogin.SHFETime);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            shfeTime = Convert.ToDateTime(pRspUserLogin.CZCETime);
                        }
                        catch (Exception)
                        {
                            try
                            {
                                shfeTime = Convert.ToDateTime(pRspUserLogin.DCETime);
                            }
                            catch (Exception)
                            {
                                throw new Exception("交易所时间格式不正确");
                            }
                        }
                    }

                    MyUtils.ExchangeTimeOffset = ExchangeTime.Instance.GetSecFromDateTime(shfeTime) -
                                                 ExchangeTime.Instance.GetSecFromDateTime(DateTime.Now);
                    Thread.Sleep(1000);
                    ReqSettlementInfoConfirm(); //结算确认
                    MyUtils.IsTraderReady = true;
                }
                else
                {
                    MessageBox.Show("登录失败");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("登录失败," + ex.Message);
            }
        }
Example #18
0
 public override void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.SubscribeMarketData(this.instrumentIDs);
 }
Example #19
0
 public void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (!IsErrorRspInfo(pRspInfo))
     {
         cMainForm.SetMDLoginState((object)"已连接");
     }
 }
Example #20
0
 /// <summary>
 /// 登录成功
 /// </summary>
 /// <param name="pRspUserLogin"></param>
 /// <param name="pRspInfo"></param>
 /// <param name="nRequestID"></param>
 /// <param name="bIsLast"></param>
 public void HandleOnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     Console.WriteLine("登录成功");
 }
Example #21
0
 public override void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.instruments.Clear();
     this.ReqQryInstrument(new ThostFtdcQryInstrumentField(), 0);
 }
Example #22
0
 /// <summary>
 /// 登录回调
 /// </summary>
 /// <param name="pDepthMarketData"></param>
 public void HandleOnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
 }
Example #23
0
 void trader_OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo.ErrorID == 0)
     {
         this.SetMsg("正在查询结算结果确认信息……");
         try
         {
             Thread.Sleep(1000);
             this.trader.ReqQrySettlementInfoConfirm(new ThostFtdcQrySettlementInfoConfirmField(), requestID++);
         }
         catch (Exception exp)
         {
             this.SetMsg("结算结果确认信息查询失败," + exp.Message);
         }
     }
     else
     {
         this.SetMsg(pRspInfo.ErrorMsg);
     }
 }
Example #24
0
        /// <summary>
        /// 用户登录请求答应
        /// </summary>
        /// <param name="pRspUserLogin"></param>
        /// <param name="pRspInfo"></param>
        /// <param name="nRequestID"></param>
        /// <param name="bIsLast"></param>
        void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            DebugPrintFunc(new StackTrace());
            if (bIsLast && !IsErrorRspInfo(pRspInfo))
            {
                // 保存会话参数
                FRONT_ID = pRspUserLogin.FrontID;
                SESSION_ID = pRspUserLogin.SessionID;
                int iNextOrderRef = 0;
                if (!string.IsNullOrEmpty(pRspUserLogin.MaxOrderRef))
                    iNextOrderRef = Convert.ToInt32(pRspUserLogin.MaxOrderRef);
                iNextOrderRef++;
                ORDER_REF = Convert.ToString(iNextOrderRef);
                //获取当前交易日
                Console.WriteLine("--->>> 获取当前交易日 = " + api.GetTradingDay());

                //请求查询结算信息确认
                ReqQrySettlementInfoConfirm();
            }
        }
Example #25
0
        private void CtpTrader_OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            autoResetEventLogin.Set();

            orderRef = Math.Max(orderRef, long.Parse(pRspUserLogin.MaxOrderRef.Trim()));
        }
Example #26
0
 public override void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.instruments.Clear();
     this.ReqQryInstrument(new ThostFtdcQryInstrumentField(), 0);
 }
Example #27
0
 ///登录请求响应
 public void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (!IsErrorRspInfo(pRspInfo))
     {
         cMainForm.SetTDLoginState((object)"已连接");
         cMainForm.iOrderRefID = Int32.Parse(pRspUserLogin.MaxOrderRef);
         cMainForm.iSessionID = pRspUserLogin.SessionID;
         cMainForm.iFrontID = pRspUserLogin.FrontID;
     }
 }
Example #28
0
 public override void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo.ErrorID != 0)
     {
         LogCenter.Error("行情登录失败:" + pRspInfo.ErrorMsg);
         return;
     }
     LogCenter.Log("行情登录成功");
     AccountCenter.Instance.IsMDLogin = true;
     int i = this.SubscribeMarketData(subscribeSet.ToArray());
     if (i != 0)
     {
         LogCenter.Error("订阅行情错误:" + CTPErrorHelper.GetError(i));
     }
 }
Example #29
0
 void marketer_OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.SetMsg("行情主机登陆成功!");
     this.DialogResult = DialogResult.OK;
 }