Interactive Brokers (IB) allows to connect with their trading software Trader Workstation (TWS) through their TWS API.
You first need to start TWS on your computer and within the settings menue you have to enable TWS API access for your "localhost" network interface (127.0.0.1) on port 7496. For paper trading this is port 7497 per default. This allows to run scripts on the same machine you run TWS on.
Check this: https://interactivebrokers.github.io/tws-api/initial_setup.html.
Official TWS API software from Interactive Brokers can be found on https://www.interactivebrokers.com/en/trading/ib-api.php.
Discussions around the TWS API are best on https://groups.io/g/twsapi.
Please also check the FAQ at: https://dimon.ca/dmitrys-tws-api-faq/.
ib_insync ist another python API to connect to your TWS with discussions at https://groups.io/g/insync.
To install ib_insync, first install python3 and then run:
pip3 install ib_insync
To update ib_insync later on, run:
pip3 install --upgrade ib_insync
pandas is a useful additional python library for data analysis and manipulation.
Install on Debian or Ubuntu Linux with:
sudo apt-get install python3-pandas
Or you can install via pip3:
pip3 install pandas
For updates run:
pip3 install --upgrade pandas
Example script which downloads historic stock data for all companies of the DOW, SP500 and Nasdaq100 indices.
See stock-hist-data-download.py.
- automate running IB TWS: https://github.com/IbcAlpha/IBC
- Github topics to look at:
- IB ruby: https://github.com/ib-ruby
- https://github.com/andrey-zotov/ib_console
- https://github.com/pavanmullapudy/InteractiveBrokers_TWS_API
A bit different to the TWS API are flex queries and downloading/parsing of them.
Here some projects around this: