Git Product home page Git Product logo

easyib's Introduction

EasyIB: Python 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. Motivation to the project was to build a Python wrapper that can run on linux/cloud environments. Thus, Client Portal API was preferred over Trader Workstation (TWS) API.

Please see https://easyib.readthedocs.io for the full documentation.

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

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. Part Time Larry has an excellent youtube tutorial on this topic: https://www.youtube.com/watch?v=O1OhiiCx6Ho.

EasyIB was developed under the Voyz/Ibeam docker image environment.

Once a gateway session is running, pip command can be used to install EasyIB:

pip install easyib

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",
    }
]

order = api.submit_orders(list_of_orders)
print(order)

Reference

For the full reference, please visit https://easyib.readthedocs.io/en/latest/reference.html.

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

Documentation of available functions are at https://easyib.readthedocs.io/en/latest/reference.html.

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_fut_conids(symbol: str) Get trsv/futures list
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, conid="default") 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

easyib's People

Contributors

jb2483 avatar utilmon avatar

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.