Skip to content

areed1192/interactive-brokers-api

Repository files navigation

Interactive Brokers Client Portal API

Python PyPI License: MIT

An unofficial Python client for the Interactive Brokers Client Portal Web API. Manage trades, pull historical and real-time data, manage accounts, create and modify orders — all from Python.

Table of Contents

Features

Service Property Description
Authentication ibc_client.authentication Login, logout, session keep-alive, SSO validation
Accounts ibc_client.accounts Account listing and server PnL
Portfolio ibc_client.portfolio_accounts Positions, ledger, allocation, sub-accounts
Orders ibc_client.orders Place, modify, cancel, bracket, and what-if orders
Trades ibc_client.trades Query executed trades
Market Data ibc_client.market_data Snapshots, historical bars, subscriptions
Contracts ibc_client.contracts Search stocks/futures/options, security definitions, trading rules
Alerts ibc_client.alerts Create, activate, delete, and query alerts
Scanners ibc_client.scanners Market scanner parameters and execution
PnL ibc_client.pnl Real-time profit and loss
FYI ibc_client.fyi Notifications, delivery options, disclaimers
Portfolio Analysis ibc_client.portfolio_analysis Performance summaries and transaction history
Customer ibc_client.customers Customer info
Data ibc_client.data_services News, calendar, and research data

Requirements

  • Python 3.10+
  • An Interactive Brokers account (paper or live)
  • Java 8 update 192 or higher (OpenJDK 11+ also works)
  • The Client Portal Gateway (downloaded automatically on first use)

Installation

Install from PyPI:

pip install ibc-api

Or install in development mode from source:

git clone https://github.com/areed1192/interactive-brokers-api.git
cd interactive-brokers-api
pip install -e ".[dev]"

Quick Start

from ibc import InteractiveBrokersClient

# Initialize the client.
ibc_client = InteractiveBrokersClient(
    account_number="U1234567",
)

# Authenticate (opens browser for gateway login).
ibc_client.authentication.wait_for_login()

# Grab a market data snapshot.
snapshot = ibc_client.market_data.snapshot(contract_ids=["265598"])
print(snapshot)

# Search for a contract.
results = ibc_client.contracts.search_symbol(symbol="AAPL")
print(results)

# Place an order.
order = {
    "conid": 265598,
    "orderType": "LMT",
    "price": 150.00,
    "side": "BUY",
    "quantity": 1,
    "tif": "DAY",
}
response = ibc_client.orders.place_order(
    account_id=ibc_client.account_number,
    order=order
)
print(response)

See the samples/ directory for more complete examples.

SSL Certificates

The Client Portal Gateway uses a self-signed SSL certificate on localhost:5000. Your browser will warn about an insecure connection when you open the login page — this is expected. The connection is only "insecure" between your code and your own machine; requests from the gateway to Interactive Brokers are fully encrypted.

This library defaults to verify_ssl=False and suppresses the corresponding urllib3 warnings, which is the standard approach for localhost gateway usage.

The verify_ssl parameter accepts three kinds of values:

Value Meaning
False (default) Skip SSL verification entirely — standard for the self-signed localhost gateway.
True Verify using the default CA bundle (Python's certifi).
"/path/to/ca-bundle.crt" Verify using a custom CA certificate file or directory.
# Default — skip verification (localhost self-signed cert)
ibc_client = InteractiveBrokersClient(account_number="U1234567")

# Verify with a custom CA cert
ibc_client = InteractiveBrokersClient(
    account_number="U1234567",
    verify_ssl="/etc/ssl/certs/my-ib-gateway-ca.crt",
)

If you want stricter local SSL verification, you can replace the gateway's keystore and pass verify_ssl=True or a path to your custom CA cert:

  1. Generate a self-signed certificate and import it into a Java KeyStore (requires keytool from your Java installation):

    keytool -genkey -keyalg RSA -alias selfsigned -keystore my.jks -storepass mypassword -validity 730 -keysize 2048
  2. Replace ibc/resources/clientportal.beta.gw/root/vertx.jks with your new my.jks file and update sslPwd in root/conf.yaml to match your store password.

  3. Export the certificate to PEM format and pass the path as verify_ssl:

    ibc_client = InteractiveBrokersClient(
        account_number="U1234567",
        verify_ssl="/path/to/my-gateway-ca.pem",
    )

    Alternatively, pass verify_ssl=True if you have added the certificate to your OS trust store or Python's certifi bundle.

For most users, the default verify_ssl=False is the correct choice.

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, unfortunately 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.

About

A python application used to interact with the Interactive Brokers REST API.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Contributors

Languages

Generated from areed1192/sigma-template