Exemple #1
0
 public OnRtnOrderArgs(IntPtr pTraderApi, ref CZQThostFtdcOrderField pOrder)
 {
     this.pTraderApi = pTraderApi;
     this.pOrder = pOrder;
 }
        private void OnRtnOrder(IntPtr pTraderApi, ref CZQThostFtdcOrderField pOrder)
        {
            if (OutputLogToConsole)
            {
                Console.WriteLine("{0},{1},{2},开平{3},价{4},原量{5},成交{6},提交{7},状态{8},引用{9},{10}",
                    pOrder.InsertTime, pOrder.InstrumentID, pOrder.Direction, pOrder.CombOffsetFlag, pOrder.LimitPrice,
                    pOrder.VolumeTotalOriginal, pOrder.VolumeTraded, pOrder.OrderSubmitStatus, pOrder.OrderStatus,
                    pOrder.OrderRef,pOrder.StatusMsg);
            }

            SingleOrder order;
            string strKey = string.Format("{0}:{1}:{2}", _RspUserLogin.FrontID, _RspUserLogin.SessionID, pOrder.OrderRef);
            if (_OrderRef2Order.TryGetValue(strKey, out order))
            {
                order.Text = string.Format("{0}|{1}", order.Text, pOrder.StatusMsg);

                //找到对应的报单回应
                Dictionary<string, CZQThostFtdcOrderField> _Ref2Action;
                if (!_Orders4Cancel.TryGetValue(order, out _Ref2Action))
                {
                    //没找到,自己填一个
                    _Ref2Action = new Dictionary<string, CZQThostFtdcOrderField>();
                    _Orders4Cancel[order] = _Ref2Action;
                }

                lock (_Ref2Action)
                {
                    switch (pOrder.OrderStatus)
                    {
                        case TZQThostFtdcOrderStatusType.AllTraded:
                            //已经是最后状态,不能用于撤单了
                            _Ref2Action.Remove(strKey);
                            break;
                        case TZQThostFtdcOrderStatusType.PartTradedQueueing:
                            //只是部分成交,还可以撤单,所以要记录下来
                            _Ref2Action[strKey] = pOrder;
                            break;
                        case TZQThostFtdcOrderStatusType.PartTradedNotQueueing:
                            //已经是最后状态,不能用于撤单了
                            _Ref2Action.Remove(strKey);
                            break;
                        case TZQThostFtdcOrderStatusType.NoTradeQueueing:
                            if (0 == _Ref2Action.Count())
                            {
                                EmitAccepted(order);
                            }
                            _Ref2Action[strKey] = pOrder;
                            break;
                        case TZQThostFtdcOrderStatusType.NoTradeNotQueueing:
                            //已经是最后状态,不能用于撤单了
                            _Ref2Action.Remove(strKey);
                            break;
                        case TZQThostFtdcOrderStatusType.Canceled:
                            //已经是最后状态,不能用于撤单了
                            _Ref2Action.Remove(strKey);
                            //分析此报单是否结束,如果结束分析整个Order是否结束
                            switch (pOrder.OrderSubmitStatus)
                            {
                                case TZQThostFtdcOrderSubmitStatusType.InsertRejected:
                                    //如果是最后一个的状态,同意发出消息
                                    if (0 == _Ref2Action.Count())
                                        EmitRejected(order, pOrder.StatusMsg);
                                    else
                                        Cancel(order);
                                    break;
                                default:
                                    //如果是最后一个的状态,同意发出消息
                                    if (0 == _Ref2Action.Count())
                                        EmitCancelled(order);
                                    else
                                        Cancel(order);
                                    break;
                            }
                            break;
                        case TZQThostFtdcOrderStatusType.Unknown:
                            switch (pOrder.OrderSubmitStatus)
                            {
                                case TZQThostFtdcOrderSubmitStatusType.InsertSubmitted:
                                    //新单,新加入记录以便撤单
                                    if (0 == _Ref2Action.Count())
                                    {
                                        EmitAccepted(order);
                                    }
                                    _Ref2Action[strKey] = pOrder;
                                    break;
                            }
                            break;
                        case TZQThostFtdcOrderStatusType.NotTouched:
                            //没有处理
                            break;
                        case TZQThostFtdcOrderStatusType.Touched:
                            //没有处理
                            break;
                    }

                    //已经是最后状态了,可以去除了
                    if (0 == _Ref2Action.Count())
                    {
                        _Orders4Cancel.Remove(order);
                    }
                }
            }
            else
            {
                //由第三方软件发出或上次登录时的剩余的单子在这次成交了,先不处理,当不存在
            }
        }
Exemple #3
0
 public OnRspQryOrderArgs(IntPtr pTraderApi, ref CZQThostFtdcOrderField pOrder, ref CZQThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.pTraderApi = pTraderApi;
     this.pOrder = pOrder;
     this.pRspInfo = pRspInfo;
     this.nRequestID = nRequestID;
     this.bIsLast = bIsLast;
 }
Exemple #4
0
 private void OnRtnOrder_callback(IntPtr pTraderApi, ref CZQThostFtdcOrderField pOrder)
 {
     if (null != OnRtnOrder)
     {
         OnRtnOrder(this, new OnRtnOrderArgs(pTraderApi, ref pOrder));
     }
 }
Exemple #5
0
 private void OnRspQryOrder_callback(IntPtr pTraderApi, ref CZQThostFtdcOrderField pOrder, ref CZQThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (null != OnRspQryOrder)
     {
         OnRspQryOrder(this, new OnRspQryOrderArgs(pTraderApi, ref pOrder, ref pRspInfo, nRequestID, bIsLast));
     }
 }
Exemple #6
0
        public void CancelOrder(ref CZQThostFtdcOrderField pOrder)
        {
            if (null == m_pTdApi || IntPtr.Zero == m_pTdApi)
            {
                return;
            }

            TraderApi.TD_CancelOrder(m_pTdApi, ref pOrder);
        }
Exemple #7
0
 public static extern void TD_CancelOrder(IntPtr pTraderApi, ref CZQThostFtdcOrderField pOrder);
        private void OnRtnOrder(IntPtr pTraderApi, ref CZQThostFtdcOrderField pOrder)
        {
            tdlog.Info("{0},{1},{2},开平{3},价{4},原量{5},成交{6},提交{7},状态{8},前置{9},会话{10},引用{11},报单编号{12},{13}",
                    pOrder.InsertTime, pOrder.InstrumentID, pOrder.Direction, pOrder.CombOffsetFlag, pOrder.LimitPrice,
                    pOrder.VolumeTotalOriginal, pOrder.VolumeTraded, pOrder.OrderSubmitStatus, pOrder.OrderStatus,
                    pOrder.FrontID, pOrder.SessionID, pOrder.OrderRef, pOrder.OrderSysID, pOrder.StatusMsg);

            // 加上这句只是为了在一个账号多会话高频交易时提前过滤
            if (pOrder.SessionID != _RspUserLogin.SessionID || pOrder.FrontID != _RspUserLogin.FrontID)
            {
                return;
            }

            SingleOrder order;
            string strKey = string.Format("{0}:{1}:{2}", pOrder.FrontID, pOrder.SessionID, pOrder.OrderRef);
            if (_OrderRef2Order.TryGetValue(strKey, out order))
            {
                order.Text = string.Format("{0}|{1}", order.Text.Substring(0, Math.Min(order.Text.Length, 64)), pOrder.StatusMsg);
                order.OrderID = pOrder.OrderSysID;

                //找到对应的报单回应
                Dictionary<string, CZQThostFtdcOrderField> _Ref2Action;
                if (!_Orders4Cancel.TryGetValue(order, out _Ref2Action))
                {
                    //没找到,自己填一个
                    _Ref2Action = new Dictionary<string, CZQThostFtdcOrderField>();
                    _Orders4Cancel[order] = _Ref2Action;
                }

                // 有对它进行过撤单操作,这地方是为了加正在撤单状态
                OrdStatus status;
                if (_PendingCancelFlags.TryGetValue(order, out status))
                {
                    // 记下当时的状态
                    _PendingCancelFlags[order] = order.OrdStatus;
                    EmitPendingCancel(order);
                }

                lock (_Ref2Action)
                {
                    string strSysID = string.Format("{0}:{1}", pOrder.ExchangeID, pOrder.OrderSysID);

                    switch (pOrder.OrderStatus)
                    {
                        case TZQThostFtdcOrderStatusType.AllTraded:
                            //已经是最后状态,不能用于撤单了
                            _PendingCancelFlags.Remove(order);
                            _Ref2Action.Remove(strKey);
                            break;
                        case TZQThostFtdcOrderStatusType.PartTradedQueueing:
                            //只是部分成交,还可以撤单,所以要记录下来
                            _Ref2Action[strKey] = pOrder;
                            break;
                        case TZQThostFtdcOrderStatusType.PartTradedNotQueueing:
                            //已经是最后状态,不能用于撤单了
                            _PendingCancelFlags.Remove(order);
                            _Ref2Action.Remove(strKey);
                            break;
                        case TZQThostFtdcOrderStatusType.NoTradeQueueing:
                            // 用于收到成交回报时定位
                            _OrderSysID2OrderRef[strSysID] = strKey;

                            if (0 == _Ref2Action.Count())
                            {
                                _Ref2Action[strKey] = pOrder;
                                EmitAccepted(order);
                            }
                            else
                            {
                                _Ref2Action[strKey] = pOrder;
                            }
                            break;
                        case TZQThostFtdcOrderStatusType.NoTradeNotQueueing:
                            //已经是最后状态,不能用于撤单了
                            _PendingCancelFlags.Remove(order);
                            _Ref2Action.Remove(strKey);
                            break;
                        case TZQThostFtdcOrderStatusType.Canceled:
                            //已经是最后状态,不能用于撤单了
                            _PendingCancelFlags.Remove(order);
                            _Ref2Action.Remove(strKey);
                            //分析此报单是否结束,如果结束分析整个Order是否结束
                            switch (pOrder.OrderSubmitStatus)
                            {
                                case TZQThostFtdcOrderSubmitStatusType.InsertRejected:
                                    //如果是最后一个的状态,同意发出消息
                                    if (0 == _Ref2Action.Count())
                                        EmitRejected(order, pOrder.StatusMsg);
                                    else
                                        Cancel(order);
                                    break;
                                default:
                                    //如果是最后一个的状态,同意发出消息
                                    if (0 == _Ref2Action.Count())
                                        EmitCancelled(order);
                                    else
                                        Cancel(order);
                                    break;
                            }
                            break;
                        case TZQThostFtdcOrderStatusType.Unknown:
                            switch (pOrder.OrderSubmitStatus)
                            {
                                case TZQThostFtdcOrderSubmitStatusType.InsertSubmitted:
                                    // 有可能头两个报单就这状态,就是报单编号由空变为了有。为空时,也记,没有关系
                                    _OrderSysID2OrderRef[strSysID] = strKey;

                                    //新单,新加入记录以便撤单
                                    if (0 == _Ref2Action.Count())
                                    {
                                        _Ref2Action[strKey] = pOrder;
                                        EmitAccepted(order);
                                    }
                                    else
                                    {
                                        _Ref2Action[strKey] = pOrder;
                                    }
                                    break;
                            }
                            break;
                        case TZQThostFtdcOrderStatusType.NotTouched:
                            //没有处理
                            break;
                        case TZQThostFtdcOrderStatusType.Touched:
                            //没有处理
                            break;
                    }

                    //已经是最后状态了,可以去除了
                    if (0 == _Ref2Action.Count())
                    {
                        _Orders4Cancel.Remove(order);
                    }
                }
            }
            else
            {
                //由第三方软件发出或上次登录时的剩余的单子在这次成交了,先不处理,当不存在
            }
        }