IB TWS API C#foreach符号获得二级



我试图获得符号列表的二级:

IBApi.Contract contract = new IBApi.Contract();
List<IBApi.TagValue> mktDataOptions = new List<IBApi.TagValue>();
int Ticker = 1;
foreach (var line in File.ReadLines(textBox1.Text))
{
contract.Symbol = line;
contract.SecType = "STK";
contract.Exchange = "SMART";
contract.Currency = "GBP";

ibClient.ClientSocket.reqMarketDepth(Ticker, contract, 5, true, new List<TagValue>());
ibClient.ClientSocket.cancelMktDepth(Ticker, false);
Ticker++;
}

在3个符号后,我得到错误:

Code: 309, Msg: Max number (3) of market depth requests has been reached.

为什么,我使用cancelMktDepth作为停止数据?

谢谢你的帮助!

Marc Jone

如果您在TWS中按[Ctrl][Alt]=键,将弹出一个小窗口,让您知道当前对数据请求的限制。您似乎有3个可用的深度请求(默认值(。

查看您的代码,在请求数据和取消数据之间没有延迟。很可能是请求没有时间处理。

此外,Level2通过"添加"更新"删除"模型不断更新,因此您不会一次收到整个表。

您可能会发现以下内容很有用;

private readonly List<DeepBookMessage> bids, asks;

private void Recv_UpdateMktDepth(DeepBookMessage msg)
{
List<DeepBookMessage> book = msg.Side == 0 ? asks : bids;
switch(msg.Operation)
{
case 0:   // 0 = Insert quote in new position
book.Insert(msg.Position, msg);
break;
case 1:   // 1 = Update quote in existing position
while(book.Count < msg.Position) 
book.Add(new(-1, -1, -1, msg.Side, -1, -1, "", true));
book[msg.Position] = msg;
break;
case 2:   // 2 = Delete current quote. Make sure we have a quote at this level
if(book.Count > msg.Position) book.RemoveAt(msg.Position);
break;
}
}

相关内容

  • 没有找到相关文章

最新更新