← 返回
开发者工具 中文

IBKR CLI

Comprehensive Interactive Brokers (IBKR) TWS/Gateway skill using ib_insync. Includes Python and bash CLIs for account, market data, historical data, contract...
使用 ib_insync 的全面盈透证券 (IBKR) TWS/Gateway 技能。包含 Python 和 Bash CLI,支持账户、市场数据、历史数据、合约等功能。
oscraters oscraters 来源
开发者工具 clawhub v1.0.0 1 版本 99908.4 Key: 无需
★ 0
Stars
📥 1,091
下载
💾 25
安装
1
版本
#latest

概述

IBKR Skill

Overview

This skill integrates with Interactive Brokers Trader Workstation (TWS) and IB Gateway through ib_insync, exposing operational IBKR workflows through:

  • A unified Python CLI: scripts/ibkr_cli.py
  • A bash CLI wrapper: scripts/ibkr.sh
  • Compatibility alias: scripts/openclaw.sh
  • Backward-compatible script entrypoints:
  • scripts/get_account_info.py
  • scripts/get_historical_data.py
  • scripts/place_order.py

Prerequisites

  • Interactive Brokers account with API permissions.
  • TWS or IB Gateway running with API enabled.
  • Python 3.9+ recommended.
  • ib_insync installed:
pip install ib_insync

Connection Configuration

All CLIs support connection overrides using flags or env vars.

Environment variables:

  • IBKR_HOST (default 127.0.0.1)
  • IBKR_PORT (default 7497)
  • IBKR_CLIENT_ID (default 1)
  • IBKR_ACCOUNT (optional)

Examples:

IBKR_PORT=4002 IBKR_CLIENT_ID=14 ./scripts/ibkr.sh account-summary
python3 scripts/ibkr_cli.py positions --host 127.0.0.1 --port 7496 --account DU123456

Bash CLI

./scripts/ibkr.sh [args]

Supported commands:

  • account (account summary + positions)
  • account-summary
  • positions
  • portfolio
  • pnl
  • quote
  • historical
  • place-order
  • cancel-order
  • open-orders
  • executions
  • contract-details
  • scanner

./scripts/openclaw.sh is an alias to the same CLI surface.

Python CLI

python3 scripts/ibkr_cli.py [args]

Account Services

python3 scripts/ibkr_cli.py account-summary --json
python3 scripts/ibkr_cli.py positions --account DU123456
python3 scripts/ibkr_cli.py portfolio --json
python3 scripts/ibkr_cli.py pnl --account DU123456 --wait 2

Market Data Services

python3 scripts/ibkr_cli.py quote --symbol AAPL --sec-type STK --market-data-type 3
python3 scripts/ibkr_cli.py historical --symbol EURUSD --sec-type CASH --duration "30 D" --bar-size "1 hour"

Notes:

  • Historical requests support full IB-format values via flags, including spaced tokens like "30 D".
  • For CASH, default whatToShow is MIDPOINT unless explicitly overridden.

Contract Discovery

python3 scripts/ibkr_cli.py contract-details --symbol ES --sec-type FUT --expiry 202606

Trading and Order Lifecycle

python3 scripts/ibkr_cli.py place-order --symbol AAPL --sec-type STK --action BUY --quantity 10 --order-type MKT
python3 scripts/ibkr_cli.py place-order --symbol AAPL --sec-type STK --action SELL --quantity 10 --order-type LMT --limit-price 250 --tif GTC
python3 scripts/ibkr_cli.py open-orders
python3 scripts/ibkr_cli.py cancel-order --order-id 12345
python3 scripts/ibkr_cli.py executions --json

Supported order types in the CLI:

  • MKT
  • LMT
  • STP
  • STP LMT

place-order waits for status updates and surfaces API errors collected during placement.

Scanner Service

python3 scripts/ibkr_cli.py scanner --instrument STK --location-code STK.US.MAJOR --scan-code TOP_PERC_GAIN --rows 25

Compatibility Scripts

Legacy scripts remain supported and now delegate to the unified CLI:

  • get_account_info.py
  • get_historical_data.py (legacy positional mode still works)
  • place_order.py (legacy positional mode still works)

Error Handling

The CLI returns non-zero exit codes for:

  • Import/dependency failures
  • Connection failures
  • Contract qualification failures
  • Invalid arguments
  • Missing open order for cancellation

References

See references/api_reference.md for IBKR and ib_insync documentation links.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-29 17:21 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

professional

Stock Analysis

udiedrichsen
{"answer":"基于雅虎财经数据,分析股票与加密货币。支持投资组合管理、自选股预警、股息分析、8维评分、热门趋势扫描及传闻/早期信号探测。适用于股票分析、持仓追踪、财报异动、加密监控、热门股追踪或提前发掘非主流传闻。"}
★ 274 📥 57,317
professional

A股量化 AkShare

mbpz
A股量化数据分析工具,基于AkShare库获取A股行情、财务数据、板块信息等。用于回答关于A股股票查询、行情数据、财务分析、选股等问题。
★ 179 📥 61,429
professional

All-Market Financial Data Hub

financial-ai-analyst
基于东方财富数据库,支持自然语言查询金融数据,覆盖A股、港股、美股、基金、债券等资产,提供实时行情、公司信息、估值、财务报表等,适用于投资研究、交易复盘、市场监控、行业分析、信用研究、财报审计、资产配置等场景,满足机构与个人需求。返回结果为
★ 118 📥 40,993