Bomper / ibkr_web_client

This is just another Python client for the Interactive Brokers API, which is using the OAuth1.0a protocol for authentication.

Repository from Github https://github.comBomper/ibkr_web_clientRepository from Github https://github.comBomper/ibkr_web_client

IBKR API Client

This is just another Python client for the Interactive Brokers API, which is using the OAuth1.0a protocol for authentication. Main benefits of this client are:

  • You don't need to install Client Portal Gateway
  • Automatic authentication with live session token renewal

Setup

  1. You must have an account on Interactive Brokers.
  2. Login to IBKR for Paper or Live trading account.
  3. Go to page, follow instructions to generate Consumer Key and Tokens.
  4. Install package locally for your python environment using python -m pip install .
  5. Set environment variables (or just hardcode values for config)
    • API_IBKR_CONSUMER_KEY - Consumer Key
    • API_IBKR_TOKEN - Access Token
    • API_IBKR_SECRET - Access Secret Token
    • API_IBKR_DH_PARAM - path to dhparam.pem file
    • API_IBKR_DH_PRIVATE_ENCRYPTION - path to private_encryption.pem file
    • API_IBKR_DH_PRIVATE_SIGNATURE - path to private_signature.pem file
  6. Use the client
import os
from pathlib import Path
from ibkr_web_client import IBKRConfig, IBKRHttpClient

config = IBKRConfig(
    token_access=os.getenv("API_IBKR_TOKEN"),     
    token_secret=os.getenv("API_IBKR_SECRET"),
    consumer_key=os.getenv("API_IBKR_CONSUMER_KEY"),
    dh_param_path=Path(os.getenv("API_IBKR_DH_PARAM")),
    dh_private_encryption_path=Path(os.getenv("API_IBKR_DH_PRIVATE_ENCRYPTION")),
    dh_private_signature_path=Path(os.getenv("API_IBKR_DH_PRIVATE_SIGNATURE")),
)

client = IBKRHttpClient(config)
client.portfolio_accounts()

Documentation

TODO notes

  • Authentication
  • Alerts
    • Create or Modify Alert
    • For now only Price, Margin and Trade conditions are added
    • Get a list of available alerts
    • Get details of a specific alert
    • Get MTA Alert
    • Activate or deactivate an alert
    • Delete an alert
  • Accounts
  • Contract
    • Search the security definition by Contract ID
    • All Conids by Exchange
    • Contract information by Contract ID
    • Currency pairs
    • Currency Exchange Rate
    • Find all Info and rules for a given contract
    • Search Algo Params by Contract ID
    • Search Bond Filter Information
    • Search Contract by Symbol
    • Search Contract Rules
    • Search SecDef information by conid
    • Search Strikes by Underlying Contract ID
    • Search Future by Symbol
    • Search Stocks by Symbol
    • Trading Schedule by Symbol
  • FA Allocation Management
  • FYIs and Notifications
  • Market Data
    • Live Market Data Snapshot
    • Regulatory Snapshot
    • Historical Market Data
    • Unsubscribe (Single)
    • Unsubscribe (All)
  • Option Chains
  • Order Monitoring
  • Orders
  • Portfolio
    • Portfolio Accounts
    • Portfolio Subaccounts
    • Portfolio Subaccounts (Large Account Structures)
    • Specific Account's Portfolio Information
    • Portfolio Allocation (Single)
    • Combination Positions
    • Portfolio Allocation (All)
    • Positions
    • Positions by Conid
    • Invalidate Backend Portfolio Cache
    • Portfolio Summary
    • Portfolio Ledger
    • Position & Contract Info
  • Portfolio Analyst
    • Account Performance
    • Transaction History
  • Scanner
    • Iserver Scanner Parameters
    • Iserver Market Scanner
    • HMDS Scanner Parameters (Not working)
    • HMDS Market Scanner (Not working)
  • Session
  • Watchlists
    • Create a Watchlist
    • Get All Watchlists
    • Get Watchlist Information
    • Delete a Watchlist

Tests

To run tests you need to have your own Paper Trading account. Run tests with pytest:

pytest

Disclaimer

  • Use at your own risk

About

This is just another Python client for the Interactive Brokers API, which is using the OAuth1.0a protocol for authentication.

License:MIT License


Languages

Language:Python 100.0%