示例#1
0
 private void ProcessExecRejected(OrderField field)
 {
     if (_map.TryPickLocal(field.LocalID, out var order))
     {
         _provider.OnMessage(CreateReport(new OrderRecord(order), (OrderStatus)field.Status,
                                          ExecType.ExecRejected, field.Text()));
     }
     else if (_map.TryPickRejected(field.ID, out var record))
     {
         //出现超出涨跌停时,会先收到 ProcessExecNew
         _provider.OnMessage(CreateReport(record, (OrderStatus)field.Status, ExecType.ExecRejected,
                                          field.Text()));
     }
 }
示例#2
0
 private void ProcessExecCancelReject(OrderField field)
 {
     if (_map.TryGetOrder(field.ID, out var record))
     {
         _provider.OnMessage(CreateReport(record, (OrderStatus)field.Status, ExecType.ExecCancelReject,
                                          field.Text()));
     }
 }
示例#3
0
 private void ProcessExecRejected(OrderField field)
 {
     if (_map.TryGetOrder(field.ID, out var record))
     {
         var report = CreateReport(record, (OrderStatus)field.Status, ExecType.ExecRejected, field.Text());
         report.SetErrorId(field.XErrorID, field.RawErrorID);
         _provider.OnMessage(report);
         _map.RemoveDone(field.ID);
     }
 }
示例#4
0
文件: XApiCom.cs 项目: mlken/XAPI2
        private void OnRspQryOrder_callback(object sender, [In] ref OrderField order, int size1, bool bIsLast)
        {
            if (null == OnRspQryOrder)
            {
                return;
            }

            OrderClass cls = new OrderClass();

            if (size1 > 0)
            {
                OrderField field = order;

                cls.InstrumentName = field.InstrumentName();
                cls.Symbol         = field.Symbol;
                cls.InstrumentID   = field.InstrumentID;
                cls.ExchangeID     = field.ExchangeID;
                cls.ClientID       = field.ClientID;
                cls.AccountID      = field.AccountID;
                cls.Side           = (int)field.Side;
                cls.Side_String    = Enum <XAPI.OrderSide> .ToString(field.Side);

                cls.Qty              = field.Qty;
                cls.Price            = field.Price;
                cls.OpenClose        = (int)field.OpenClose;
                cls.OpenClose_String = Enum <XAPI.OpenCloseType> .ToString(field.OpenClose);

                cls.HedgeFlag        = (int)field.HedgeFlag;
                cls.HedgeFlag_String = Enum <XAPI.HedgeFlagType> .ToString(field.HedgeFlag);

                cls.Date        = field.Date;
                cls.Time        = field.Time;
                cls.ID          = field.ID;
                cls.OrderID     = field.OrderID;
                cls.LocalID     = field.LocalID;
                cls.Type        = (int)field.Type;
                cls.Type_String = Enum <XAPI.OrderType> .ToString(field.Type);

                cls.StopPx             = field.StopPx;
                cls.TimeInForce        = (int)field.TimeInForce;
                cls.TimeInForce_String = Enum <XAPI.TimeInForce> .ToString(field.TimeInForce);

                cls.Status        = (int)field.Status;
                cls.Status_String = Enum <XAPI.OrderStatus> .ToString(field.Status);

                cls.ExecType        = (int)field.ExecType;
                cls.ExecType_String = Enum <XAPI.ExecType> .ToString(field.ExecType);

                cls.LeavesQty     = field.LeavesQty;
                cls.CumQty        = field.CumQty;
                cls.AvgPx         = field.AvgPx;
                cls.XErrorID      = field.XErrorID;
                cls.RawErrorID    = field.RawErrorID;
                cls.Text          = field.Text();
                cls.ReserveInt32  = field.ReserveInt32;
                cls.ReserveChar64 = field.ReserveChar64;

                cls.PortfolioID1    = field.PortfolioID1;
                cls.PortfolioID2    = field.PortfolioID2;
                cls.PortfolioID3    = field.PortfolioID3;
                cls.Business        = (int)field.Business;
                cls.Business_String = Enum <XAPI.BusinessType> .ToString(field.Business);
            }

            if (null == OnRspQryOrder)
            {
                QueueData qd = new QueueData();
                qd.Type        = (int)ResponseType.OnRspQryOrder;
                qd.Type_String = Enum <XAPI.ResponseType> .ToString(ResponseType.OnRspQryOrder);

                qd.Sender = this;
                qd.Data1  = cls;
                qd.Data2  = size1;
                qd.Data3  = bIsLast;

                MessageQueue.Enqueue(qd);
            }
            else
            {
                OnRspQryOrder(this, cls, size1, bIsLast);
            }
        }
示例#5
0
        public void Process(ref OrderField order, NLog.Logger log)
        {
            // 所有的成交信息都不处理,交给TradeField处理
            if (order.ExecType == XAPI.ExecType.Trade)
            {
                return;
            }

            lock (this)
            {
                OrderRecord record;

                switch (order.ExecType)
                {
                case XAPI.ExecType.New:
                    if (this.pendingOrders.TryRemove(order.LocalID, out record))
                    {
                        this.workingOrders[order.ID] = record;
                        // 将LocalID更新为ID
                        this.orderIDs[record.Order.Id] = order.ID;
                        EmitExecutionReport(record, (SQ.ExecType)order.ExecType, (SQ.OrderStatus)order.Status, order.Text());
                    }
                    else
                    {
                        //log.Warn("New,找不到订单,pendingOrders.Count={0}", pendingOrders.Count);
                    }
                    break;

                case XAPI.ExecType.Rejected:
                    if (this.pendingOrders.TryRemove(order.LocalID, out record))
                    {
                        orderIDs.Remove(record.Order.Id);
                        record.LeavesQty = 0;
                        EmitExecutionReport(record, (SQ.ExecType)order.ExecType, (SQ.OrderStatus)order.Status, order.Text());
                    }
                    else if (this.workingOrders.TryGetValue(order.ID, out record))
                    {
                        // 比如说出现超出涨跌停时,先会到ProcessNew,所以得再多判断一次
                        workingOrders.Remove(order.ID);
                        orderIDs.Remove(record.Order.Id);
                        record.LeavesQty = 0;
                        EmitExecutionReport(record, (SQ.ExecType)order.ExecType, (SQ.OrderStatus)order.Status, order.Text());
                    }
                    break;

                case XAPI.ExecType.Cancelled:
                    if (this.workingOrders.TryGetValue(order.ID, out record))
                    {
                        workingOrders.Remove(order.ID);
                        orderIDs.Remove(record.Order.Id);
                        record.LeavesQty = 0;
                        EmitExecutionReport(record, SQ.ExecType.ExecCancelled, SQ.OrderStatus.Cancelled);
                    }
                    else if (this.pendingOrders.TryRemove(order.LocalID, out record))
                    {
                        orderIDs.Remove(record.Order.Id);
                        record.LeavesQty = 0;
                        EmitExecutionReport(record, (SQ.ExecType)order.ExecType, (SQ.OrderStatus)order.Status, order.Text());
                    }
                    break;

                case XAPI.ExecType.PendingCancel:
                    if (this.workingOrders.TryGetValue(order.ID, out record))
                    {
                        EmitExecutionReport(record, SQ.ExecType.ExecPendingCancel, SQ.OrderStatus.PendingCancel);
                    }
                    else if (this.pendingOrders.TryGetValue(order.LocalID, out record))
                    {
                        EmitExecutionReport(record, SQ.ExecType.ExecPendingCancel, SQ.OrderStatus.PendingCancel);
                    }
                    break;

                case XAPI.ExecType.CancelReject:
                    if (this.pendingCancels.TryRemove(order.ID, out record))
                    {
                        // 已经收到第一回报的情况下
                        EmitExecutionReport(record, SQ.ExecType.ExecCancelReject, (SQ.OrderStatus)order.Status, order.Text());
                    }
                    else if (this.pendingCancels.TryRemove(order.LocalID, out record))
                    {
                        // 没有收到第一条回报的情况下
                        EmitExecutionReport(record, SQ.ExecType.ExecCancelReject, (SQ.OrderStatus)order.Status, order.Text());
                    }
                    //else if (this.workingOrders.TryGetValue(order.ID, out record))
                    //{
                    //    // 撤单回报延时的情况下
                    //    EmitExecutionReport(record, SQ.ExecType.ExecCancelReject, (SQ.OrderStatus)order.Status, order.Text());
                    //}
                    break;
                }
            }
        }
示例#6
0
        private void OnRtnOrder_callback(object sender, ref OrderField order)
        {
            OrderField field = order;

            OrderClass cls = new OrderClass();

            cls.InstrumentName = field.InstrumentName();
            cls.Symbol         = field.Symbol;
            cls.InstrumentID   = field.InstrumentID;
            cls.ExchangeID     = field.ExchangeID;
            cls.ClientID       = field.ClientID;
            cls.AccountID      = field.AccountID;
            cls.Side           = (int)field.Side;
            cls.Side_String    = Enum <XAPI.OrderSide> .ToString(field.Side);

            cls.Qty              = field.Qty;
            cls.Price            = field.Price;
            cls.OpenClose        = (int)field.OpenClose;
            cls.OpenClose_String = Enum <XAPI.OpenCloseType> .ToString(field.OpenClose);

            cls.HedgeFlag        = (int)field.HedgeFlag;
            cls.HedgeFlag_String = Enum <XAPI.HedgeFlagType> .ToString(field.HedgeFlag);

            cls.Date        = field.Date;
            cls.Time        = field.Time;
            cls.ID          = field.ID;
            cls.OrderID     = field.OrderID;
            cls.LocalID     = field.LocalID;
            cls.Type        = (int)field.Type;
            cls.Type_String = Enum <XAPI.OrderType> .ToString(field.Type);

            cls.StopPx             = field.StopPx;
            cls.TimeInForce        = (int)field.TimeInForce;
            cls.TimeInForce_String = Enum <XAPI.TimeInForce> .ToString(field.TimeInForce);

            cls.Status        = (int)field.Status;
            cls.Status_String = Enum <XAPI.OrderStatus> .ToString(field.Status);

            cls.ExecType        = (int)field.ExecType;
            cls.ExecType_String = Enum <XAPI.ExecType> .ToString(field.ExecType);

            cls.LeavesQty     = field.LeavesQty;
            cls.CumQty        = field.CumQty;
            cls.AvgPx         = field.AvgPx;
            cls.XErrorID      = field.XErrorID;
            cls.RawErrorID    = field.RawErrorID;
            cls.Text          = field.Text();
            cls.ReserveInt32  = field.ReserveInt32;
            cls.ReserveChar64 = field.ReserveChar64;

            if (null == OnRtnOrder)
            {
                QueueData qd = new QueueData();
                qd.Type        = (int)ResponeType.OnRtnOrder;
                qd.Type_String = Enum <XAPI.ResponeType> .ToString(ResponeType.OnRtnOrder);

                qd.Sender = this;
                qd.Data1  = cls;

                MessageQueue.Enqueue(qd);
            }
            else
            {
                OnRtnOrder(this, ref cls);
            }
        }
示例#7
0
        public void Process(ref OrderField order)
        {
            // 所有的成交信息都不处理,交给TradeField处理
            if (order.ExecType == XAPI.ExecType.Trade)
            {
                return;
            }

            OrderRecord record;

            switch (order.ExecType)
            {
            case XAPI.ExecType.New:
                if (this.pendingOrders.TryRemove(order.LocalID, out record))
                {
                    this.workingOrders.Add(order.ID, record);
                    // 将LocalID更新为ID
                    this.orderIDs[record.Order.Id] = order.ID;
                    EmitExecutionReport(record, (SQ.ExecType)order.ExecType, (SQ.OrderStatus)order.Status);
                }
                break;

            case XAPI.ExecType.Rejected:
                if (this.pendingOrders.TryRemove(order.LocalID, out record))
                {
                    orderIDs.Remove(record.Order.Id);
                    EmitExecutionReport(record, (SQ.ExecType)order.ExecType, (SQ.OrderStatus)order.Status, order.Text());
                }
                else if (this.workingOrders.TryGetValue(order.ID, out record))
                {
                    // 比如说出现超出涨跌停时,先会到ProcessNew,所以得再多判断一次
                    workingOrders.Remove(order.ID);
                    orderIDs.Remove(record.Order.Id);
                    EmitExecutionReport(record, (SQ.ExecType)order.ExecType, (SQ.OrderStatus)order.Status, order.Text());
                }
                break;

            case XAPI.ExecType.Cancelled:
                if (this.workingOrders.TryGetValue(order.ID, out record))
                {
                    workingOrders.Remove(order.ID);
                    orderIDs.Remove(record.Order.Id);
                    EmitExecutionReport(record, SQ.ExecType.ExecCancelled, SQ.OrderStatus.Cancelled);
                }
                else if (this.pendingOrders.TryRemove(order.LocalID, out record))
                {
                    orderIDs.Remove(record.Order.Id);
                    EmitExecutionReport(record, (SQ.ExecType)order.ExecType, (SQ.OrderStatus)order.Status, order.Text());
                }
                break;

            case XAPI.ExecType.PendingCancel:
                if (this.workingOrders.TryGetValue(order.ID, out record))
                {
                    EmitExecutionReport(record, SQ.ExecType.ExecPendingCancel, SQ.OrderStatus.PendingCancel);
                }
                break;

            case XAPI.ExecType.CancelReject:
                if (this.pendingCancels.TryRemove(order.ID, out record))
                {
                    EmitExecutionReport(record, SQ.ExecType.ExecCancelReject, (SQ.OrderStatus)order.Status, order.Text());
                }
                break;
            }
        }