Python wrapper for Interactive Brokers Client Portal Web API

Overview

EasyIB: Unofficial Wrapper for Interactive Brokers API

https://img.shields.io/pypi/v/easyib https://img.shields.io/pypi/pyversions/easyib https://img.shields.io/pypi/l/easyib Documentation Status

EasyIB is an unofficial python wrapper for Interactive Brokers Client Portal Web API.

Features

Notable functionality includes:

  • Pull account info, portfolio, cash balance, net value
  • Pull market historical data
  • Submit, modify, cancel orders
  • Get order status, list of live orders
  • Ping (tickle) server, get authentication status, re-authenticate

How to install

pip install easyib

EasyIB assumes a gateway session is active and authenticated. Follow instructions at https://interactivebrokers.github.io/cpwebapi/ for authentication. A custom package such as Voyz/IBeam can be also used for setting up an active session.

Quick start

Historical data

import easyib

api = easyib.REST()

bars = api.get_bars("AAPL", period="1w", bar="1d")
print(bars)

Submitting an order

list_of_orders = [
    {
        "conid": api.get_conid("AAPL"),
        "orderType": "MKT",
        "side": "BUY",
        "quantity": 7,
        "tif": "GTC",
    }
]

api.submit_orders(list_of_orders)

Reference

REST

By default, EasyIB assumes the gateway session is open at https://localhost:5000 withtout a SSL certificate. A custom url and SSL certificate can be set by:

api = easyib.REST(url="https://localhost:5000", ssl=False)

API REST Methods

See the official documentation of the End Point at https://www.interactivebrokers.com/api/doc.html

REST Method End Point Result
get_accounts() Get portfolio/accounts list
switch_account(accountId: str) Post iserver/account/{accoutId} dict
get_cash() Get portfolio/{accountId}/ledger float
get_netvalue() Get portfolio/{accountId}/ledger float
get_conid(symbol: str) Get trsv/stocks int
get_portfolio() Get portfolio/{accountId}/positions/0 dict
reply_yes(id: str) Post iserver/reply/{id} dict
submit_orders(list_of_orders: list, reply_yes=True) Post iserver/account/{acountId}/orders dict
get_order(orderId: str) Get iserver/account/order/satus/ dict
get_live_orders(filters=[]) Get iserver/account/orders dict
cancel_order(orderId: str) Delete iserver/account/{accountId}/order/{orderId} dict
modify_order(orderId=None, order=None, reply_yes=True) Post iserver/account/{accountId}/order/{orderId} dict
get_bars(symbol: str, period="1w", bar="1d", outsideRth=False) Get iserver/marketdata/history dict
ping_server() Post tickle dict
get_auth_status() Post iserver/auth/status dict
re_authenticate() Post iserver/reauthenticate None
log_out() Post logout None
Comments
  • Trading TWS session is connected from a different IP address

    Trading TWS session is connected from a different IP address

    Hi!

    I wanted to try this library but when I try the sample code I just receive this error:

    {'error': 'Trading TWS session is connected from a different IP address'}

    Any idea about if this is a bug or theres something wrong?

    opened by jordics 6
  • how to get futures data and place orders

    how to get futures data and place orders

    As I mainly trade futures I am wondering how to get futures data and place orders? Doing the following:

    bars = ib.get_bars("NG", period="1w", bar="1d")
    print(bars)
    

    Results in the following error:

    {'error': "No data of type EODChart is available for the exchange 'VALUE' and the security type 'Stock' and '1 W' and '1 day'"}

    Using ibapi the sequence would go something like this:

    contract = Contract()
    contract.symbol = 'NG'
    contract.exchange = 'NYMEX'
    # contract.secType = 'CONTFUT'
    contract.secType = 'FUT'
    contract.lastTradeDateOrContractMonth  = '202109'
    
    app.reqHistoricalData(1, contract, '20210815 17:59:00', '10 D', '15 mins', 'BID', 0, 2, False, [])
    

    How would this be done using EasyIB?

    opened by spitzbubchen 3
  • Feature: add ability to filter instruments and contracts

    Feature: add ability to filter instruments and contracts

    get_conid by default returns the first contract of the first instrument it finds. This causes problems if multiple markets have instruments using this symbol, as a contract different from what was expected might be returned. I found this when looking up the $MUB US equity, which is not the first $MUB instrument returned by IB, so I didn't receive the contract ID I wanted.

    Two parameters, instrument_filters and contract_filters, are added to get_conid. instrument_filters filters the instrument data, i.e. the name, chineseName, and assetClass fields. contract_filters filters the contract data, i.e the exchange and isUS fields. All filters must be fulfilled for the instrument/contract to be included. The filters can be used together.

    I've added some samples of searching for US $MUB using the filters.

    opened by GoldenChrysus 2
  • get_bars() not working

    get_bars() not working

    This is very nice work! I tried most of the functions and they work well, however, when I run the get_bars() example I get the following error:

    Traceback (most recent call last):
      File "test.py", line 30, in <module>
        bars = ib.get_bars("AAPL", period="1w", bar="1d")
      File "/home/rod/Projects/tradingview/ibapi.py", line 252, in get_bars
        return response.json()
      File "/home/rod/Projects/tradingview/venv/lib/python3.8/site-packages/requests/models.py", line 910, in json
        return complexjson.loads(self.text, **kwargs)
      File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
        return _default_decoder.decode(s)
      File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
        raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    
    opened by spitzbubchen 2
  • Can't get portfolio

    Can't get portfolio

    Hi, I keep getting the error below when I try to get my portfolio. This is a new paper account with no portfolio in place yet, so I'd expect it to return an empty portfolio instead of an error? I've tried restarting ibeam and my server but the error persists. Other service calls work. Any ideas much appreciated! Thanks

    Traceback (most recent call last):
      File "/home/xxx/test.py", line 72, in <module>
        print(api.get_portfolio())
      File "/home/xxx/.local/lib/python3.9/site-packages/easyib/easyib.py", line 98, in get_portfolio
        for item in response.json():
      File "/usr/lib/python3/dist-packages/requests/models.py", line 900, in json
        return complexjson.loads(self.text, **kwargs)
      File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
        return _default_decoder.decode(s)
      File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
        raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    
    
    opened by freekeys 1
  • Feature: add ability to filter instruments and contracts (Sourcery refactored)

    Feature: add ability to filter instruments and contracts (Sourcery refactored)

    Pull Request #7 refactored by Sourcery.

    Since the original Pull Request was opened as a fork in a contributor's repository, we are unable to create a Pull Request branching from it.

    To incorporate these changes, you can either:

    1. Merge this Pull Request instead of the original, or

    2. Ask your contributor to locally incorporate these commits and push them to the original Pull Request

      Incorporate changes via command line
      git fetch https://github.com/ashpipe/EasyIB pull/7/head
      git merge --ff-only FETCH_HEAD
      git push

    NOTE: As code is pushed to the original Pull Request, Sourcery will re-run and update (force-push) this Pull Request with new refactorings as necessary. If Sourcery finds no refactorings at any point, this Pull Request will be closed automatically.

    See our documentation here.

    Run Sourcery locally

    Reduce the feedback loop during development by using the Sourcery editor plugin:

    Help us improve this pull request!

    opened by sourcery-ai[bot] 1
  • Is it possible to get streaming market data with ibeam?

    Is it possible to get streaming market data with ibeam?

    how would one use ibeam to get a continuous stream of market data (or is it not currently possible)? It is easy to do with the native api but it requires the gateway UI to be open, which is quite inconvenient.

    opened by desmondsy 1
Owner
null
Generate direct m3u playlist for all the channels subscribed in the Tata Sky portal

Tata Sky IPTV Script generator A script to generate the m3u playlist containing direct streamable file (.mpd or MPEG-DASH or DASH) based on the channe

Gaurav Thakkar 250 Jan 1, 2023
Benachrichtigungs-Bot für das niedersächische Impfportal / Notification bot for the lower saxony vaccination portal

Ein kleines Wochenend-Projekt von mir. Der Bot überwacht die REST-API des niedersächsischen Impfportals auf freie Impfslots und sendet eine Benachrichtigung mit deinem bevorzugtem Service. Ab da gilt leider: der Schnellste gewinnt. Bitte missbraucht den Bot nicht und verwendet moderate Intervalle.

sibalzer 37 May 11, 2022
Techie Sneh 19 Dec 3, 2021
Portal Backend for Yuta management

Portal Backend for Yuta management Prerequisites Python 3.10 or above. pip, pdm installed. Quickstart Install the required packages: pdm install Runn

Loc Mai 1 Dec 20, 2021
An interactive App to play with Spotify data, both from the Spotify Web API and from CSV datasets.

An interactive App to play with Spotify data, both from the Spotify Web API and from CSV datasets.

Caio Lang 3 Jan 24, 2022
Aws-lambda-requests-wrapper - Request/Response wrapper for AWS Lambda with API Gateway

AWS Lambda Requests Wrapper Request/Response wrapper for AWS Lambda with API Gat

null 1 May 20, 2022
Python client library for Google Maps API Web Services

Python Client for Google Maps Services Description Use Python? Want to geocode something? Looking for directions? Maybe matrices of directions? This l

Google Maps 3.8k Jan 1, 2023
Spotify Web API client for Python 3

Welcome to the GitHub repository of Tekore! We provide a client for the Spotify Web API for Python, complete with all available endpoints and authenti

Felix Hildén 186 Dec 22, 2022
A Python wrapper around the OpenWeatherMap web API

PyOWM A Python wrapper around OpenWeatherMap web APIs What is it? PyOWM is a client Python wrapper library for OpenWeatherMap (OWM) web APIs. It allow

Claudio Sparpaglione 740 Dec 18, 2022
WhatsApp Web API client with multi-device support

Tauros WhatsApp Web client for multi-device in python Free software: MIT Documentation: https://tauros.readthedocs.io Features TODO Credits This packa

Manjit Pardeshi 0 Jan 20, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
An API wrapper for the file.io web service.

??️ File.io An API wrapper for the file.io web service. Install $ pip3 install fileio or

nkot56297 1 Dec 18, 2021
wyscoutapi is an extremely basic API client for the Wyscout API (v2 & v3) for Python

wyscoutapi wyscoutapi is an extremely basic API client for the Wyscout API (v2 & v3). Usage Install with pip install wyscoutapi. To connect to the Wys

Ben Torvaney 11 Nov 22, 2022
Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Harun Mbaabu Mwenda 46 Sep 1, 2022
Python API Client for Twitter API v2

?? Python Client For Twitter API v2 ?? Why Twitter Stream ? Twitter-Stream.py a python API client for Twitter API v2 now supports FilteredStream, Samp

Twitivity 31 Nov 19, 2022
Dns-Client-Server - Dns Client Server For Python

Dns-client-server DNS Server: supporting all types of queries and replies. Shoul

Nishant Badgujar 1 Feb 15, 2022
Raphtory-client - The python client for the Raphtory project

Raphtory Client This is the python client for the Raphtory project Install via p

Raphtory 5 Apr 28, 2022
Python API wrapper around Trello's API

A wrapper around the Trello API written in Python. Each Trello object is represented by a corresponding Python object. The attributes of these objects

Richard Kolkovich 904 Jan 2, 2023