Interactive Broker Python Setup
Who are Interactive Brokers?
Interactive Brokers (IB) is an American multinational brokerage firm that provides the most prominent electronic trading platform in the U.S.
Interactive Brokers provide two ways to trade:
- Using TWS Dashboard
- Interactive Brokers Gateway
What is Interactive Brokers Native Python API?
The Interactive Brokers Python native API is a set of neat methods that allow you to trade via Interactive Brokers using Python code.
The native APIs act as a bridge between your local system and the IB servers, using which you can fetch the required information to make trading calls and place orders.
Alternatives to IB Native APIs
The IB Native API is developed and maintained by IB themselves. This means that it will provide the most stable and seamless connection to the IB servers. But IB Native APIs are a tad bit difficult to wrap our heads around compared to other third-party alternatives.
These third-party alternatives include IBridgePy, IB-insync, or IbPy.
The major issue with the third-party tools is that the support for these tools can end at any point and one might need to scrape their development efforts and move to an alternative third-party solution and re-implement it.
This makes IB Native APIs, even though difficult to implement a very obvious choice to move forward with.
How to get started with IB Native API?
Open an account with IB
There are three types of accounts provided by Interactive Brokers
- Live account - This account has real money and any trades made via this account with have a monetary impact
- Paper account - This is a dummy account that comes with a Live account. It has almost all the features of a Live account and it does not use actual money. All the trades made via this account will be dummy trades and will have no impact.
- Demo account - The demo account seems like a paper account at first glance but it does not have certain purchased features. For example, if the Live Price package has been bought on the Live account the connected Paper account will also have this service. But a demo account will not have this service. So certain APIs might work differently.
You can download
Once the download is done you can signup for a demo account.
Once this is out of the way, on to the IB Native API.
Download IB Native API
IB Native APIs are a tad bit different to install. They can be installed using pip
. Instead, you need to go to their github page. You will see the following agreement.
Click on the "I Agree" button. You will be redirected to another page. Over there you will see a number of options. Based on your operating system select the stable version.
For Windows an installer package will be downloaded, as for Mac/Unix users, a compressed file will be downloaded. You can run the installer or decompress the folder and you will have a folder named TWS API. The following is the content of the folder:
Open a terminal and cd
into the folder TWS API
. Then further cd
into source
-> pythonclient
. After this, all you need to do is type in the following command
pip install --upgrade .
You have the Native APIs successfully installed on your local system. Now you can use the Native APIs for development.
The blogs on how to use Native API will be covered separately.
That's all from me today. Thank you and have a great one.
Subscribe to my newsletter
Read articles from Mihir Sampat directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by