All Projects → areed1192 → Interactive Broker Python Api

areed1192 / Interactive Broker Python Api

Licence: mit
A python client library for the different APIs offered by Interactive Broker including the Trader Workstation API, Client Portal Web API, and Client Portal Streaming Web API.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Interactive Broker Python Api

Ccxt Rest
Open Source Unified REST API of 100+ Crypto Exchange Sites (18k+ docker pulls) - https://ccxt-rest.io/
Stars: ✭ 210 (+27.27%)
Mutual labels:  api, trading
Crypto Exchanges Gateway
Your gateway to the world of crypto !
Stars: ✭ 343 (+107.88%)
Mutual labels:  api, trading
Uniswap Python
🦄 The unofficial Python client for the Uniswap exchange.
Stars: ✭ 191 (+15.76%)
Mutual labels:  api, trading
Python Poloniex
Poloniex API wrapper for Python 2.7 & 3
Stars: ✭ 557 (+237.58%)
Mutual labels:  api, trading
Coinbase Pro Node
Coinbase Pro API written in TypeScript and covered by tests.
Stars: ✭ 116 (-29.7%)
Mutual labels:  api, trading
Zerodha live automate trading using ai ml on indian stock market Using Basic Python
Online trading using Artificial Intelligence Machine leaning with basic python on Indian Stock Market, trading using live bots indicator screener and back tester using rest API and websocket 😊
Stars: ✭ 131 (-20.61%)
Mutual labels:  api, trading
Ccxt
A JavaScript / Python / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
Stars: ✭ 22,501 (+13536.97%)
Mutual labels:  api, trading
Pymarketcap
Python3 API wrapper and web scraper for https://coinmarketcap.com
Stars: ✭ 73 (-55.76%)
Mutual labels:  api, trading
Ccxt.net
CCXT.NET – CryptoCurrency eXchange Trading Library for .NET
Stars: ✭ 89 (-46.06%)
Mutual labels:  api, trading
Cryptotrader
A responsive dynamic webapp to trade cryptopairs on the most prominent exchanges
Stars: ✭ 118 (-28.48%)
Mutual labels:  api, trading
Tastyworks api
An unofficial, reverse-engineered Python API for tastyworks.
Stars: ✭ 138 (-16.36%)
Mutual labels:  api, trading
Netcore Boilerplate
Boilerplate of API in .NET Core 3.1
Stars: ✭ 166 (+0.61%)
Mutual labels:  api
Sherpa
Sherpa is a highly available, fast, and flexible horizontal job scaling for HashiCorp Nomad. It is capable of running in a number of different modes to suit different requirements, and can scale based on Nomad resource metrics or external sources.
Stars: ✭ 165 (+0%)
Mutual labels:  api
Item Nbt Api
Add custom NBT tags to Items/Tiles/Entities without NMS!
Stars: ✭ 163 (-1.21%)
Mutual labels:  api
Mobx Rest
REST conventions for Mobx
Stars: ✭ 164 (-0.61%)
Mutual labels:  api
Spaces Api
An API wrapper for DigitalOcean's Spaces object storage designed for easy use.
Stars: ✭ 166 (+0.61%)
Mutual labels:  api
Crex
A Golang cryptocurrency trading API & Library. Support Binance, BitMEX, Deribit, Bybit, Huobi DM, OKEX Futures and more.
Stars: ✭ 166 (+0.61%)
Mutual labels:  trading
Roastapp
Laravel学院 Roast 应用源码
Stars: ✭ 164 (-0.61%)
Mutual labels:  api
Ta
Technical Analysis Library using Pandas and Numpy
Stars: ✭ 2,649 (+1505.45%)
Mutual labels:  trading
Nelmioapidocbundle
Generates documentation for your REST API from annotations
Stars: ✭ 2,009 (+1117.58%)
Mutual labels:  api

Unofficial Interactive Brokers API

Table of Contents

Overview

The unofficial Python API client library for Interactive Broker Client Portal Web API allows individuals with Interactive Broker accounts to manage trades, pull historical and real-time data, manage their accounts, create and modify orders all using the Python programming language.

Interactive Broker offers multiple APIs for their clients. If you would like to learn more about their API offerings click on the links below:

What's in the API

  • Authentication
  • Account Endpoints
  • Market Data Endpoints
  • Trade Endpoints
  • Portfolio Endpoints
  • Scanner Endpoints
  • Portfolio Analysis Endpoints
  • Web Streaming

Setup Requirements

The following requirements must be met to use this API:

  • A Interactive Broker account, you'll need your account password and account number to use the API.
  • Java 8 update 192 or higher installed (gateway is compatible with higher Java versions including OpenJDK 11).
  • Download the Beta Client Portal Gateway

Setup Client Portal

Once you've downloaded the latest client portal or if you chose to use the one provided by the repo. You need to unzip the folder and place it in the repo where this code is stored.

Setup API Key and Credentials

The API does not require any API keys to use it, all of the authentication is handled by the Client Portal Gateway. Everytime a user starts a new session with the API they will need to proivde their login credentials for the account they wish to use. The Interactive Broker Web API does offer the ability to use the API using a paper account.

Important: Your account number and account password should be kept secret.

Setup Installation

pip install interactive-broker-python-web-api

Setup Writing Account Information

The Client needs specific account information to create a and validate a new session. Where you choose to store this information is up to you, but I'll layout some options here.

Write a Config File:

It's common in Python to have a config file that contains information you need to use during the setup of a script. Additionally, you can make this file in a standard way so that way it's easy to read everytime. In Python, there is a module called configparser which can be used to create config files that mimic that of Windows INI files.

To create a config file using hte configparser module, run the script below in a separate file or go to the Resources Folder and run the write_config.py file.

import pathlib
from configparser import ConfigParser

# Initialize a new instance of the `ConfigParser` object.
config = ConfigParser()

# Define a new section called `main`.
config.add_section('main')

# Set the values for the `main` section.
config.set('main', 'REGULAR_ACCOUNT', 'YOUR_ACCOUNT_NUMBER')
config.set('main', 'REGULAR_USERNAME', 'YOUR_ACCOUNT_USERNAME')

config.set('main', 'PAPER_ACCOUNT', 'YOUR_ACCOUNT_NUMBER')
config.set('main', 'PAPER_USERNAME', 'YOUR_ACCOUNT_USERNAME')

# Make the `config` folder for the user.
new_directory = pathlib.Path("config/").mkdir(parents=True, exist_ok=True)

# Write the contents of the `ConfigParser` object to the `config.ini` file.
with open('config/config.ini', 'w+') as f:
    config.write(f)

Store the Variables in the Script:

If you plan to not share the script with anyone else, then you can store the account info inside the script itself. However, please make sure that you do not make the file public to individuals you don't know.

Usage

This example demonstrates how to login to the API and demonstrates sending a request using the market_data_history endpoint, using your API key.

from ibw.client import IBClient

REGULAR_ACCOUNT = 'MY_ACCOUNT_NUMBER'
REGULAR_USERNAME = 'MY_ACCOUNT_USERNAME'

# Create a new session of the IB Web API.
ib_client = IBClient(
    username=REGULAR_USERNAME,
    account=REGULAR_ACCOUNT,
    is_server_running=True
)

# create a new session.
ib_client.create_session()

# grab the account data.
account_data = ib_client.portfolio_accounts()

# print the data.
print(account_data)

# Grab historical prices.
aapl_prices = ib_client.market_data_history(conid=['265598'], period='1d', bar='5min')

# print the prices.
print(aapl_prices)

# close the current session.
ib_client.close_session()

Features

Request Validation

For certain requests, in a limited fashion, it will help validate your request when possible. For example, when grabbing real-time quotes using the market_data endpoint, it will validate the fields you request to ensure they're valid fields for that endpoint.

Endpoint Verification

To use certain endpoints, you must call other endpoints before you use it. To help limit the amount of confusion for users, the library will call those endpoints for you behind the scenes so that way you don't need to worry about it.

Client Portal Download

If the user doesn't have the clientportal gateway downloaded, then the library will download a copy it, unzip it for you, and quickly allow you to get up and running with your scripts.

Documentation and Resources

Support these Projects

Patreon: Help support this project and future projects by donating to my Patreon Page. I'm always looking to add more content for individuals like yourself, unfortuantely some of the APIs I would require me to pay monthly fees.

YouTube: If you'd like to watch more of my content, feel free to visit my YouTube channel Sigma Coding.

Hire Me: If you have a project, you think I can help you with feel free to reach out at [email protected] or fill out the contract request form

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].