Connecting to Interactive Brokers API via Python
Interactive Brokers now has an official Python API (beta 9.73) download. It requires Python 3.1+.
See the docs.
Update
IB has now (Feb 2017) an official Python SDK (aka API). It supports Python 3 only (use IbPy if Python 2 is a must)
- Link to the docs: http://interactivebrokers.github.io/tws-api/
Supports API versions 9.72 and later.
The ibpy
project found a new home under https://github.com/blampe/IbPy (and apparently a new owner with it)
As you may see in the README the API version supported is 9.70. Current IB API version is 9.72, but the existing ibpy
works like a charm with the current versions of TWS (952 stable, 954 latest as of Jan-2015) and the corresponding 9.72 API.
If using Python 3 I would put most of the emphasis in the bytes vs unicode topic because the strings passed into the API (according to my experience) must be bytes (I usually do Python 2 with from future ... unicode_literals)
The examples provided with the ibpy
distribution work out of the box.
Edit:
I have added a couple of working samples in other answers:
ibpy Getting portfolio information: Interactive Broker, Python
Getting parameters of listed options & futures in Interactive Brokers API
They use Queue
to make it a complete working example (the same concept can be applied to deliver historic or real-time data) which deliver what's requested (or the corresponding error)