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
- You must have an account on Interactive Brokers.
- Login to IBKR for Paper or Live trading account.
- Go to page, follow instructions to generate Consumer Key and Tokens.
- Install package locally for your python environment using
python -m pip install . - Set environment variables (or just hardcode values for config)
API_IBKR_CONSUMER_KEY- Consumer KeyAPI_IBKR_TOKEN- Access TokenAPI_IBKR_SECRET- Access Secret TokenAPI_IBKR_DH_PARAM- path to dhparam.pem fileAPI_IBKR_DH_PRIVATE_ENCRYPTION- path to private_encryption.pem fileAPI_IBKR_DH_PRIVATE_SIGNATURE- path to private_signature.pem file
- 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()- General information: https://www.interactivebrokers.com/campus/ibkr-api-page/cpapi-v1/#introduction
- OAuth for IB https://www.interactivebrokers.com/webtradingapi/oauth.pdf
- 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
To run tests you need to have your own Paper Trading account.
Run tests with pytest:
pytest- Use at your own risk