Coder Social home page Coder Social logo

tws-api-examples's Introduction

TWS API examples for Interactive Brokers (IB)

Interactive Brokers (IB) allows to connect with their trading software Trader Workstation (TWS) through their TWS API.

Enable TWS API access for your local computer

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 (demo/test account) this is port 7497 per default. This allows to run scripts on the same machine you run TWS on.

Instead of IB TWS, you can also use IB Gateway. This uses port 4002 per default for paper trading (demo/test account) and 4001 for an active/real/live account.

Check this: https://interactivebrokers.github.io/tws-api/initial_setup.html.

Once you start scripts connecting to your TWS, you can see also a new tab "API" on your TWS.

Official TWS API software from IB

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/.

Install ib_async for python

ib_async is another python API to connect to your TWS with docu at https://ib-api-reloaded.github.io/ib_async/api.html and discussions at https://groups.io/g/insync. (Original project at https://github.com/erdewit/ib_insync.)

To install ib_async, first install python3 and then run:

pip3 install ib_async

To update ib_async later on, run:

pip3 install --upgrade ib_async

python library pandas

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

historic stock data download

Example script which downloads historic stock data for all companies of the DOW, SP500 and Nasdaq100 indices.

The data is stored into the subdirectory "data" per default, so please create this directory before calling this script.

See stock-hist-data-download.py.

How to update the index list of the SP500 and Nasdaq100:

python3 stock-hist-data-download.py --list-index > TMPFILE
diff -u stock-hist-data-download.py TMPFILE

Also check out https://github.com/deltaray-io/ib_dl.

links to similar / further projects

IB flex queries

A bit different to the TWS API are flex queries and downloading/parsing of them.

Here some projects around this:

tws-api-examples's People

Contributors

laroche avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tws-api-examples's Issues

Enabling the Script on Windows

I played around and it seems to me that Windows can cause some pain in the ass here. I tried to adjust the file names myself but I had no success, yet. Anyway, I guess 95 % of the users are running their TWS in a Windows Desktop environment, so maybe we should spend the effort to make this tool available on linux and windows.

Extract configuration to conf file

Configuration files are in the main script, here stock-hist-data-download.py. Maybe it is better to store all config information in one file, i.e. config.py

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.