erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.81k stars 753 forks source link

Timeouts on historical contract data #687

Open 8W9aG opened 8 months ago

8W9aG commented 8 months ago

I have a script that attempts to find the historical data for futures (lets say ZF), and in doing so loops through the contract months from 3 years ago to 3 years in the future, for example 202103, 202106, 202109.

An example of this call is like so:

bars = self._ibtw.reqHistoricalData(
    contract,
    endDateTime=dt,
    durationStr="10 D",
    barSizeSetting="1 min",
    whatToShow="TRADES",
    useRTH=True,
    formatDate=1,
    timeout=30.0,
)

Some of these result in a timeout (no matter what the value of the timeout is). Its reasonable that I receive no bars for my request having said that I suspect that if the contract month is not valid or too far in the past something gets lost and it just times out instead of giving me an empty bars result. Given I make a lot of these requests I would much prefer empty results rather than waiting for a timeout, its also hard for me to determine whether the timeout is valid in this case or whether the API doesn't want to give me the data.

mattsta commented 7 months ago

I think this falls back on the regular disclaimer IBKR is not a reliable data provider.

For bulk data you'll want something more data oriented like polygon.io.

You are likely being cut off by IBKR's "pacing violations" logic: https://interactivebrokers.github.io/tws-api/historical_limitations.html