A local-first CLI for Interactive Brokers built on top of ib_async, Typer, and Rich.
If you use Claude Code, OpenClaw, or other AI agents that support the skills ecosystem, you can install the ibkr-cli skill to let your agent handle the entire setup and trading workflow for you:
npx skills add uu-z/ibkr-cli-forkOnce installed, simply tell your agent what you want to do (e.g., "help me install ibkr-cli and check my IBKR account") and it will guide you through everything — from installing IB Gateway to placing your first trade.
- Gateway-first local connection management with Docker lifecycle commands
- Auto-generated live and paper profiles from
ibkr gateway up - Connectivity checks for TCP reachability and IBKR API handshake
- Account queries for summary and positions
- Order queries for open, completed, and executions
- Safe stock order preview via IBKR what-if orders
- Real stock order submission with explicit
--submit - Order types: market, limit, stop, stop-limit, trailing stop, and bracket (take-profit + stop-loss)
- Open order cancellation by order ID
- Order modification (price, quantity, type, etc.) without cancel-and-resubmit
- Market data snapshot quotes with live-to-delayed fallback
- Finite quote watch mode for repeated quote updates
- Historical bar retrieval
- News headlines and article retrieval
- Options chain lookup with expirations, strikes, and greeks
- Market scanner for screening stocks by various criteria
- Company fundamentals: snapshot, financial summary, full financials, ownership (requires Reuters Fundamentals subscription)
- Historical trade records, P&L by symbol, fund transfers, dividends and cash transactions (via Flex Queries)
- CLI configuration management (
ibkr config set/show/path) - Automatic update check with
ibkr update
- Python 3.10+
- Either Docker or a local TWS / IB Gateway installation
- Market data subscriptions as required by your IBKR account
Install from PyPI with pipx so the ibkr command is isolated from your main Python environment:
pipx install ibkr-cliIf you prefer to install into the current Python environment:
python -m pip install ibkr-cliAfter installation:
ibkr --help
ibkr --versionBring up a dedicated IB Gateway container and auto-create its profiles:
ibkr gateway up ib-a --userid YOUR_IBKR_USER --password YOUR_IBKR_PASSWORD --vnc-password dev --defaultThis creates:
ib-a-live->127.0.0.1:4001ib-a-paper->127.0.0.1:4002
and stores the Gateway metadata plus generated profiles in the normal ibkr config file.
Inspect Gateway status:
ibkr gateway ps
ibkr gateway doctor ib-a
ibkr gateway logs ib-a --tail 100If Docker is not installed, you can still use the CLI with a local desktop app.
Built-in local profiles:
paper->127.0.0.1:7497for TWS paperlive->127.0.0.1:7496for TWS livegateway-paper->127.0.0.1:4002for IB Gateway papergateway-live->127.0.0.1:4001for IB Gateway live
Start TWS or IB Gateway, enable API socket access, then test a built-in profile:
ibkr connect test --profile paper
ibkr connect test --profile gateway-paperThe CLI keeps profiles and gateway metadata in a config file. To see where it is located:
ibkr config pathThe built-in fallback profiles are still available:
paper->127.0.0.1:7497live->127.0.0.1:7496gateway-paper->127.0.0.1:4002gateway-live->127.0.0.1:4001
You can still edit the config file directly or reset it to defaults with ibkr profile init --force, but the recommended path is to create managed profiles through ibkr gateway up.
ibkr profile list
ibkr profile show ib-a-paper
ibkr profile show ib-a-liveibkr doctor --profile ib-a-paper
ibkr connect test --profile ib-a-paperibkr account summary --profile ib-a-paper
ibkr positions --profile ib-a-paperibkr orders open --profile ib-a-paper
ibkr orders completed --profile ib-a-paper
ibkr orders executions --profile ib-a-paper
ibkr orders cancel 12345 --profile ib-a-paper
ibkr orders modify 12345 --limit 150.50 --profile ib-a-paperPreview first:
ibkr buy AAPL 10 --preview --profile ib-a-live
ibkr sell AAPL 10 --preview --profile ib-a-liveSubmit only when you explicitly intend to place an order:
ibkr buy AAPL 10 --submit --profile ib-a-live
ibkr sell AAPL 10 --submit --profile ib-a-liveLimit order:
ibkr buy AAPL 10 --type LMT --limit 150.00 --preview --profile ib-a-liveStop order:
ibkr sell AAPL 10 --type STP --stop 140.00 --preview --profile ib-a-liveStop-limit order:
ibkr sell AAPL 10 --type "STP LMT" --stop 140.00 --limit 139.50 --preview --profile ib-a-liveTrailing stop (by dollar amount or percentage):
ibkr sell AAPL 10 --type TRAIL --trail-amount 2.00 --preview --profile ib-a-live
ibkr sell AAPL 10 --type TRAIL --trail-percent 5 --preview --profile ib-a-liveBracket order (take-profit + stop-loss):
ibkr buy AAPL 10 --take-profit 160.00 --stop-loss 140.00 --preview --profile ib-a-live
ibkr buy AAPL 10 --type LMT --limit 150.00 --take-profit 160.00 --stop-loss 140.00 --preview --profile ib-a-liveThe CLI automatically checks for new versions once a day. To manually check and upgrade:
ibkr updateSnapshot quote:
ibkr quote AAPL --profile ib-a-paper
ibkr quote AAPL --profile ib-a-paper --jsonFinite quote watch:
ibkr quote AAPL --watch --updates 5 --interval 2 --profile ib-a-paperHistorical bars:
ibkr bars AAPL --profile ib-a-paper
ibkr bars AAPL --profile ib-a-paper --duration "1 D" --bar-size "5 mins" --jsonList available news providers:
ibkr news providers --profile gateway-paperFetch headlines for a symbol:
ibkr news headlines AAPL --profile gateway-paper
ibkr news headlines AAPL --limit 20 --providers "BRFG,DJNL" --profile gateway-paper
ibkr news headlines AAPL --start "20260101 00:00:00" --end "20260318 00:00:00" --profile gateway-paperRead a full article (using provider code and article ID from the headlines output):
ibkr news article BRFG "BRFG$12345" --profile gateway-paperList available option chains (expirations and strikes) for a symbol:
ibkr options chain AAPL --profile gateway-paperFetch option quotes with greeks for a specific expiration (auto-selects strikes near the money):
ibkr options quotes AAPL 20260320 --profile gateway-paperFilter by call/put and specific strikes:
ibkr options quotes AAPL 20260320 --right C --profile gateway-paper
ibkr options quotes AAPL 20260320 --strike 150 --strike 155 --strike 160 --profile gateway-paperList available scan codes, instruments, or locations:
ibkr scanner params codes --profile gateway-paper
ibkr scanner params instruments --profile gateway-paper
ibkr scanner params locations --profile gateway-paperRun a market scan:
ibkr scanner run TOP_PERC_GAIN --profile gateway-paper
ibkr scanner run MOST_ACTIVE --limit 10 --profile gateway-paper
ibkr scanner run HOT_BY_VOLUME --above-price 10 --below-price 100 --above-volume 1000000 --profile gateway-paper
ibkr scanner run HIGH_DIVIDEND_YIELD --market-cap-above 1000000000 --profile gateway-paperNote: Fundamentals commands require a Reuters Fundamentals subscription (~$7/month). Subscribe via IBKR Account Management > Settings > Market Data Subscriptions (search for "Reuters Fundamentals" or "LSEG").
Company snapshot (overview, ratios, officers, forecasts):
ibkr fundamentals snapshot AAPL --profile gateway-liveFinancial summary (key metrics across periods):
ibkr fundamentals summary AAPL --profile gateway-liveFull financial statements (income, balance sheet, cash flow):
ibkr fundamentals financials AAPL --profile gateway-liveOwnership structure (institutional and insider holders):
ibkr fundamentals ownership AAPL --profile gateway-liveThese commands fetch historical account data via IBKR Flex Queries over HTTPS. They do not require IB Gateway or TWS to be running, but data may be delayed up to T-1.
Setup:
# Token: Account Management > Settings > FlexWeb Service
ibkr config set flex.token YOUR_TOKEN
# Query ID: Account Management > Reports > Flex Queries
ibkr config set flex.query_id YOUR_QUERY_IDTrade history:
ibkr trades
ibkr trades --days 7
ibkr trades --days 90 --jsonP&L by symbol (realized + unrealized):
ibkr pnl
ibkr pnl --days 90Fund deposits, withdrawals, and transfers:
ibkr transfers
ibkr transfers --days 180Dividends, interest, withholding tax, and other cash transactions:
ibkr dividends
ibkr dividends --days 90ibkr config show # View current config (token is masked)
ibkr config set <key> <value> # Set a value (e.g. flex.token, flex.query_id, default_profile)
ibkr config path # Show config file locationMost read and trading commands support --json for machine-readable output.
Examples:
ibkr quote AAPL --profile gateway-paper --json
ibkr orders completed --profile gateway-paper --json
ibkr buy AAPL 10 --preview --profile gateway-paper --jsonWhen a command fails in --json mode, the CLI returns a structured error payload and exits with a non-zero process code.
Shape:
{
"ok": false,
"error": {
"code": "invalid_arguments",
"message": "Choose exactly one of --preview or --submit.",
"exit_code": 2,
"details": {
"preview": false,
"submit": false
}
}
}Current error code families include:
invalid_argumentsconfig_load_failedconfig_already_existsunknown_profileconnectivity_check_failedaccount_query_failedorder_query_failedorder_operation_failedmarket_data_request_failednews_request_failedoptions_request_failedscanner_request_failedfundamentals_request_failedflex_request_failed
Use gateway-paper or paper while validating commands that submit or cancel real orders.
buy and sell require exactly one of:
--preview--submit
This prevents accidental live order placement from a default command path.
If multiple CLI processes connect to the same TWS or IB Gateway profile with the same fixed client_id, IBKR can reject or interfere with the second connection.
For validation and manual testing, prefer running commands sequentially per profile unless you intentionally assign unique client IDs.
quote automatically falls back from live market data to delayed market data when live prices are unavailable.
This package installs the command ibkr.
If your machine already has another CLI exposing the same command name, uninstall the old tool or adjust your PATH so that this package's ibkr entrypoint is the one your shell resolves first.
Install in editable mode:
python -m pip install -e .Install in editable mode with optional test dependencies:
python -m pip install -e ".[test]"Run directly from source if needed:
python -m ibkr_cli.app --helpRun the offline test suite:
python -m unittest discover -s tests -vThe packaged entrypoint for installed users is:
ibkr --help