【问题标题】:IB TWS API C# foreach symbol get Level IIIB TWS API C# foreach 符号获得二级
【发布时间】:2022-10-25 08:19:14
【问题描述】:

我尝试获得二级符号列表:

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 停止数据?

感谢帮助!

马克·琼斯

【问题讨论】:

    标签: c# interactive-brokers tws


    【解决方案1】:

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

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

    此外,Level2 通过“添加”“插入”“删除”模型不断更新,因此您不太可能一次收到整个表格。

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

    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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-26
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 2021-12-07
      • 2022-01-10
      • 2020-10-28
      • 1970-01-01
      相关资源
      最近更新 更多