示例#1
0
        private void OnRtnTrade(IntPtr pTraderApi, ref CThostFtdcTradeField pTrade)
        {
            tdlog.Info("时{0},合约{1},方向{2},开平{3},价{4},量{5},引用{6},成交编号{7}",
                       pTrade.TradeTime, pTrade.InstrumentID, pTrade.Direction, pTrade.OffsetFlag,
                       pTrade.Price, pTrade.Volume, pTrade.OrderRef, pTrade.TradeID);

            //找到自己发送的订单,标记成交
            string strSysID = string.Format("{0}:{1}", pTrade.ExchangeID, pTrade.OrderSysID);
            string strKey;

            if (!orderMap.TryGetValue(strSysID, out strKey))
            {
                return;
            }

            GenericOrderItem item;

            if (orderMap.TryGetValue(strKey, out item))
            {
                MultiOrderLeg leg   = item.GetLeg(CTPAPI.FromCTP(pTrade.Direction), pTrade.InstrumentID);
                SingleOrder   order = leg.Order;
#if CTP
                double Price = pTrade.Price;
#elif CTPZQ
                double Price = Convert.ToDouble(pTrade.Price);
#endif
                int Volume = pTrade.Volume;

                int LeavesQty = (int)order.LeavesQty - Volume;
                EmitFilled(order, Price, Volume, CommType.Absolute, 0);

                // 成交完成,清理数据
                OnRtnTradeLastStatus(item, pTrade, strSysID, strKey);
            }
        }
示例#2
0
        private void EmitCancelReject(GenericOrderItem item, int error_id, string message)
        {
            TextResponse r = new TextResponse()
            {
                Error    = CTPAPI.FromCTP(error_id),
                ErrorID  = error_id,
                ErrorMsg = message,
            };

            foreach (var leg in item.GetLegs())
            {
                r.OpenClose    = leg.OpenClose;
                leg.Order.Text = r.ToString();
                EmitCancelReject(leg.Order, leg.Order.OrdStatus, r.ToString());
            }
        }