¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

How can I speed up getting data for all SP500 stocks


 

Hi,?

Please help to advise on this.

Since getting ticker for each stock just taking too much time. Calling?reqTickers() for 500 stocks took 1 hour.

So I am trying to write a func to get the current price for all SP500 stocks in parallel for my ML model. The code as below:

def get_all_pre_closed_and_current_price_from_ib_concurrently(self, stock_names):
self.open_prices = {}
self.close_prices = {}
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
futures = [executor.submit(self.get_pre_closed_and_current_price_from_ib_for_one_stock_concurrently, stock_name) for
stock_name in stock_names]
wait(futures, timeout=5, return_when=ALL_COMPLETED) # ALL_COMPLETED is actually the default
loop.close()
return self.open_prices, self.close_prices
def get_pre_closed_and_current_price_from_ib_for_one_stock_concurrently(self, stock_name):
contract = Stock(stock_name, 'SMART', 'USD')
s_ticker_snap = self.ib.reqTickers(contract, regulatorySnapshot=False)
s_last = s_ticker_snap[0].last
s_bid = s_ticker_snap[0].bid
s_ask = s_ticker_snap[0].ask
s_peg = (s_bid + s_ask) / 2
s_peg = round(s_peg, 2)
print("{} stock price: {}, ".format(contract.symbol, s_peg))
self.close_prices[stock_name], self.open_prices[stock_name] = s_peg, s_ticker_snap[0].close
However, it doesn't work as it fails to download any ticker at all.

Much appreciated.


 

On Thu, Dec 17, 2020 at 07:26 AM, TodyD wrote:
reqTickers

Maybe clearer for other members, but I never saw a function called reqTickers in IB API.

What are you refering to ? reqMktData? in tick mode ?

?

Incidentally if I understand what you want to do I suspect you can't or it is inefficient with IB.

They safely and promptly deliver a dozen ticks in //

but 500 is beyond standard subscription limitations (100 aggregated), and BTW if you pay for "boost" you may anyway hit their "hard stop" at 1000 max.

?

IB is in essence a Brooker with low commission and SMART routing, not a Feeder.

1- Consider getting your data from polygon.io. iqfeed, or even IEX (FireHose mode), etc ...

2- Then when building your order call specifically IB on the related instrument to get latest info from their opinion.

?


 

Did a few exercises on that matter.
Came to a rather simple solution. However, language is Ruby.
Perhaps you give it a try:

? and an example to start with:
https://github.com/ib-ruby/ib-extensions/blob/master/examples/market_price

hartmut


 

I agree with you @hymagik I think there a limitation on downloading data from 500 stocks.
But it should be feasible et stream data from 100 stocks as it is done in TWS.

I am still looking for the same solution and I was disappointed that IBKR that you have to implement a for loop to download data for each ticker, it takes so much time!