Interactive Brokers — API Setup

Fotios
2 min readApr 11, 2020

--

We set up our Interactive Brokers API using the following steps.

Visit the Interactive Brokers GitHub page interactivebrokers.github.io

Agree to the terms, download TWS API Stable for Mac/Unix or Windows and unzip the downloaded file. Follow the unzip instructions at https://ibkb.interactivebrokers.com/article/2484 if you are not sure how to do that.

Go to the folder IBJts/source/pythonclient and run python setup.py install to install the IB Python library. Also install colorama for color output support. pip install colorama

The IBJts folder is no longer needed but it contains some sample code files in case you want them.

Create a script named ib_test.py and use the following code:

When you run python ib_test.py it will fail because it needs to connect to a running instance of the Trader Workstation (TWS)or IB Gateway. You will also have to allow incoming socket connections in the configuration settings of TWS.

No EClient Found
Simulated Trading Login
Allow Socket Client Connections

You can now run the script again and it should connect without any errors.

You can find the official documentation of the API here https://interactivebrokers.github.io/tws-api/index.html

Happy coding!

--

--

Fotios

Chaotic Good 💘 Computer Science 🎓 Coder 👨‍💻 Founder 🧱 2 Startup Exits 🎯 Capital Allocator 📈 G•R•A•T•I•T•U•D•E ✨✨✨ sonotap.com & fundalytica.com