我启用了延迟市场数据,使用:
ibClient.ClientSocket.reqMarketDataType(4);
但是我的一些市场数据会延迟,而一些不会。有什么方法可以告诉我们哪些是延迟的(最好是延迟多少)?
当您收到tickprice消息时,请注意字段参数,它告诉您它是延迟的还是实时的。另外,注册MarketDataType事件将为您提供另一条消息作为数据类型的标头。
类似:
public enum TickFields:int
{
BidPrice = 1,
AskPrice = 2,
LastPrice = 4,
DelayedBid = 66,
DelayedAsk = 67,
DelayedLast = 68,
}
public enum MarketDataTypes:int
{
Unknown = 0,
Live = 1,
Frozen = 2,
Delayed = 3,
DelayedFrozen = 4,
}
以上常量可在https://interactivebrokers.github.io/tws-api/tick_types.html和https://interactivebrokers.github.io/tws-api/market_data_type.html获得
//in constructor
ibClient.TickPrice += Recv_TickPrice;
ibClient.MarketDataType += Recv_MarketDataType;
private void Recv_TickPrice(TickPriceMessage msg)
{
switch((TickFields)msg.Field)
{
case TickFields.AskPrice:
case TickFields.DelayedAsk:
// do something with the ask price
break;
case TickFields.BidPrice:
case TickFields.DelayedBid:
// do something with the bid price
break;
default:
return;
}
}
private void Recv_MarketDataType(MarketDataTypeMessage msg)
{
Program.Log(LogLevel.Debug, "> Recv_MktDataType()", $"MarketDataType: {(MarketDataTypes)msg.MarketDataType}");
switch((MarketDataTypes)msg.MarketDataType)
{
case MarketDataTypes.Live:
break;
case MarketDataTypes.Frozen:
break;
case MarketDataTypes.Delayed:
break;
case MarketDataTypes.DelayedFrozen:
break;
default:
return;
}
}
如果我没记错的话,在TickPriceMessages的每个块之前发送一个MarketDataTypeMessage,所以当TWS将你的reqMarketDataType(FrozenDelayed)升级为延迟(或live -如果你订阅了该工具的数据)时,你应该收到以下内容:
MarketDataTypeMessage(冻)
TickPriceMessage(多个)
MarketDataTypeMessage(现场/延迟)
TickPriceMessage(多个)
当然,您接收到的ticktypes将取决于reqMktData中输入的genericTickList字符串。