Getting Multiple Last Price Quotes from Interactive Brokers's API
Asked Answered
R

1

7

I have a question regarding the Python API of Interactive Brokers.

Can multiple asset and stock contracts be passed into reqMktData() function and obtain the last prices? (I can set the snapshots = TRUE in reqMktData to get the last price. You can assume that I have subscribed to the appropriate data services.)

To put things in perspective, this is what I am trying to do:

1) Call reqMktData, get last prices for multiple assets.

2) Feed the data into my prediction engine, and do something

3) Go to step 1.

When I contacted Interactive Brokers, they said: "Only one contract can be passed to reqMktData() at one time, so there is no bulk request feature in requesting real time data."

Obviously one way to get around this is to do a loop but this is too slow. Another way to do this is through multithreading but this is a lot of work plus I can't afford the extra expense of a new computer. I am not interested in either one.

Any suggestions?

Rimmer answered 16/5, 2018 at 15:13 Comment(0)
F
1

You can only specify 1 contract in each reqMktData call. There is no choice but to use a loop of some type. The speed shouldn't be an issue as you can make up to 50 requests per second, maybe even more for snapshots.

The speed issue could be that you want too much data (> 50/s) or you're using an old version of the IB python api, check in connection.py for lock.acquire, I've deleted all of them. Also, if there has been no trade for >10 seconds, IB will wait for a trade before sending a snapshot. Test with active symbols.

However, what you should do is request live streaming data by setting snapshot to false and just keep track of the last price in the stream. You can stream up to 100 tickers with the default minimums. You keep them separate by using unique ticker ids.

Foreigner answered 18/5, 2018 at 14:15 Comment(1)
Actually the speed is an issue for the loop; I know this since I have tried this. (I mentioned it in my problem statement.) The stream suggestion may work. I have not tried this yet but I have a strong hunch that this is much easier said than done.Rimmer

© 2022 - 2024 — McMap. All rights reserved.