示例#1
0
        ///报单通知
        private void OnRtnOrder(ThostFtdcOrderField pOrder)
        {
            //__DEBUGPF__();
            System.Diagnostics.Debug.WriteLine(string.Format("{2} OnRtnOrder: {0}, {1}, {3}",
                                                             pOrder.OrderRef, pOrder.InstrumentID, DateTime.Now.ToString("HH:mm:ss"), pOrder.OrderStatus));

            if (IsMyOrder(pOrder))
            {
                var customOrder = new CustomOrder();
                // 原始报单信息
                customOrder.OrderNo      = int.Parse(pOrder.OrderRef);
                customOrder.InstrumentID = pOrder.InstrumentID;
                customOrder.Direction    = (pOrder.Direction == EnumDirectionType.Buy) ? BS_CODE.Buy : BS_CODE.Sell;
                customOrder.OffsetFlag   = (pOrder.CombOffsetFlag_0 == EnumOffsetFlagType.Open) ? OC_CODE.Open : OC_CODE.Close;
                customOrder.Price        = pOrder.LimitPrice;
                customOrder.Volume       = pOrder.VolumeTotalOriginal;
                // 更新委托回报信息
                customOrder.tradeRef    = pOrder.ExchangeID + "_" + pOrder.OrderSysID;      // 查找对应成交回报的依据
                customOrder.TradedVol   = pOrder.VolumeTotalOriginal - pOrder.VolumeTotal;  // 已成交数量
                customOrder.OrderStatus = ConvertStatus(pOrder.OrderStatus);

                // 处理委托回报
                if (HandleRtnOrderDel != null)
                {
                    HandleRtnOrderDel(customOrder);
                    //HandleRtnOrderDel.BeginInvoke(customOrder, null, null);
                }
            }
        }
示例#2
0
        /// <summary>
        /// """报单回报"""
        /// </summary>
        /// <param name="pOrder"></param>
        public void HandleOnRtnOrder(ThostFtdcOrderField pOrder)
        {
            var order = new OrderData();

            ///报单推送
            this.Gateway.MainController.MainEvent._OnOrder.Invoke(order);
        }
示例#3
0
        void _trade_OnRtnOrder(ThostFtdcOrderField pOrder)
        {
            this.QueryAccount();
            var orderId = (pOrder.OrderSysID ?? "").Trim();
            var old     = this.Account.PendingOrders.FirstOrDefault(_ => _.OrderID == orderId);

            if (old != null)
            {
                this.Account.PendingOrders.Remove(old);
            }
            if (orderId.Length > 0 && pOrder.GetOrderStatus() == OrderStatus.Pending)
            {
                this.Account.PendingOrders.Add(pOrder.ToOptionOrder());
            }

            var oldNative = this._orders.ToList().FirstOrDefault(_ => _.OrderSysID == orderId);

            if (oldNative != null)
            {
                this._orders.Remove(oldNative);
            }
            if (orderId.Length > 0)
            {
                this._orders.Add(pOrder);
            }
        }
示例#4
0
 /// <summary>
 /// 清空报单信息
 /// </summary>
 public void clearOrderInfo()
 {
     ShortOptionOrder = null;
     LongOptionOrder = null;
     CloseLongOptionOrder = null;
     CloseShortOptionOrder = null;
     PlaceShortOptionOrderRef = null;
     PlaceLongOptionOrderRef = null;
     CloseLongOptionOrderRef = null;
     CloseShortOptionOrderRef = null;
 }
示例#5
0
 public static string ToString2(this ThostFtdcOrderField field)
 {
     return(string.Format("OrderRef:{0},{1},{2} {3}, {4} {5} {6} {7} {8}",
                          field.OrderRef,
                          field.UserID,
                          field.OrderStatus,
                          field.StatusMsg,
                          field.CombOffsetFlag_0,
                          field.Direction,
                          field.VolumeTotalOriginal,
                          field.InstrumentID,
                          field.LimitPrice
                          ));
 }
示例#6
0
 ///报单通知
 void OnRtnOrder(ThostFtdcOrderField pOrder)
 {
     DebugPrintFunc(new StackTrace());
     if (IsMyOrder(pOrder))
     {
         if (IsTradingOrder(pOrder))
         {
             ReqOrderAction(pOrder);
         }
         else if (pOrder.OrderStatus == EnumOrderStatusType.Canceled)
         {
             Console.WriteLine("--->>> 撤单成功");
         }
     }
 }
示例#7
0
        private void CtpTrader_OnRtnOrder(ThostFtdcOrderField pOrder)
        {
            orderOnWay = pOrder;

            if (pOrder.OrderStatus == EnumOrderStatusType.AllTraded)
            {
                isSuccess = true;
                autoResetEventOrderCompleted.Set();
            }
            else if (pOrder.OrderStatus == EnumOrderStatusType.Canceled)
            {
                isSuccess = false;
                autoResetEventOrderCompleted.Set();
            }
        }
示例#8
0
        public static OpenClose GetOpenClose(this ThostFtdcOrderField self)
        {
            switch (self.CombOffsetFlag_0)
            {
            case EnumOffsetFlagType.Close:
            case EnumOffsetFlagType.CloseToday:
            case EnumOffsetFlagType.CloseYesterday:
            case EnumOffsetFlagType.ForceClose:
            case EnumOffsetFlagType.LocalForceClose:
                return(OpenClose.Close);

            default:
                return(OpenClose.Open);
            }
        }
示例#9
0
 ///报单通知
 void OnRtnOrder(ThostFtdcOrderField pOrder)
 {
     __DEBUGPF__();
     if (IsMyOrder(pOrder))
     {
         if (IsTradingOrder(pOrder))
         {
             ReqOrderAction(pOrder);
         }
         else if (pOrder.OrderStatus == EnumOrderStatusType.Canceled)
         {
             Console.WriteLine("--->>> 撤单成功");
         }
     }
 }
示例#10
0
 void _trade_OnRspQryOrder(ThostFtdcOrderField pOrder, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pOrder != null)
     {
         var exists = this._orders.FirstOrDefault(_ => _.OrderSysID == pOrder.OrderSysID);
         if (exists == null)
         {
             this._orders.Add(pOrder);
         }
     }
     if (bIsLast)
     {
         this.Account.PendingOrders = this._orders.Where(_ => (_.OrderSysID ?? "").Trim().Length > 0 && _.GetOrderStatus() == OrderStatus.Pending).Select(_ => _.ToOptionOrder()).ToList();
     }
 }
示例#11
0
 public static OptionOrder ToOptionOrder(this ThostFtdcOrderField self)
 {
     return(new OptionOrder
     {
         InstrumentID = self.InstrumentID,
         FilledQty = self.VolumeTraded,
         LeavesQty = self.VolumeTotal,
         OrderID = self.OrderSysID,
         OpenClose = self.GetOpenClose(),
         Price = self.LimitPrice,
         Qty = self.VolumeTotalOriginal,
         Side = self.Direction == EnumDirectionType.Buy ? OrderSide.Buy : OrderSide.Sell,
         OrderTime = DateTime.ParseExact(self.InsertDate + " " + self.InsertTime, "yyyyMMdd HH:mm:ss", DateTimeFormatInfo.InvariantInfo),
         Status = self.GetOrderStatus()
     });
 }
示例#12
0
        void ReqOrderAction(ThostFtdcOrderField pOrder)
        {
            if (ORDER_ACTION_SENT)
            {
                return;
            }

            ThostFtdcInputOrderActionField req = new ThostFtdcInputOrderActionField();

            ///经纪公司代码
            req.BrokerID = pOrder.BrokerID;
            ///投资者代码
            req.InvestorID = pOrder.InvestorID;
            ///报单操作引用
            //	TThostFtdcOrderActionRefType	OrderActionRef;
            ///报单引用
            req.OrderRef = pOrder.OrderRef;
            ///请求编号
            //	TThostFtdcRequestIDType	RequestID;
            ///前置编号
            req.FrontID = FRONT_ID;
            ///会话编号
            req.SessionID = SESSION_ID;
            ///交易所代码
            //	TThostFtdcExchangeIDType	ExchangeID;
            ///报单编号
            //	TThostFtdcOrderSysIDType	OrderSysID;
            ///操作标志
            req.ActionFlag = CTP.EnumActionFlagType.Delete;
            ///价格
            //	TThostFtdcPriceType	LimitPrice;
            ///数量变化
            //	TThostFtdcVolumeType	VolumeChange;
            ///用户代码
            //	TThostFtdcUserIDType	UserID;
            ///合约代码
            req.InstrumentID = pOrder.InstrumentID;

            int iResult = api.ReqOrderAction(req);

            Console.WriteLine("--->>> 报单操作请求: " + ((iResult == 0) ? "成功" : "失败"));

            ORDER_ACTION_SENT = true;
        }
示例#13
0
        public override void OnRtnOrder(ThostFtdcOrderField pOrder)
        {
            var order = new Order
            {
                InstrumentID        = pOrder.InstrumentID,
                UserID              = pOrder.UserID,
                Direction           = (DirectionType)pOrder.Direction,
                CombOffsetFlag      = (OffsetFlag)pOrder.CombOffsetFlag_0,
                LimitPrice          = pOrder.LimitPrice,
                VolumeTotalOriginal = pOrder.VolumeTotalOriginal,
                OrderSubmitStatus   = (OrderSubmitStatus)pOrder.OrderSubmitStatus,
                OrderStatus         = (OrderStatus)pOrder.OrderStatus,
                VolumeTraded        = pOrder.VolumeTraded,
                VolumeTotal         = pOrder.VolumeTotal,
                InsertTime          = DateTimeHelper.GenerateTime(pOrder.InsertDate, pOrder.InsertTime),
                StatusMsg           = pOrder.StatusMsg,
            };

            OrderRecordViewModel.Instance.AddOrder(order);
        }
示例#14
0
        public static OrderStatus GetOrderStatus(this ThostFtdcOrderField self)
        {
            switch (self.OrderStatus)
            {
            case EnumOrderStatusType.AllTraded:
                return(OrderStatus.Filled);

            case EnumOrderStatusType.Canceled:
                return(OrderStatus.Canceled);

            case EnumOrderStatusType.NoTradeNotQueueing:
            case EnumOrderStatusType.NoTradeQueueing:
                return(OrderStatus.Pending);

            case EnumOrderStatusType.PartTradedNotQueueing:
            case EnumOrderStatusType.PartTradedQueueing:
                return(OrderStatus.Pending);

            default:
                return(OrderStatus.Unknown);
            }
        }
示例#15
0
 private bool IsMyOrder(ThostFtdcOrderField pOrder)
 {
     return(pOrder.FrontID == FRONT_ID &&
            pOrder.SessionID == SESSION_ID);
 }
示例#16
0
 /// <summary>
 /// 构造一个新实例
 /// </summary>
 /// <param name="MarketData">报单信息</param>
 public RtnOrderEventArgs(ThostFtdcOrderField orderField)
 {
     this.orderField = orderField;
 }
示例#17
0
 private void TraderAdapter_OnRtnOrder(ThostFtdcOrderField pOrder)
 {
 }
示例#18
0
 private void TD_OnCanceled(ThostFtdcOrderField pOrder)
 {
 }
示例#19
0
 public override void OnRtnOrder(ThostFtdcOrderField pOrder)
 {
     throw new NotImplementedException();
 }
示例#20
0
 /// <summary>
 /// 判断是否是我的报单
 /// </summary>
 /// <param name="pOrder"></param>
 /// <returns></returns>
 private bool IsMyOrder(ThostFtdcOrderField pOrder)
 {
     //return true;
     return ((pOrder.FrontID == trader.FrontID) && (pOrder.SessionID == trader.SessionID));
 }
示例#21
0
 bool IsTradingOrder(ThostFtdcOrderField pOrder)
 {
     return((pOrder.OrderStatus != EnumOrderStatusType.PartTradedNotQueueing) &&
            (pOrder.OrderStatus != EnumOrderStatusType.Canceled) &&
            (pOrder.OrderStatus != EnumOrderStatusType.AllTraded));
 }
示例#22
0
        /// <summary>
        /// 报单操作请求
        /// </summary>
        /// <param name="pOrder"></param>
        void ReqOrderAction(ThostFtdcOrderField pOrder)
        {
            if (ORDER_ACTION_SENT)
                return;

            ThostFtdcInputOrderActionField req = new ThostFtdcInputOrderActionField();
            //经纪公司代码
            req.BrokerID = pOrder.BrokerID;
            //投资者代码
            req.InvestorID = pOrder.InvestorID;
            //报单引用
            req.OrderRef = pOrder.OrderRef;
            //请求编号
               req.RequestID = 5;
            //前置编号
            req.FrontID = FRONT_ID;
            //会话编号
            req.SessionID = SESSION_ID;
            //交易所代码
            req.ExchangeID = INVESTOR_ID;
            //报单编号
            //	TThostFtdcOrderSysIDType	OrderSysID;
            //操作标志
            req.ActionFlag = KSFT.EnumActionFlagType.Delete;
            //用户代码
            req.UserID = INVESTOR_ID;
            //合约代码
            req.InstrumentID = pOrder.InstrumentID;

            int iResult = api.ReqOrderAction(req, ++iRequestID);
            Console.WriteLine("--->>> 报单操作请求: " + ((iResult == 0) ? "成功" : "失败"));

            ORDER_ACTION_SENT = true;
        }
示例#23
0
 /// <summary>
 /// 判断自己的订单
 /// </summary>
 /// <param name="pOrder"></param>
 /// <returns></returns>
 bool IsMyOrder(ThostFtdcOrderField pOrder)
 {
     return ((pOrder.FrontID == FRONT_ID) &&
             (pOrder.SessionID == SESSION_ID) &&
             (pOrder.OrderRef == ORDER_REF));
 }
示例#24
0
 void TD_OnTraded(ThostFtdcOrderField pOrder)
 {
 }
示例#25
0
 /// <summary>
 /// 撤单成功的处理
 /// </summary>
 /// <param name="pOrder"></param>
 void TD_OnCanceled(ThostFtdcOrderField pOrder)
 {
     if(pOrder.InstrumentID == this.option.InstrumentID)
     {
         if (this.option.PlaceLongOptionOrderRef == pOrder.OrderRef)
         {
             this.option.PlaceLongOptionOrderRef = null;
         }
         else if (this.option.PlaceShortOptionOrderRef == pOrder.OrderRef)
         {
             this.option.PlaceShortOptionOrderRef = null;
         }
         else if (this.option.CloseLongOptionOrderRef == pOrder.OrderRef)
         {
             this.option.CloseLongOptionOrderRef = null;
         }
         else if (this.option.CloseShortOptionOrderRef == pOrder.OrderRef)
         {
             this.option.CloseShortOptionOrderRef = null;
         }
     }
 }
示例#26
0
 /// <summary>
 /// 构造一个新实例
 /// </summary>
 /// <param name="MarketData">报单信息</param>
 /// <param name="Tag">关联数据</param>
 public RtnOrderEventArgs(ThostFtdcOrderField orderField, object Tag)
 {
     this.orderField = orderField;
     this.tag = Tag;
 }
示例#27
0
        /// <summary>
        /// 报单回报
        /// </summary>
        /// <param name="pOrder"></param>
        public void OnRtnOrder(ThostFtdcOrderField pOrder)
        {
            DateTime logtime = DateTime.Now;
            if (IsTradingOrder(pOrder))
            {
                if (IsMyOrder(pOrder))
                {
                    if (pOrder.ExchangeID != null && pOrder.ExchangeID != "" && pOrder.OrderSysID != null && pOrder.OrderSysID != "")
                    {
                        if (pOrder.OrderStatus != EnumOrderStatusType.Unknown)
                        {

                        }
                    }
                }
            }
            else if (pOrder.OrderStatus == EnumOrderStatusType.Canceled)
            {
                if (IsMyOrder(pOrder))
                {
                }
            }
            else if (pOrder.OrderStatus == EnumOrderStatusType.AllTraded)
            {
                if (IsMyOrder(pOrder))
                {
                }
            }
            else if (pOrder.OrderStatus == EnumOrderStatusType.PartTradedNotQueueing)
            {
                if (IsMyOrder(pOrder))
                {
                }
            }
            else if (pOrder.OrderStatus == EnumOrderStatusType.NoTradeNotQueueing)
            {
                if (IsMyOrder(pOrder))
                {
                }
            }
        }
示例#28
0
 /// <summary>
 /// 判断是否是错误报单
 /// </summary>
 /// <param name="pOrder"></param>
 /// <returns></returns>
 private bool IsErrorOrder(ThostFtdcOrderField pOrder)
 {
     return ((pOrder.OrderStatus == EnumOrderStatusType.Unknown) || pOrder.OrderSysID == "");
 }
示例#29
0
        /// <summary>
        /// 取消报单
        /// </summary>
        /// <param name="order"></param>
        /// <returns>-1--无效报单,0--下撤单指令成功,1--下撤单指令失败</returns>
        public int CancelOrder(ThostFtdcOrderField pOrder)
        {
            lock (ReqLock)
            {
                ThostFtdcInputOrderActionField req = new ThostFtdcInputOrderActionField();
                ///操作标志
                req.ActionFlag = EnumActionFlagType.Delete;
                ///经纪公司代码
                req.BrokerID = pOrder.BrokerID;
                ///交易所代码
                req.ExchangeID = pOrder.ExchangeID;
                ///前置编号
                req.FrontID = pOrder.FrontID;
                ///投资者代码
                req.InvestorID = pOrder.InvestorID;
                ///合约代码
                req.InstrumentID = pOrder.InstrumentID;
                ///报单引用
                req.OrderRef = pOrder.OrderRef;
                ///报单编号
                req.OrderSysID = pOrder.OrderSysID;
                //请求编号
                //req.RequestID = pOrder.RequestID;
                ///会话编号
                req.SessionID = pOrder.SessionID;
                ///用户代码
                req.UserID = pOrder.UserID;
                int iResult = trader.ReqOrderAction(req, ++RequestID);

                if (OrderRef2ArbitrageStategyMap.ContainsKey(pOrder.OrderRef))
                {
                    OrderRef2ArbitrageStategyMap.Remove(pOrder.OrderRef);
                }
                return iResult;
            }
        }
示例#30
0
 ///请求查询报单响应
 public void OnRspQryOrder(ThostFtdcOrderField pOrder, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (!IsErrorRspInfo(pRspInfo))
     {
     }
 }
示例#31
0
 /// <summary>
 /// 对报单回报的处理
 /// </summary>
 /// <param name="pOrder"></param>
 private void TD_OnTrading(ThostFtdcOrderField pOrder)
 {
     if (pOrder.InstrumentID == "IF1407" || pOrder.InstrumentID == "IF1408" || pOrder.InstrumentID == "IF1409" || pOrder.InstrumentID == "IF1412")
     {
         if (pOrder.VolumeTraded != 0)
         {
             if (!this.tradingOrderDictionary.ContainsKey(pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID))
             {
                 if (pOrder.Direction == EnumDirectionType.Buy && pOrder.CombOffsetFlag_0 == EnumOffsetFlagType.Open)
                 {
                     if (this.longPosition.Position + pOrder.VolumeTraded == 0)
                     {
                         this.longPosition.PositionCost = 0;
                     }
                     else
                     {
                         this.longPosition.PositionCost = (this.longPosition.PositionCost * this.longPosition.Position +
                             pOrder.LimitPrice * pOrder.VolumeTraded) / (this.longPosition.Position + pOrder.VolumeTraded);
                     }
                     this.longPosition.Position += pOrder.VolumeTraded;
                 }
                 else if (pOrder.Direction == EnumDirectionType.Buy && pOrder.CombOffsetFlag_0 != EnumOffsetFlagType.Open)
                 {
                     if (this.shortPosition.Position + pOrder.VolumeTraded == 0)
                     {
                         this.shortPosition.PositionCost = 0;
                     }
                     else
                     {
                         this.shortPosition.PositionCost = (this.shortPosition.PositionCost * this.shortPosition.Position +
                             pOrder.LimitPrice * pOrder.VolumeTraded) / (this.shortPosition.Position + pOrder.VolumeTraded);
                     }
                     this.shortPosition.Position -= pOrder.VolumeTraded;
                 }
                 else if (pOrder.Direction == EnumDirectionType.Sell && pOrder.CombOffsetFlag_0 == EnumOffsetFlagType.Open)
                 {
                     if (this.shortPosition.Position + pOrder.VolumeTraded == 0)
                     {
                         this.shortPosition.PositionCost = 0;
                     }
                     else
                     {
                         this.shortPosition.PositionCost = (this.shortPosition.PositionCost * this.shortPosition.Position +
                             pOrder.LimitPrice * pOrder.VolumeTraded) / (this.shortPosition.Position + pOrder.VolumeTraded);
                     }
                     this.shortPosition.Position += pOrder.VolumeTraded;
                 }
                 else if (pOrder.Direction == EnumDirectionType.Sell && pOrder.CombOffsetFlag_0 != EnumOffsetFlagType.Open)
                 {
                     if (this.longPosition.Position + pOrder.VolumeTraded == 0)
                     {
                         this.longPosition.PositionCost = 0;
                     }
                     else
                     {
                         this.longPosition.PositionCost = (this.longPosition.PositionCost * this.longPosition.Position +
                             pOrder.LimitPrice * pOrder.VolumeTraded) / (this.longPosition.Position + pOrder.VolumeTraded);
                     }
                     this.longPosition.Position -= pOrder.VolumeTraded;
                 }
                 if (pOrder.VolumeTotal != 0)
                 {
                     this.tradingOrderDictionary.Add(pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID, pOrder);
                 }
             }
             else
             {
                 if (pOrder.Direction == EnumDirectionType.Buy && pOrder.CombOffsetFlag_0 == EnumOffsetFlagType.Open)
                 {
                     if (this.longPosition.Position - (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded) == 0)
                     {
                         this.longPosition.PositionCost = 0;
                     }
                     else
                     {
                         this.longPosition.PositionCost = (this.longPosition.PositionCost * this.longPosition.Position -
                             pOrder.LimitPrice * (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded)) / (this.longPosition.Position -
                             (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded));
                     }
                     this.longPosition.Position += pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded;
                 }
                 else if (pOrder.Direction == EnumDirectionType.Buy && pOrder.CombOffsetFlag_0 != EnumOffsetFlagType.Open)
                 {
                     if (this.shortPosition.Position - (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded) == 0)
                     {
                         this.shortPosition.PositionCost = 0;
                     }
                     else
                     {
                         this.shortPosition.PositionCost = (this.shortPosition.PositionCost * this.shortPosition.Position -
                             pOrder.LimitPrice * (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded)) / (this.shortPosition.Position -
                             (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded));
                     }
                     this.shortPosition.Position -= pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded;
                 }
                 else if (pOrder.Direction == EnumDirectionType.Sell && pOrder.CombOffsetFlag_0 == EnumOffsetFlagType.Open)
                 {
                     if (this.shortPosition.Position - (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded) == 0)
                     {
                         this.shortPosition.PositionCost = 0;
                     }
                     else
                     {
                         this.shortPosition.PositionCost = (this.shortPosition.PositionCost * this.shortPosition.Position -
                             pOrder.LimitPrice * (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded)) / (this.shortPosition.Position -
                             (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded));
                     }
                     this.shortPosition.Position += pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded;
                 }
                 else if (pOrder.Direction == EnumDirectionType.Sell && pOrder.CombOffsetFlag_0 != EnumOffsetFlagType.Open)
                 {
                     if (this.longPosition.Position - (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded) == 0)
                     {
                         this.longPosition.PositionCost = 0;
                     }
                     else
                     {
                         this.longPosition.PositionCost = (this.longPosition.PositionCost * this.longPosition.Position -
                             pOrder.LimitPrice * (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded)) / (this.longPosition.Position -
                             (pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded));
                     }
                     this.longPosition.Position -= pOrder.VolumeTraded - this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID].VolumeTraded;
                 }
                 if (pOrder.VolumeTotal == 0)
                 {
                     this.tradingOrderDictionary.Remove(pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID);
                 }
                 else
                 {
                     this.tradingOrderDictionary[pOrder.OrderRef + "-" + pOrder.FrontID + "-" + pOrder.SessionID] = pOrder;
                 }
             }
         }
         else
         {
             if (this.PlaceLongOptionOrderRef == pOrder.OrderRef)
             {
                 this.LongOptionOrder = pOrder;
             }
             else if (this.PlaceShortOptionOrderRef == pOrder.OrderRef)
             {
                 this.ShortOptionOrder = pOrder;
             }
             else if (this.CloseLongOptionOrderRef == pOrder.OrderRef)
             {
                 this.CloseLongOptionOrder = pOrder;
             }
             else if (this.CloseShortOptionOrderRef == pOrder.OrderRef)
             {
                 this.CloseShortOptionOrder = pOrder;
             }
         }
     }
 }
示例#32
0
 ///报单通知
 public void OnRtnOrder(ThostFtdcOrderField pOrder)
 {
     cMainForm.SetTDOnRtnOrder((object)pOrder);
 }
示例#33
0
 /// <summary>
 /// 根据委托撤单信息构成键,ExchangeID + OrderSysID
 /// </summary>
 /// <param name="pOrder"></param>
 /// <returns></returns>
 private string GetOrderKey(ThostFtdcOrderField pOrder)
 {
     return(string.Format("{0}:{1}", pOrder.ExchangeID, pOrder.OrderSysID));
 }
示例#34
0
 /// <summary>
 /// 判断成交单是否是我的报单
 /// </summary>
 /// <param name="pOrder"></param>
 /// <param name="pTrade"></param>
 /// <returns></returns>
 private bool IsMyTrade(ThostFtdcOrderField pOrder, ThostFtdcTradeField pTrade)
 {
     return (pTrade != null && pOrder != null && (pTrade.OrderRef == pOrder.OrderRef) &&
             (pTrade.BrokerID == pOrder.BrokerID) && (pTrade.BrokerOrderSeq == pOrder.BrokerOrderSeq) &&
             (pTrade.ExchangeID == pOrder.ExchangeID) && (pTrade.TraderID == pOrder.TraderID) &&
             (pTrade.OrderLocalID == pOrder.OrderLocalID) && (pTrade.OrderSysID == pOrder.OrderSysID));
 }
示例#35
0
 bool IsMyOrder(ThostFtdcOrderField pOrder)
 {
     return((pOrder.FrontID == FRONT_ID) &&
            (pOrder.SessionID == SESSION_ID) &&
            (pOrder.OrderRef == ORDER_REF));
 }
示例#36
0
 void TraderAdapter_OnRspQryOrder(ThostFtdcOrderField pOrder, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
 }
示例#37
0
 /// <summary>
 /// 判断交易订单
 /// </summary>
 /// <param name="pOrder"></param>
 /// <returns></returns>
 bool IsTradingOrder(ThostFtdcOrderField pOrder)
 {
     return ((pOrder.OrderStatus != EnumOrderStatusType.PartTradedNotQueueing) &&
             (pOrder.OrderStatus != EnumOrderStatusType.Canceled) &&
             (pOrder.OrderStatus != EnumOrderStatusType.AllTraded));
 }
示例#38
0
 private void TD_OnTrading(ThostFtdcOrderField pOrder)
 {
 }
示例#39
0
 public override void OnRtnOrder(ThostFtdcOrderField pOrder)
 {
     var order = new Order
     {
         InstrumentID = pOrder.InstrumentID,
         UserID = pOrder.UserID,
         Direction = (DirectionType)pOrder.Direction,
         CombOffsetFlag = (OffsetFlag)pOrder.CombOffsetFlag_0,
         LimitPrice = pOrder.LimitPrice,
         VolumeTotalOriginal = pOrder.VolumeTotalOriginal,
         OrderSubmitStatus = (OrderSubmitStatus)pOrder.OrderSubmitStatus,
         OrderStatus = (OrderStatus)pOrder.OrderStatus,
         VolumeTraded = pOrder.VolumeTraded,
         VolumeTotal = pOrder.VolumeTotal,
         InsertTime = DateTimeHelper.GenerateTime(pOrder.InsertDate, pOrder.InsertTime),
         StatusMsg = pOrder.StatusMsg,
     };
     OrderRecordViewModel.Instance.AddOrder(order);
 }
示例#40
0
        /// <summary>
        /// 报单查询应答
        /// </summary>
        /// <param name="pOrder"></param>
        /// <param name="pRspInfo"></param>
        /// <param name="nRequestID"></param>
        /// <param name="bIsLast"></param>
        void OnRspQryOrder(ThostFtdcOrderField pOrder, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            DebugPrintFunc(new StackTrace());
            if (bIsLast && !IsErrorRspInfo(pRspInfo))
            {

                //交易查询请求
                ReqQryTrade();
            }
        }
示例#41
0
 /// <summary>
 /// 报单通知
 /// </summary>
 /// <param name="pOrder"></param>
 void OnRtnOrder(ThostFtdcOrderField pOrder)
 {
     DebugPrintFunc(new StackTrace());
     if (IsMyOrder(pOrder))
     {
         if (IsTradingOrder(pOrder))
             ReqOrderAction(pOrder);
         else if (pOrder.OrderStatus == EnumOrderStatusType.Canceled)
             Console.WriteLine("--->>> 撤单成功");
     }
 }
示例#42
0
 public override void OnRtnOrder(ThostFtdcOrderField pOrder)
 {
     throw new NotImplementedException();
 }