Пример #1
0
        public void UpdateTrade(CustomTrade trade)
        {
            var ins = Instruments[trade.InstrumentID] as FutureInstrument;

            // 更新仓位
            if (trade.OffsetFlag == EnumOffsetFlagType.Open)
            {
                if (trade.Direction == EnumDirectionType.Sell)
                {
                    ins.SellPosition++;
                }
                else
                {
                    ins.BuyPosition++;
                }
            }
            else
            {
                if (trade.Direction == EnumDirectionType.Buy)
                {
                    ins.SellPosition--;
                }
                else
                {
                    ins.BuyPosition--;
                }
            }
        }
Пример #2
0
 private void UpdateTrade(CustomTrade trade)
 {
     lock (tradeLocker)
     {
         foreach (var f in formList)
         {
             // 推送成交回报
             if (!f.IsDisposed)
             {
                 f.OnRtnTrade(trade);
             }
         }
     }
 }
Пример #3
0
        public void OnRtnTrade(CustomTrade pTrade)
        {
            if (!IsMyTrade(pTrade))
            {
                return;
            }

            if (pTrade.InstrumentID == inParam.InIF1)
            {
                if (pTrade.Direction == (int)BS_CODE.Buy) // 跨期自动交易的IF1和IF2不能随意变更,否则对成交汇总的计算会造成错误影响
                {
                    TradeDetail_IF1BO.TradeVol    += pTrade.TradeVol;
                    TradeDetail_IF1BO.TradeAmount += pTrade.TradeVol * pTrade.TradePrice * IF_CONTRACT_FACTOR;

                    // 更新持仓(按对计算)
                    TradeSummary.Position += pTrade.TradeVol;
                }
                else
                {
                    TradeDetail_IF1SC.TradeVol    += pTrade.TradeVol;
                    TradeDetail_IF1SC.TradeAmount += pTrade.TradeVol * pTrade.TradePrice * IF_CONTRACT_FACTOR;

                    // 更新持仓(按对计算)
                    TradeSummary.Position -= pTrade.TradeVol;
                }
            }
            else if (pTrade.InstrumentID == inParam.InIF2)
            {
                if (pTrade.Direction == BS_CODE.Sell)
                {
                    TradeDetail_IF2SO.TradeVol    += pTrade.TradeVol;
                    TradeDetail_IF2SO.TradeAmount += pTrade.TradeVol * pTrade.TradePrice * IF_CONTRACT_FACTOR;
                }
                else
                {
                    TradeDetail_IF2BC.TradeVol    += pTrade.TradeVol;
                    TradeDetail_IF2BC.TradeAmount += pTrade.TradeVol * pTrade.TradePrice * IF_CONTRACT_FACTOR;
                }
            }

            TradeSummary.TradeCount += pTrade.TradeVol;

            TradeSummary.OpenAvgPrice  = TradeDetail_IF1BO.TradeAvgPrice - TradeDetail_IF2SO.TradeAvgPrice;
            TradeSummary.CloseAvgPrice = TradeDetail_IF1SC.TradeAvgPrice - TradeDetail_IF2BC.TradeAvgPrice;
            TradeSummary.RealProfit    = (TradeSummary.CloseAvgPrice - TradeSummary.OpenAvgPrice) * Math.Min(TradeDetail_IF1BO.TradeVol, TradeDetail_IF1SC.TradeVol) * 300;
            //TradeSummary.FloatProfit = (lastHQInfo.CurrentSpread - TradeSummary.OpenAvgPrice) * TradeSummary.Position * 300;
            TradeSummary.Fee         = (TradeDetail_IF1BO.TradeAmount + TradeDetail_IF1SC.TradeAmount + TradeDetail_IF2BC.TradeAmount + TradeDetail_IF2SO.TradeAmount) * TRADE_FEE_RETIO;
            TradeSummary.TotalProfit = TradeSummary.RealProfit + TradeSummary.FloatProfit - TradeSummary.Fee;
        }
Пример #4
0
        ///成交通知
        private void OnRtnTrade(ThostFtdcTradeField pTrade)
        {
            __DEBUGPF__();

            // 更新成交回报信息
            CustomTrade customTrade = new CustomTrade();

            customTrade.tradeRef     = pTrade.ExchangeID + "_" + pTrade.OrderSysID;         // 成交回报的唯一编号
            customTrade.InstrumentID = pTrade.InstrumentID;
            customTrade.Direction    = pTrade.Direction;
            customTrade.OffsetFlag   = pTrade.OffsetFlag;
            customTrade.TradePrice   = pTrade.Price;
            customTrade.TradeVol     = pTrade.Volume;
            customTrade.TradeTime    = pTrade.TradeTime;

            // 处理成交回报
            if (HandleRtnTradeDel != null)
            {
                //HandleRtnTradeDel.BeginInvoke(customTrade, null, null);
                HandleRtnTradeDel(customTrade);
            }
        }
Пример #5
0
        ///成交通知
        private void OnRtnTrade(ThostFtdcTradeField pTrade)
        {
            __DEBUGPF__();

            // 更新成交回报信息
            CustomTrade customTrade = new CustomTrade();

            customTrade.tradeRef     = pTrade.ExchangeID + "_" + pTrade.OrderSysID;         // 成交回报的唯一编号
            customTrade.InstrumentID = pTrade.InstrumentID;
            customTrade.Direction    = (pTrade.Direction == EnumDirectionType.Buy) ? BS_CODE.Buy : BS_CODE.Sell;
            customTrade.OffsetFlag   = (pTrade.OffsetFlag == EnumOffsetFlagType.Open) ? OC_CODE.Open : OC_CODE.Close;
            customTrade.TradePrice   = pTrade.Price;
            customTrade.TradeVol     = pTrade.Volume;
            customTrade.TradeTime    = pTrade.TradeTime;

            // 处理成交回报
            if (HandleRtnTradeDel != null)
            {
                //HandleRtnTradeDel.BeginInvoke(customTrade, null, null);
                HandleRtnTradeDel(customTrade);
            }
        }
Пример #6
0
 bool IsMyTrade(CustomTrade pTrade)
 {
     return((order0 != null && order0.tradeRef == pTrade.tradeRef) ||
            (order1 != null && order1.tradeRef == pTrade.tradeRef) ||
            (order2 != null && order2.tradeRef == pTrade.tradeRef));
 }
Пример #7
0
 private void OnRtnTradeInternal(CustomTrade trade)
 {
     spreadTrader.OnRtnTrade(trade);
 }
Пример #8
0
        public void OnRtnTrade(CustomTrade trade)
        {
            var del = new HandleRtnTradeDelegate(OnRtnTradeInternal);

            this.BeginInvoke(del, new object[] { trade });
        }