Extracting Historical Data from Interactive Brokers API

Early in my trading adventure I had need of data, and I knew my broker would provide it. I have since moved on to IQFeed (which charges for API access), but starting with Interactive Brokers API was still a valuable first step.

I found their API clunky to use. It does not reliably respond to all requests. I’ve had to restart my data collection session several times to get it working, and there were no thrown exceptions or clear error codes to indicate that there was a problem.

There are also known, official limitations to using the Interactive Brokers API for historical data. You will not get much depth of history. They have no expired futures data older than 2 years. No expired options data. No expired spread data. Besides what they absolutely do not have, you have to throttle yourself or have your connection to the historical data server invalidated. If you request too much data it will throw a “pacing violation” and you will have to re-initiate your connection (CTRL+ALT+h in the gateway).

All that said, you can certainly get some data out of it! If you’re already an Interactive Brokers customer you may as well start there because the other options will charge you. You can find my code on GitHub, here.

As always, you get what you pay for. This free API and (somewhat) free data access comes at the cost of greatly increased labour in using it. Interactive Brokers is not exactly well known for good quality data, either. You may have seen weird bars in your trading interface before; be prepared to get them via the API, too.

If you need help interfacing with a trading API, reach out!

«
»