private void OnErrRtnOrderInsert(IntPtr pTraderApi, ref CThostFtdcInputOrderField pInputOrder, ref CThostFtdcRspInfoField pRspInfo)
        {
            SingleOrder order;
            string strKey = string.Format("{0}:{1}:{2}", _RspUserLogin.FrontID, _RspUserLogin.SessionID, pInputOrder.OrderRef);
            if (_OrderRef2Order.TryGetValue(strKey, out order))
            {
                tdlog.Error("交易所回应:{0},{1},开平{2},价{3},原量{4},引用{5},{6}#{7}",
                        pInputOrder.InstrumentID, pInputOrder.Direction, pInputOrder.CombOffsetFlag, pInputOrder.LimitPrice,
                        pInputOrder.VolumeTotalOriginal,
                        pInputOrder.OrderRef, pRspInfo.ErrorID, pRspInfo.ErrorMsg);

                order.Text = string.Format("{0}|{1}#{2}", order.Text.Substring(0, Math.Min(order.Text.Length, 64)), pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                EmitRejected(order, order.Text);
                //没得办法,这样全撤了状态就唯一了
                Dictionary<string, CThostFtdcOrderField> _Ref2Action;
                if (_Orders4Cancel.TryGetValue(order, out _Ref2Action))
                {
                    lock (_Ref2Action)
                    {
                        _Ref2Action.Remove(strKey);
                        if (0 == _Ref2Action.Count())
                        {
                            _Orders4Cancel.Remove(order);
                            return;
                        }
                        Cancel(order);
                    }
                }
            }
        }
        private void OnErrRtnOrderAction(IntPtr pTraderApi, ref CThostFtdcOrderActionField pOrderAction, ref CThostFtdcRspInfoField pRspInfo)
        {
            SingleOrder order;
            string strKey = string.Format("{0}:{1}:{2}", pOrderAction.FrontID, pOrderAction.SessionID, pOrderAction.OrderRef);
            if (_OrderRef2Order.TryGetValue(strKey, out order))
            {
                tdlog.Error("交易所回应:{0},价{1},变化量{2},前置{3},会话{4},引用{5},{6}#{7}",
                        pOrderAction.InstrumentID, pOrderAction.LimitPrice,
                        pOrderAction.VolumeChange,
                        pOrderAction.FrontID, pOrderAction.SessionID, pOrderAction.OrderRef,
                        pRspInfo.ErrorID, pRspInfo.ErrorMsg);

                order.Text = string.Format("{0}|{1}#{2}", order.Text.Substring(0, Math.Min(order.Text.Length, 64)), pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                EmitCancelReject(order, order.OrdStatus, order.Text);
            }
        }
        public void OnRspQryDepthMarketData(IntPtr pTraderApi, ref CThostFtdcDepthMarketDataField pDepthMarketData, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (0 == pRspInfo.ErrorID)
            {
                CThostFtdcDepthMarketDataField DepthMarket;
                if (!_dictDepthMarketData.TryGetValue(pDepthMarketData.InstrumentID, out DepthMarket))
                {
                    //没找到此元素,保存一下
                    _dictDepthMarketData[pDepthMarketData.InstrumentID] = pDepthMarketData;
                }

                tdlog.Info("已经接收查询深度行情 {0}", pDepthMarketData.InstrumentID);
                //通知单例
                CTPAPI.GetInstance().FireOnRspQryDepthMarketData(pDepthMarketData);
            }
            else
            {
                tdlog.Error("nRequestID:{0},ErrorID:{1},OnRspQryDepthMarketData:{2}", nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryDepthMarketData:" + pRspInfo.ErrorMsg);
            }
        }
Exemplo n.º 4
0
 private void OnErrRtnOrderAction_callback(IntPtr pTraderApi, ref CThostFtdcOrderActionField pOrderAction, ref CThostFtdcRspInfoField pRspInfo)
 {
     if (null != OnErrRtnOrderAction)
     {
         OnErrRtnOrderAction(this, new OnErrRtnOrderActionArgs(pTraderApi, ref pOrderAction, ref pRspInfo));
     }
 }
Exemplo n.º 5
0
 private void OnErrRtnOrderInsert_callback(IntPtr pTraderApi, ref CThostFtdcInputOrderField pInputOrder, ref CThostFtdcRspInfoField pRspInfo)
 {
     if (null != OnErrRtnOrderInsert)
     {
         OnErrRtnOrderInsert(this, new OnErrRtnOrderInsertArgs(pTraderApi, ref pInputOrder, ref pRspInfo));
     }
 }
Exemplo n.º 6
0
 public OnErrRtnOrderActionArgs(IntPtr pTraderApi, ref CThostFtdcOrderActionField pOrderAction, ref CThostFtdcRspInfoField pRspInfo)
 {
     this.pTraderApi = pTraderApi;
     this.pOrderAction = pOrderAction;
     this.pRspInfo = pRspInfo;
 }
Exemplo n.º 7
0
 public OnRspQryTradingAccountArgs(IntPtr pTraderApi, ref CThostFtdcTradingAccountField pTradingAccount, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.pTraderApi = pTraderApi;
     this.pTradingAccount = pTradingAccount;
     this.pRspInfo = pRspInfo;
     this.nRequestID = nRequestID;
     this.bIsLast = bIsLast;
 }
Exemplo n.º 8
0
 private void OnRspQryInvestorPosition_callback(IntPtr pTraderApi, ref CThostFtdcInvestorPositionField pInvestorPosition, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (null != OnRspQryInvestorPosition)
     {
         OnRspQryInvestorPosition(this, new OnRspQryInvestorPositionArgs(pTraderApi, ref pInvestorPosition, ref pRspInfo, nRequestID, bIsLast));
     }
 }
Exemplo n.º 9
0
 private void OnRspQryTradingAccount_callback(IntPtr pTraderApi, ref CThostFtdcTradingAccountField pTradingAccount, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (null != OnRspQryTradingAccount)
     {
         OnRspQryTradingAccount(this, new OnRspQryTradingAccountArgs(pTraderApi, ref pTradingAccount, ref pRspInfo, nRequestID, bIsLast));
     }
 }
        private void OnErrRtnOrderAction(IntPtr pTraderApi, ref CThostFtdcOrderActionField pOrderAction, ref CThostFtdcRspInfoField pRspInfo)
        {
            tdlog.Error("交易所回应:{0},价{1},变化量{2},前置{3},会话{4},引用{5},{6}#{7}",
                        pOrderAction.InstrumentID, pOrderAction.LimitPrice,
                        pOrderAction.VolumeChange,
                        pOrderAction.FrontID, pOrderAction.SessionID, pOrderAction.OrderRef,
                        pRspInfo.ErrorID, pRspInfo.ErrorMsg);

            GenericOrderItem item;
            string strKey = string.Format("{0}:{1}:{2}", pOrderAction.FrontID, pOrderAction.SessionID, pOrderAction.OrderRef);
            if (orderMap.TryGetValue(strKey, out item))
            {
                EmitCancelReject(item, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                EmitCancelLastStatus(item);
            }
        }
Exemplo n.º 11
0
 private void OnRspQryDepthMarketData_callback(IntPtr pTraderApi, ref CThostFtdcDepthMarketDataField pDepthMarketData, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (null != OnRspQryDepthMarketData)
     {
         OnRspQryDepthMarketData(this, new OnRspQryDepthMarketDataArgs(pTraderApi, ref pDepthMarketData, ref pRspInfo, nRequestID, bIsLast));
     }
 }
Exemplo n.º 12
0
        private void OnRspOrderInsert(IntPtr pTraderApi, ref CThostFtdcInputOrderField pInputOrder, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            SingleOrder order;
            string strKey = string.Format("{0}:{1}:{2}", _RspUserLogin.FrontID, _RspUserLogin.SessionID, pInputOrder.OrderRef);
            if (_OrderRef2Order.TryGetValue(strKey, out order))
            {
                tdlog.Error("CTP回应:{0},{1},开平{2},价{3},原量{4},引用{5},{6}",
                        pInputOrder.InstrumentID, pInputOrder.Direction, pInputOrder.CombOffsetFlag, pInputOrder.LimitPrice,
                        pInputOrder.VolumeTotalOriginal,
                        pInputOrder.OrderRef, pRspInfo.ErrorMsg);

                order.Text = string.Format("{0}|{1}", order.Text, pRspInfo.ErrorMsg);
                EmitRejected(order, order.Text);
                //这些地方没法处理混合报单
                //没得办法,这样全撤了状态就唯一了
                //但由于不知道在错单时是否会有报单回报,所以在这查一次,以防重复撤单出错
                //找到对应的报单回应
                Dictionary<string, CThostFtdcOrderField> _Ref2Action;
                if (_Orders4Cancel.TryGetValue(order, out _Ref2Action))
                {
                    lock (_Ref2Action)
                    {
                        _Ref2Action.Remove(strKey);
                        if (0 == _Ref2Action.Count())
                        {
                            _Orders4Cancel.Remove(order);
                            return;
                        }
                        Cancel(order);
                    }
                }
            }
        }
Exemplo n.º 13
0
 private void OnRspQryInstrument(IntPtr pTraderApi, ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (0 == pRspInfo.ErrorID)
     {
         _dictInstruments[pInstrument.InstrumentID] = pInstrument;
         if (bIsLast)
         {
             tdlog.Info("合约列表已经接收完成,共{0}条",_dictInstruments.Count);
         }
     }
     else
     {
         tdlog.Error("nRequestID:{0},ErrorID:{1},OnRspQryInstrument:{2}", nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
         EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInstrument:" + pRspInfo.ErrorMsg);
     }
 }
Exemplo n.º 14
0
        private void OnRspOrderAction(IntPtr pTraderApi, ref CThostFtdcInputOrderActionField pInputOrderAction, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            SingleOrder order;
            if (_OrderRef2Order.TryGetValue(string.Format("{0}:{1}:{2}", _RspUserLogin.FrontID, _RspUserLogin.SessionID, pInputOrderAction.OrderRef), out order))
            {
                tdlog.Error("CTP回应:{0},价{1},变化量{2},引用{3},{4}",
                        pInputOrderAction.InstrumentID, pInputOrderAction.LimitPrice,
                        pInputOrderAction.VolumeChange, pInputOrderAction.OrderRef,
                        pRspInfo.ErrorMsg);

                order.Text = string.Format("{0}|{1}", order.Text, pRspInfo.ErrorMsg);
                EmitCancelReject(order, order.Text);
            }
        }
Exemplo n.º 15
0
 private void OnDisconnect(IntPtr pApi, ref CThostFtdcRspInfoField pRspInfo, ConnectionStatus step)
 {
     if (m_pMdApi == pApi)//行情
     {
         if (isConnected)
         {
             mdlog.Error("Step:{0},ErrorID:{1},ErrorMsg:{2},等待定时重试连接", step, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
         }
         else
         {
             mdlog.Info("Step:{0},ErrorID:{1},ErrorMsg:{2}", step, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
         }
     }
     else if (m_pTdApi == pApi)//交易
     {
         if (isConnected)//如果以前连成功,表示密码没有错,只是初始化失败,可以重试
         {
             tdlog.Error("Step:{0},ErrorID:{1},ErrorMsg:{2},等待定时重试连接", step, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
         }
         else
         {
             tdlog.Info("Step:{0},ErrorID:{1},ErrorMsg:{2}", step, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
         }
     }
     if (!isConnected)//从来没有连接成功过,可能是密码错误,直接退出
     {
         //不能在线程中停止线程,这样会导致软件关闭进程不退出
         //_Disconnect();
     }
     else
     {
         //以前连接过,现在断了次线,要等重连
         ChangeStatus(ProviderStatus.Connecting);
         EmitDisconnectedEvent();
     }
 }
Exemplo n.º 16
0
 public OnErrRtnOrderInsertArgs(IntPtr pTraderApi, ref CThostFtdcInputOrderField pInputOrder, ref CThostFtdcRspInfoField pRspInfo)
 {
     this.pTraderApi = pTraderApi;
     this.pInputOrder = pInputOrder;
     this.pRspInfo = pRspInfo;
 }
Exemplo n.º 17
0
 private void OnRspError_callback(IntPtr pApi, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (null != OnRspError)
     {
         OnRspError(this,new OnRspErrorArgs(pApi,ref pRspInfo,nRequestID,bIsLast));
     }
 }
        private void OnErrRtnOrderInsert(IntPtr pTraderApi, ref CThostFtdcInputOrderField pInputOrder, ref CThostFtdcRspInfoField pRspInfo)
        {
            tdlog.Error("交易所回应:{0},{1},开平{2},价{3},原量{4},引用{5},{6}#{7}",
                        pInputOrder.InstrumentID, pInputOrder.Direction, pInputOrder.CombOffsetFlag, pInputOrder.LimitPrice,
                        pInputOrder.VolumeTotalOriginal,
                        pInputOrder.OrderRef, pRspInfo.ErrorID, pRspInfo.ErrorMsg);

            GenericOrderItem item;
            string strKey = string.Format("{0}:{1}:{2}", _RspUserLogin.FrontID, _RspUserLogin.SessionID, pInputOrder.OrderRef);
            if (orderMap.TryGetValue(strKey, out item))
            {
                EmitRejected(item,pRspInfo.ErrorID,pRspInfo.ErrorMsg);
                OnLastStatus(item, "", strKey);
            }
        }
Exemplo n.º 19
0
 private void OnRspOrderInsert_callback(IntPtr pTraderApi, ref CThostFtdcInputOrderField pInputOrder, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (null != OnRspOrderInsert)
     {
         OnRspOrderInsert(this, new OnRspOrderInsertArgs(pTraderApi, ref pInputOrder, ref pRspInfo, nRequestID, bIsLast));
     }
 }
Exemplo n.º 20
0
 private void OnDisconnect_callback(IntPtr pApi, ref CThostFtdcRspInfoField pRspInfo, ConnectionStatus step)
 {
     if (null != OnDisconnect)
     {
         OnDisconnect(this, new OnDisconnectArgs(pApi, ref pRspInfo, step));
     }
 }
Exemplo n.º 21
0
 private void OnRspQryInstrumentMarginRate_callback(IntPtr pTraderApi, ref CThostFtdcInstrumentMarginRateField pInstrumentMarginRate, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (null != OnRspQryInstrumentMarginRate)
     {
         OnRspQryInstrumentMarginRate(this, new OnRspQryInstrumentMarginRateArgs(pTraderApi, ref pInstrumentMarginRate, ref pRspInfo, nRequestID, bIsLast));
     }
 }
Exemplo n.º 22
0
        private void OnRspQryInstrumentMarginRate(IntPtr pTraderApi, ref CThostFtdcInstrumentMarginRateField pInstrumentMarginRate, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (0 == pRspInfo.ErrorID)
            {
                _dictMarginRate[pInstrumentMarginRate.InstrumentID] = pInstrumentMarginRate;
                tdlog.Info("已经接收保证金率 {0}", pInstrumentMarginRate.InstrumentID);

                //通知单例
                CTPAPI.GetInstance().FireOnRspQryInstrumentMarginRate(pInstrumentMarginRate);
            }
            else
            {
                tdlog.Error("nRequestID:{0},ErrorID:{1},OnRspQryInstrumentMarginRate:{2}", nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInstrumentMarginRate:" + pRspInfo.ErrorMsg);
            }
        }
Exemplo n.º 23
0
 private void OnRspQryOrder_callback(IntPtr pTraderApi, ref CThostFtdcOrderField pOrder, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (null != OnRspQryOrder)
     {
         OnRspQryOrder(this, new OnRspQryOrderArgs(pTraderApi, ref pOrder, ref pRspInfo, nRequestID, bIsLast));
     }
 }
Exemplo n.º 24
0
 private void OnRspQryTradingAccount(IntPtr pTraderApi, ref CThostFtdcTradingAccountField pTradingAccount, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLastt)
 {
     if (0 == pRspInfo.ErrorID)
     {
         m_TradingAccount = pTradingAccount;
         //有资金信息过来了,重新计时
         timerAccount.Enabled = false;
         timerAccount.Enabled = true;
     }
     else
     {
         tdlog.Error("nRequestID:{0},ErrorID:{1},OnRspQryTradingAccount:{2}", nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
         EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryTradingAccount:" + pRspInfo.ErrorMsg);
     }
 }
Exemplo n.º 25
0
        private void OnRspQryInstrument(IntPtr pTraderApi, ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (0 == pRspInfo.ErrorID)
            {
#if CTP
                _dictInstruments[pInstrument.InstrumentID] = pInstrument;
#else
                //比较无语,测试平台上会显示很多无效数据,有关期货的还会把正确的数据给覆盖,所以临时这样处理
                if (pInstrument.ProductClass != TThostFtdcProductClassType.Futures)
                {
                    string symbol = GetYahooSymbol(pInstrument.InstrumentID, pInstrument.ExchangeID);
                    _dictInstruments[symbol] = pInstrument;

                    // 行情中可能没有交易所信息,这个容器用于容错处理
                    _dictInstruments2[pInstrument.InstrumentID] = symbol;
                }
#endif

                if (bIsLast)
                {
                    tdlog.Info("合约列表已经接收完成,共{0}条", _dictInstruments.Count);
                }
            }
            else
            {
                tdlog.Error("nRequestID:{0},ErrorID:{1},OnRspQryInstrument:{2}", nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInstrument:" + pRspInfo.ErrorMsg);
            }
        }
Exemplo n.º 26
0
 public OnDisconnectArgs(IntPtr pApi, ref CThostFtdcRspInfoField pRspInfo, ConnectionStatus step)
 {
     this.pApi = pApi;
     this.pRspInfo = pRspInfo;
     this.step = step;
 }
Exemplo n.º 27
0
 private void OnRspQryInvestorPosition(IntPtr pTraderApi, ref CThostFtdcInvestorPositionField pInvestorPosition, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (0 == pRspInfo.ErrorID)
     {
         _dbInMemInvestorPosition.InsertOrReplace(
             pInvestorPosition.InstrumentID,
             pInvestorPosition.PosiDirection,
             pInvestorPosition.HedgeFlag,
             pInvestorPosition.PositionDate,
             pInvestorPosition.Position);
         timerPonstion.Enabled = false;
         timerPonstion.Enabled = true;
     }
     else
     {
         tdlog.Error("nRequestID:{0},ErrorID:{1},OnRspQryInvestorPosition:{2}", nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
         EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInvestorPosition:" + pRspInfo.ErrorMsg);
     }
 }
        private void OnDisconnect(IntPtr pApi, ref CThostFtdcRspInfoField pRspInfo, ConnectionStatus step)
        {
            if (m_pMdApi == pApi)//行情
            {
                _bMdConnected = false;
                if (isConnected)
                {
                    mdlog.Error("Step:{0},ErrorID:{1},ErrorMsg:{2},等待定时重试连接", step, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                }
                else
                {
                    mdlog.Info("Step:{0},ErrorID:{1},ErrorMsg:{2}", step, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                }
            }
            else if (m_pTdApi == pApi)//交易
            {
                _bTdConnected = false;
                if (isConnected)//如果以前连成功,表示密码没有错,只是初始化失败,可以重试
                {
                    tdlog.Error("Step:{0},ErrorID:{1},ErrorMsg:{2},等待定时重试连接", step, pRspInfo.ErrorID, pRspInfo.ErrorMsg);

                    if (7 == pRspInfo.ErrorID//综合交易平台:还没有初始化
                        || 8 == pRspInfo.ErrorID)//综合交易平台:前置不活跃
                    {
                        //这个地方登录重试太快了,等定时器来处理吧!
                        //Disconnect_TD();
                        //Connect_TD();
                    }
                }
                else
                {
                    tdlog.Info("Step:{0},ErrorID:{1},ErrorMsg:{2}", step, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                }
            }
            if (!isConnected)//从来没有连接成功过,可能是密码错误,直接退出
            {
                //不能在线程中停止线程,这样会导致软件关闭进程不退出
                //_Disconnect();
            }
            else
            {
                //以前连接过,现在断了次线,要等重连
                ChangeStatus(ProviderStatus.Connecting);
                EmitDisconnectedEvent();
            }
        }
Exemplo n.º 29
0
 private void OnRspError(IntPtr pApi, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     tdlog.Error("nRequestID:{0},ErrorID:{1},OnRspError:{2}", nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
     EmitError(nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
 }
Exemplo n.º 30
0
        private void OnDisconnect_callback(IntPtr pApi, ref CThostFtdcRspInfoField pRspInfo, ConnectionStatus step)
        {
            if(isConnected)
            {
                if (7 == pRspInfo.ErrorID//综合交易平台:还没有初始化
                    || 8 == pRspInfo.ErrorID)//综合交易平台:前置不活跃
                {
                    Disconnect_TD();
                    Connect_TD();
                }
            }

            if (null != OnDisconnect)
            {
                OnDisconnect(this, new OnDisconnectArgs(pApi, ref pRspInfo, step));
            }
        }