https://github.com/toptalent-23/ibkr_trading_api
Python sync/async framework for Interactive Brokers Trading API and Utility tools for IBKR TWS API
https://github.com/toptalent-23/ibkr_trading_api
asyncio ibapi interactive-brokers python trading twsapi
Last synced: 9 months ago
JSON representation
Python sync/async framework for Interactive Brokers Trading API and Utility tools for IBKR TWS API
- Host: GitHub
- URL: https://github.com/toptalent-23/ibkr_trading_api
- Owner: TopTalent-23
- License: bsd-2-clause
- Created: 2025-04-22T19:40:10.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-22T20:19:24.000Z (about 1 year ago)
- Last Synced: 2025-08-01T16:42:25.534Z (10 months ago)
- Topics: asyncio, ibapi, interactive-brokers, python, trading, twsapi
- Language: Python
- Homepage:
- Size: 16 MB
- Stars: 0
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
IBKR_Trading_API
------------
The goal of the IB-insync library is to make working with the
`Trader Workstation API `_
from Interactive Brokers as easy as possible.
The main features are:
* An easy to use linear style of programming;
* An `IB component `_
that automatically keeps in sync with the TWS or IB Gateway application;
* A fully asynchonous framework based on
`asyncio `_
and
`eventkit `_
for advanced users;
* Interactive operation with live data in Jupyter notebooks.
Be sure to take a look at the
`notebooks `_,
the `recipes `_
and the `API docs `_.
Configure IBKR Trade Workstation API
------------
.. image:: docs/IBKR-TWS-GlobalConfiguration-API-Settings.png
:alt: Screenshot of the project in action
:width: 600px
:align: center
.. image:: docs/IBKR-TWS-GlobalConfiguration-API-Settings-Demo.png
:alt: Screenshot of the project in action
:width: 600px
:align: center
Spoof detector
------------
Visualizes the bid and ask orders and sales in single window with different type of charts. Run `python spoof_detector/spoof_detector.py --help`. You will see all the options
.. image:: docs/lineplot.png
:alt: Screenshot of the project in action
:width: 600px
:align: center
.. image:: docs/heatmap.png
:alt: Screenshot of the project in action
:width: 600px
:align: center
Installation
------------
::
pip install ib_insync
Requirements:
* Python 3.6 or higher;
* A running TWS or IB Gateway application (version 1023 or higher).
Make sure the
`API port is enabled `_
and 'Download open orders on connection' is checked.
The ibapi package from IB is not needed.
Example
-------
This is a complete script to download historical data:
.. code-block:: python
from ib_insync import *
# util.startLoop() # uncomment this line when in a notebook
ib = IB()
ib.connect('127.0.0.1', 7497, clientId=1)
contract = Forex('EURUSD')
bars = ib.reqHistoricalData(
contract, endDateTime='', durationStr='30 D',
barSizeSetting='1 hour', whatToShow='MIDPOINT', useRTH=True)
# convert to pandas dataframe (pandas needs to be installed):
df = util.df(bars)
print(df)
Output::
date open high low close volume \
0 2019-11-19 23:15:00 1.107875 1.108050 1.107725 1.107825 -1
1 2019-11-20 00:00:00 1.107825 1.107925 1.107675 1.107825 -1
2 2019-11-20 01:00:00 1.107825 1.107975 1.107675 1.107875 -1
3 2019-11-20 02:00:00 1.107875 1.107975 1.107025 1.107225 -1
4 2019-11-20 03:00:00 1.107225 1.107725 1.107025 1.107525 -1
.. ... ... ... ... ... ...
705 2020-01-02 14:00:00 1.119325 1.119675 1.119075 1.119225 -1
Documentation
-------------
The complete `API documentation `_.
`Changelog `_.