예제 #1
0
        private void OnRtnOrder(IntPtr pTraderApi, ref CThostFtdcOrderField pOrder)
        {
            if (OutputLog)
            {
                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, CThostFtdcOrderField> _Ref2Action;
                if (!_Orders4Cancel.TryGetValue(order, out _Ref2Action))
                {
                    //没找到,自己填一个
                    _Ref2Action = new Dictionary<string, CThostFtdcOrderField>();
                    _Orders4Cancel[order] = _Ref2Action;
                }

                lock (_Ref2Action)
                {
                    switch (pOrder.OrderStatus)
                    {
                        case TThostFtdcOrderStatusType.AllTraded:
                            //已经是最后状态,不能用于撤单了
                            _Ref2Action.Remove(strKey);
                            break;
                        case TThostFtdcOrderStatusType.PartTradedQueueing:
                            //只是部分成交,还可以撤单,所以要记录下来
                            _Ref2Action[strKey] = pOrder;
                            break;
                        case TThostFtdcOrderStatusType.PartTradedNotQueueing:
                            //已经是最后状态,不能用于撤单了
                            _Ref2Action.Remove(strKey);
                            break;
                        case TThostFtdcOrderStatusType.NoTradeQueueing:
                            if (0 == _Ref2Action.Count())
                            {
                                EmitAccepted(order);
                            }
                            _Ref2Action[strKey] = pOrder;
                            break;
                        case TThostFtdcOrderStatusType.NoTradeNotQueueing:
                            //已经是最后状态,不能用于撤单了
                            _Ref2Action.Remove(strKey);
                            break;
                        case TThostFtdcOrderStatusType.Canceled:
                            //已经是最后状态,不能用于撤单了
                            _Ref2Action.Remove(strKey);
                            //分析此报单是否结束,如果结束分析整个Order是否结束
                            switch (pOrder.OrderSubmitStatus)
                            {
                                case TThostFtdcOrderSubmitStatusType.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 TThostFtdcOrderStatusType.Unknown:
                            switch (pOrder.OrderSubmitStatus)
                            {
                                case TThostFtdcOrderSubmitStatusType.InsertSubmitted:
                                    //新单,新加入记录以便撤单
                                    if (0 == _Ref2Action.Count())
                                    {
                                        EmitAccepted(order);
                                    }
                                    _Ref2Action[strKey] = pOrder;
                                    break;
                            }
                            break;
                        case TThostFtdcOrderStatusType.NotTouched:
                            //没有处理
                            break;
                        case TThostFtdcOrderStatusType.Touched:
                            //没有处理
                            break;
                    }

                    //已经是最后状态了,可以去除了
                    if (0 == _Ref2Action.Count())
                    {
                        _Orders4Cancel.Remove(order);
                    }
                }
            }
            else
            {
                //由第三方软件发出或上次登录时的剩余的单子在这次成交了,先不处理,当不存在
            }
        }
예제 #2
0
파일: TraderApi.cs 프로젝트: shalang/CTP
 public static extern void TD_CancelOrder(IntPtr pTraderApi, ref CThostFtdcOrderField pOrder);