private void CTPOnRspSubMarketData(ref CThostFtdcSpecificInstrumentField pSpecificInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { String ID = pSpecificInstrument.InstrumentID; String ERROR = pRspInfo.ErrorMsg; int R_ID = nRequestID; bool IsL = bIsLast; HaiFeng.MarketData tick = DicTick.GetOrAdd(ID, new HaiFeng.MarketData { InstrumentID = ID, }); if (_OnRtnTick == null) { return; } _OnRtnTick(this, new TickEventArgs { Tick = tick }); }
/// <summary> /// 深度行情通知,当SubscribeMarketData订阅行情后,行情通知由此推送 /// </summary> /// <param name="pDepthMarketData"></param> private void CTPOnRtnDepthMarketData(ref CThostFtdcDepthMarketDataField pDepthMarketData) { CThostFtdcDepthMarketDataField f = pDepthMarketData; if (string.IsNullOrEmpty(f.InstrumentID) || string.IsNullOrEmpty(f.UpdateTime) || double.IsInfinity(f.UpperLimitPrice)) //过滤无穷大/小 { return; } //修正last=double.max if (Math.Abs(f.LastPrice - double.MaxValue) < double.Epsilon) { if (Math.Abs(f.AskPrice1 - double.MaxValue) > double.Epsilon) { f.LastPrice = f.AskPrice1; } else if (Math.Abs(f.BidPrice1 - double.MaxValue) > double.Epsilon) { f.LastPrice = f.BidPrice1; } else { return; } } //去掉tradingday字段 //if (string.IsNullOrEmpty(f.TradingDay)) //{ // f.TradingDay = this.TradingDay; //日期:实盘中某些交易所,此字段为空 //} //if (string.IsNullOrEmpty(f.ActionDay)) //此字段可能为空 //{ // f.ActionDay = this.TradingDay; //} //f.ExchangeID = instrument.ExchangeID; //处理,单边有挂边的情况 if (f.AskPrice1 > f.UpperLimitPrice) //未赋值的数据 { f.AskPrice1 = f.LastPrice; } if (f.BidPrice1 > f.UpperLimitPrice) { f.BidPrice1 = f.LastPrice; } //修最高/最低 if (Math.Abs(f.HighestPrice - double.MaxValue) < double.Epsilon) { f.HighestPrice = f.AskPrice1; } if (Math.Abs(f.LowestPrice - double.MaxValue) < double.Epsilon) { f.LowestPrice = f.BidPrice1; } HaiFeng.MarketData tick = DicTick.GetOrAdd(f.InstrumentID, new HaiFeng.MarketData { InstrumentID = f.InstrumentID, }); if (f.UpdateMillisec == 0 && f.UpdateTime == tick.UpdateTime && tick.UpdateMillisec < 990) //某些交易所(如郑商所)相同秒数的ms均为0 { f.UpdateMillisec = tick.UpdateMillisec + 10; } tick.AskPrice = f.AskPrice1; tick.AskVolume = f.AskVolume1; tick.AveragePrice = f.AveragePrice; tick.BidPrice = f.BidPrice1; tick.BidVolume = f.BidVolume1; tick.LastPrice = f.LastPrice; tick.OpenInterest = f.OpenInterest; tick.UpdateMillisec = f.UpdateMillisec; tick.UpdateTime = f.UpdateTime; tick.Volume = f.Volume; tick.UpperLimitPrice = f.UpperLimitPrice; tick.LowerLimitPrice = f.LowerLimitPrice; //避免突然的波动 bool crack = false; if (tick.LastPrice != 0) //非首tick { crack = Math.Abs(this.DicTick[tick.InstrumentID].LastPrice - tick.LastPrice) > 100 * (f.AskPrice1 - f.BidPrice1); } this.DicTick[tick.InstrumentID] = tick; if (_OnRtnTick == null || crack) { return; //剧烈波动过滤掉 } _OnRtnTick(this, new TickEventArgs { Tick = tick }); }