Keyboard Shortcuts
Likes
Search
Best method for getting level 2 market depth snapshots on a large number of equities
Hi all.
As most probably know, even if paying for extra streams, there is a hard limit of around 10 market depth streams that can be open at any one time. If I wanted to see a snapshot of level 2 depth data on, say, 30 stocks, what is the best way of accomplishing this? What I currently do is this: Let's say I'm allowed to have 5 open depth streams at once. Then in my code I have a loop that iterates through my list of 30 stocks, but ensuring that only a maximum of 5 streams are open at any one time. While a stream is open, the code checks whether I have data down to a specified depth, say, 10 levels, and as soon as I reach that depth on both bid and ask sides, I close the stream and open a new one. I also have a timeout, so that if any one stream has been open for too long it gets automatically closed. In this way I iterate through the list of 30 stocks, such that at the end, I have a snapshot of the depth across all 30 stocks. Obviously some of the data will be stale at this point, but for lightly traded stocks I haven't found it to be too much of an issue. One other point I should add is that in practice, I've found that I need to have one less stream than my maximum open at a time, otherwise sometimes things overlap and I get an automatic disconnection for attempting to open too many streams at once. So, are there any clever ways for improving on this approach that people are aware of, or is this about the best I can expect to do? BTW, I usually trade ASX equities, if that makes any difference. Cheers all, Colin |
I would have used the same approach and cannot see a way to do it differently. How long does it take to grab a snapshot for 30 instruments? When you are done with a snapshot it will take a while for your request to be finalized. TWS sees it right away, but I am sure they won't add the feed back to the "available" pool until TWS receives a cancellation confirmation from the IBKR back-end. So I am not surprised that the next might get denied until TWS has received a cancellation confirmation from IBKR. Unfortunately, has no callback that indicates to you when it is safe to make the next request. This could potentially be an ongoing area of instability. The hard limit for the number of simultaneous Level 2 streams must have been increased, since now says you can have up to 60. But you can only get 10 of them by purchasing booster packs. To get to 60 you must have enough equity or commission to "earn" them. According to the fine print in
If my math is correct, $48,000 in monthly commission or an account value of $60Mio gets you to the 6,000 market line allocations you'd need for 60 simultaneous market depth feeds. Or half of that for 30 feeds :-) 闯ü谤驳别苍 |
Thanks for the response Jurgen, really appreciate it. Everything you said about the cancellation requests makes sense to me.
On average, I find I'm able to get about 1 per second if I limit myself to one stream maximum. With a two stream maximum I can get somewhere between 1.5 and 1.8 per second. With a three stream maximum I was getting a bit over 2 per second, but that's my maximum number of streams alas. This is all trading on my own account, so unfortunately I'm a wee bit short of the account values needed to get awarded bonus streams :-)??? and I'm not currently paying for any booster packs. Cheers, Colin On Tue, 2 Aug 2022 at 17:34, 闯ü谤驳别苍 Reinold via <TwsApiOnGroupsIo=[email protected]> wrote:
|
Somewhat related question - I'd like book data for equities, don't need options. When I run
reqMktDepth(101, apple_contract, 5, True,[]) # 10 levelsI hit ERROR 101 2152 Exchanges - Depth: ISLAND; IEX; Top: BYX; AMEX; PEARL; CHX; NYSENAT; PSX; MEMX; EDGEA; LTSE; ISE; DRCTEDGE; Need additional market data permissions - Depth: BATS; ARCA; BEX; NYSE;I've been adding the additional packages but the market names seem to have a lot of ambiguity (eg what is NYSE - NYSE ARCABOOK? I'm basically looking for the minimum possible subscriptions to be able to see market depth data from any equity, don't need comprehensive coverage. |
开云体育If your question is what data you should subscribe to be able to get market depth from any (US) equity, why don’t you just ask IB? They are surely more likely to give you a full and correct answer than we API users. ? |