Example #1
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
         EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInvestorPosition:" + pRspInfo.ErrorMsg);
 }
Example #2
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
         EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryTradingAccount:" + pRspInfo.ErrorMsg);
 }
Example #3
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))
     {
         if (OutputLog)
         {
             Console.WriteLine("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);
             }
         }
     }
 }
Example #4
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)
         {
             Console.WriteLine(string.Format("TdApi:{0},合约列表已经接收完成",
                 Clock.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")));
         }
     }
     else
         EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInstrument:" + pRspInfo.ErrorMsg);
 }
Example #5
0
 private void OnRspError(IntPtr pApi, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     EmitError(nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
 }
Example #6
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))
            {
                if (OutputLog)
                {
                    Console.WriteLine("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);
            }
        }
Example #7
0
 private void OnDisconnect(IntPtr pApi, ref CThostFtdcRspInfoField pRspInfo, ConnectionStatus step)
 {
     if (m_pMdApi == pApi)//行情
     {
         Disconnect_MD();
         if (isConnected)
         {
             EmitError((int)step, pRspInfo.ErrorID, "MdApi:" + pRspInfo.ErrorMsg + " 等待定时重试连接");
         }
         else
         {
             EmitError((int)step, pRspInfo.ErrorID, "MdApi:" + pRspInfo.ErrorMsg);
             Console.WriteLine(string.Format("MdApi:{0},{1},{2}", Clock.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), pRspInfo.ErrorID, pRspInfo.ErrorMsg));
         }
     }
     else if (m_pTdApi == pApi)//交易
     {
         Disconnect_TD();
         if (isConnected)//如果以前连成功,表示密码没有错,只是初始化失败,可以重试
         {
             EmitError((int)step, pRspInfo.ErrorID, "TdApi:" + pRspInfo.ErrorMsg + " 等待定时重试连接");
         }
         else
         {
             EmitError((int)step, pRspInfo.ErrorID, "TdApi:" + pRspInfo.ErrorMsg);
             Console.WriteLine(string.Format("TdApi:{0},{1},{2}", Clock.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), pRspInfo.ErrorID, pRspInfo.ErrorMsg));
         }
     }
     if (!isConnected)//从来没有连接成功过,可能是密码错误,直接退出
     {
         _Disconnect(true);
     }
     else
     {
         ChangeStatus(ProviderStatus.Connecting);
     }
 }
Example #8
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))
     {
         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);
             }
         }
     }
 }
Example #9
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))
     {
         order.Text = string.Format("{0} {1}", order.Text, pRspInfo.ErrorMsg);
         EmitCancelReject(order, order.Text);
     }
 }
Example #10
0
 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))
     {
         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);
             }
         }
     }
 }
Example #11
0
 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))
     {
         if (OutputLog)
         {
             Console.WriteLine("交易所回应:{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);
             }
         }
     }
 }