Skip to main content

A local-first CLI for Interactive Brokers

Project description

ibkr-cli

A local-first CLI for Interactive Brokers built on top of ib_async, Typer, and Rich.

Use with AI agents

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 fatwang2/ibkr-cli

Once 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.

Features

  • Profile-based local connection management for TWS and IB Gateway
  • 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)
  • Automatic update check with ibkr update

Requirements

  • Python 3.10+
  • A running TWS or IB Gateway session
  • Market data subscriptions as required by your IBKR account

Installation

Install from PyPI with pipx so the ibkr command is isolated from your main Python environment:

pipx install ibkr-cli

If you prefer to install into the current Python environment:

python -m pip install ibkr-cli

After installation:

ibkr --help
ibkr --version

Quick start

Configuration

The CLI automatically creates a config file with default profiles on first use. To see where the config file is located:

ibkr config-path

The default profiles are:

  • paper -> 127.0.0.1:7497
  • live -> 127.0.0.1:7496
  • gateway-paper -> 127.0.0.1:4002
  • gateway-live -> 127.0.0.1:4001

You can edit the config file to customize host, port, or client_id. To reset it to defaults, run ibkr profile init --force.

Inspect available profiles

ibkr profile list
ibkr profile show gateway-paper

Check connectivity

ibkr doctor --profile gateway-paper
ibkr connect test --profile gateway-paper

Core commands

Account and positions

ibkr account summary --profile gateway-paper
ibkr positions --profile gateway-paper

Orders

ibkr orders open --profile gateway-paper
ibkr orders completed --profile gateway-paper
ibkr orders executions --profile gateway-paper
ibkr orders cancel 12345 --profile gateway-paper
ibkr orders modify 12345 --limit 150.50 --profile gateway-paper

Trading

Preview first:

ibkr buy AAPL 10 --preview --profile gateway-live
ibkr sell AAPL 10 --preview --profile gateway-live

Submit only when you explicitly intend to place an order:

ibkr buy AAPL 10 --submit --profile gateway-live
ibkr sell AAPL 10 --submit --profile gateway-live

Order types

Limit order:

ibkr buy AAPL 10 --type LMT --limit 150.00 --preview --profile gateway-live

Stop order:

ibkr sell AAPL 10 --type STP --stop 140.00 --preview --profile gateway-live

Stop-limit order:

ibkr sell AAPL 10 --type "STP LMT" --stop 140.00 --limit 139.50 --preview --profile gateway-live

Trailing stop (by dollar amount or percentage):

ibkr sell AAPL 10 --type TRAIL --trail-amount 2.00 --preview --profile gateway-live
ibkr sell AAPL 10 --type TRAIL --trail-percent 5 --preview --profile gateway-live

Bracket order (take-profit + stop-loss):

ibkr buy AAPL 10 --take-profit 160.00 --stop-loss 140.00 --preview --profile gateway-live
ibkr buy AAPL 10 --type LMT --limit 150.00 --take-profit 160.00 --stop-loss 140.00 --preview --profile gateway-live

Update

The CLI automatically checks for new versions once a day. To manually check and upgrade:

ibkr update

Market data

Snapshot quote:

ibkr quote AAPL --profile gateway-paper
ibkr quote AAPL --profile gateway-paper --json

Finite quote watch:

ibkr quote AAPL --watch --updates 5 --interval 2 --profile gateway-paper

Historical bars:

ibkr bars AAPL --profile gateway-paper
ibkr bars AAPL --profile gateway-paper --duration "1 D" --bar-size "5 mins" --json

News

List available news providers:

ibkr news providers --profile gateway-paper

Fetch 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-paper

Read a full article (using provider code and article ID from the headlines output):

ibkr news article BRFG "BRFG$12345" --profile gateway-paper

Options

List available option chains (expirations and strikes) for a symbol:

ibkr options chain AAPL --profile gateway-paper

Fetch option quotes with greeks for a specific expiration (auto-selects strikes near the money):

ibkr options quotes AAPL 20260320 --profile gateway-paper

Filter 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-paper

Scanner

List 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-paper

Run 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-paper

Fundamentals

Note: 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-live

Financial summary (key metrics across periods):

ibkr fundamentals summary AAPL --profile gateway-live

Full financial statements (income, balance sheet, cash flow):

ibkr fundamentals financials AAPL --profile gateway-live

Ownership structure (institutional and insider holders):

ibkr fundamentals ownership AAPL --profile gateway-live

JSON output

Most 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 --json

Error JSON shape

When 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_arguments
  • config_load_failed
  • config_already_exists
  • unknown_profile
  • connectivity_check_failed
  • account_query_failed
  • order_query_failed
  • order_operation_failed
  • market_data_request_failed
  • news_request_failed
  • options_request_failed
  • scanner_request_failed
  • fundamentals_request_failed

Operational notes

Prefer paper trading first

Use gateway-paper or paper while validating commands that submit or cancel real orders.

Submit is explicit

buy and sell require exactly one of:

  • --preview
  • --submit

This prevents accidental live order placement from a default command path.

Run same-profile validations serially

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.

Market data fallback

quote automatically falls back from live market data to delayed market data when live prices are unavailable.

Command name conflicts

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.

Development

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 --help

Run the offline test suite:

python -m unittest discover -s tests -v

The packaged entrypoint for installed users is:

ibkr --help

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ibkr_cli-0.6.0.tar.gz (42.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ibkr_cli-0.6.0-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file ibkr_cli-0.6.0.tar.gz.

File metadata

  • Download URL: ibkr_cli-0.6.0.tar.gz
  • Upload date:
  • Size: 42.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for ibkr_cli-0.6.0.tar.gz
Algorithm Hash digest
SHA256 1cbc1f0eeb4086fd881ac946f51818056e7432d56f5fdae5f811eaa9ec0fb709
MD5 a83ee0bc90b1a30adc756ac06cd3f395
BLAKE2b-256 628741c7e4394c0e2540e09af9b5399d9aa701242c440158ef639d4a310575a8

See more details on using hashes here.

File details

Details for the file ibkr_cli-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: ibkr_cli-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for ibkr_cli-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac7ac45ec15cc6bc01820fb0dc4af2ed756bd42b573d757b3a285472ca70e7c6
MD5 e20edda9017bb79399f72aa88b73b1c0
BLAKE2b-256 d4d4a49c238167c15854bfe4294d332bd4c6b37a139bd1f29fb92e5995e0f4fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page