IBKR TWS API - 如何判断所有行权的 reqOptionsMktData 何时完成?
我刚刚开始使用 Java 上的 IBKR API。我按照 API 示例代码(特别是期权链示例)来了解如何获取特定股票的期权链。
该示例对此效果很好,但我有一个问题 - 我如何知道所有数据是否已加载?似乎没有办法告诉。示例代码能够判断何时加载了每个单独的行,但似乎没有办法判断何时成功加载了所有罢工。
我认为使用 tickSnapshotEnd()
会有好处,但它似乎并没有像我期望的那样工作。我希望每个完成的请求都会调用它一次。例如,如果我在 2022 年 3 月 18 日到期时查询像 SOFI 这样的股票,我会看到有 35 次罢工,但 tickSnapshotEnd()
被调用了 40 多次,其中一些罢工重复不止一次。
请注意,我正在请求快照数据,而不是实时/流数据
I am just getting started with IBKR API on Java. I am following the API sample code, specifically the options chain example, to figure out how to get options chains for specific stocks.
The example works well for this, but I have one question - how do I know once ALL data has been loaded? There does not seem to be a way to tell. The sample code is able to tell when each individual row has been loaded, but there doesn't seem to be a way to tell when ALL strikes have been successfully loaded.
I thought that using tickSnapshotEnd()
would be beneficial, but it doesn't not seem to work as I would expect it to. I would expect it to be called once for every request that completes. For example, if I do a query for a stock like SOFI on the 2022/03/18 expiry, I see that there are 35 strikes but tickSnapshotEnd()
is called 40+ times, with some strikes repeated more than once.
Note that I am doing requests for snapshot data, not live/streaming data
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
reqOptionsMktData 显然是您正在使用的示例代码中的一个方法。不确定您使用的特定代码,所以这是一般响应。
首先你是对的,没有办法通过 API 来判断,这必须由客户端完成。当然,它会提供发出请求时使用的 requestID。客户端需要记住每个 requestID 的用途,并决定在回调中收到该信息时如何处理该信息。
这可以通过字典或哈希表来完成,在回调中接收数据后检查链是否完整。
来自 API 的消息传递通常会产生意想不到的结果,接收额外的消息很常见,这是客户端需要考虑的事情。考虑 API 无状态,并跟踪客户端中的所有内容。
看来您指的是监管快照,我建议您查看一下成本。它很快就会增加流媒体实时数据的价格。再加上 1/秒的限制将使链需要很长时间才能加载。我什至不建议使用带有实时数据的快照,自己取消请求很简单,而且速度更快。
类似于(这显然是不完整的 C#,只是一个起点)
reqOptionsMktData is obviously a method in the sample code you are using. Not sure what particular code your using, so this is a general response.
Firstly you are correct, there is no way to tell via the API, this must be done by the client. Of course it will provide the requestID that was used when the request was made. The client needs to remember what each requestID was for and decide how to process that information when it is received in the callbacks.
This can be done via a dictionary or hashtable, where upon receiving data in the callback then check if the chain is complete.
Message delivery from the API often has unexpected results, receiving extra messages is common and is something that needs to be taken into account by the client. Consider the API stateless, and track everything in the client.
Seems you are referring to Regulatory Snapshots, I would encourage you to look at the cost. It could quite quickly add up to the price of streaming live data. Add to that the 1/sec limit will make a chain take a long time to load. I wouldn't even recommend using snapshots with live data, cancelling the request yourself is trivial and much faster.
Something like (this is obviously incomplete C#, just a starting point)