Code Example: 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, but starting with Interactive Brokers’ data feed 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 exceptions to indicate that there was a problem.

There are also known, official limitations to using their 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.

All that said, you can certainly get some data out of it, and if you’re already an Interactive Brokers customer you may as well start there. You can find my code on GitHub, here.

Leave a Reply

Your email address will not be published. Required fields are marked *