IB交易助手

ibkr-openclaw

by amuletxheart

Connect OpenClaw to Interactive Brokers via IB Gateway Docker. Live portfolio data, real-time quotes, historical K-lines, technical analysis, and Telegram alerts — all read-only safe. Use when users ask about IBKR integration, portfolio monitoring, stock analysis, or automated trading alerts.

4.5k平台与服务未扫描2026年3月30日

安装

claude skill add --url https://github.com/openclaw/skills

文档

IBKR + OpenClaw Integration

Connect OpenClaw to your Interactive Brokers account for live portfolio monitoring, real-time quotes, technical analysis, and automated Telegram alerts.

Features

  • Live account data — NAV, cash, P&L, buying power
  • Positions — all holdings with avg cost and exchange
  • Real-time quotes — delayed or live market data
  • Historical K-lines — daily OHLCV data for technical analysis
  • Technical indicators — RSI, MACD, Bollinger Bands, ATR, MA (via ib_async)
  • Read-only safe — API configured for read-only access

Prerequisites

  • Interactive Brokers account (live or paper)
  • IBKR Mobile app (for 2FA approval)
  • Docker & Docker Compose installed on your server
  • Python 3.9+ with ib_async and pandas

Setup Guide

Step 1: Install Docker

bash
curl -fsSL https://get.docker.com | sh
docker --version
docker compose version

Step 2: Clone IB Gateway Docker

The IB Gateway runs in a Docker container based on gnzsnz/ib-gateway-docker.

bash
cd ~/.openclaw/workspace
git clone https://github.com/gnzsnz/ib-gateway-docker.git
cd ib-gateway-docker

Step 3: Configure Environment

Create a .env file in the ib-gateway-docker directory:

env
# IBKR Account
TWS_USERID=your_username
TWS_PASSWORD=your_password

# Trading mode: live or paper
TRADING_MODE=live

# Read-only API (recommended for monitoring)
READ_ONLY_API=yes

# API settings
TWS_ACCEPT_INCOMING=auto
TWS_MASTER_CLIENT_ID=1

# 2FA device name (find in IBKR web portal → Settings → Security)
TWOFA_DEVICE=IB Key

# 2FA timeout
TWOFA_TIMEOUT_ACTION=exit

# Timezone
TIME_ZONE=Asia/Singapore
TZ=Asia/Singapore

# VNC password (optional, for remote desktop)
VNC_SERVER_PASSWORD=your_password

# Auto restart (daily maintenance)
AUTO_RESTART_TIME=23:45

# Save settings between restarts
SAVE_TWS_SETTINGS=yes

Important: Find your TWOFA_DEVICE name in your IBKR web portal under: Settings → Security → Second Factor Authentication → Devices

Step 4: Start the Container

bash
docker compose up -d

Check logs:

bash
docker logs algo-trader-ib-gateway-1 --tail 20

Step 5: Approve 2FA

The Gateway will prompt for 2FA. Approve the notification on your IBKR Mobile app.

Once connected, the API is available on:

  • Port 4001 → Paper trading API
  • Port 4002 → Live trading API (read-only if configured)

Step 6: Install Python Dependencies

bash
pip install ib_async pandas

Step 7: Test the Connection

bash
python3 ~/.openclaw/workspace/skills/ibkr-openclaw/scripts/ibkr_client.py summary --port 4001

Expected output:

code
Account: ['DU1234567']
----------------------------------------
BuyingPower..............      500,000.00
NetLiquidation...........      125,000.00
TotalCashValue...........       25,000.00
StockMarketValue.........      100,000.00
FuturesPNL...............        -500.00
UnrealizedPnL............        3,200.00

CLI Usage

ibkr_client.py — Account, Positions & Quotes

bash
# Account summary
python3 scripts/ibkr_client.py summary --port 4001

# All positions
python3 scripts/ibkr_client.py positions --port 4001

# Quick NAV
python3 scripts/ibkr_client.py nav --port 4001

# Quote a stock
python3 scripts/ibkr_client.py quote 2800 --exchange SEHK --currency HKD --port 4001

Getting Historical Data (Python)

python
from ib_async import IB, Stock

ib = IB()
ib.connect('127.0.0.1', 4001, clientId=1, readonly=True)

contract = Stock('2800', 'SEHK', 'HKD', primaryExchange='SEHK')
qualified = ib.qualifyContracts(contract)

bars = ib.reqHistoricalData(
    qualified[0], '', '6 M', '1 day', 'TRADES', True, 1
)

for bar in bars[-5:]:
    print(f"{bar.date} O:{bar.open} H:{bar.high} L:{bar.low} C:{bar.close} V:{bar.volume}")

ib.disconnect()

API Port Reference

PortModeDescription
4001PaperPaper trading API
4002LiveLive trading API
5900VNCRemote desktop (if VNC enabled)

Troubleshooting

2FA not arriving

  • Check IBKR Mobile app is logged in with the correct username
  • Verify TWOFA_DEVICE matches your device name in IBKR web portal
  • Check phone notification settings for IBKR app

Connection timeout

  • Ensure the container is running: docker ps
  • Check logs: docker logs algo-trader-ib-gateway-1 --tail 20
  • The Gateway restarts daily at 23:45 SGT (configured via AUTO_RESTART_TIME)

Read-only errors

  • READ_ONLY_API=yes prevents trading but allows all read queries
  • Some ib_async features auto-request write access — ignore those errors
  • Account summary and positions work fine in read-only mode

Container won't start

  • Check .env file has correct credentials
  • Ensure ports 4001, 4002, 5900 are not in use: netstat -tlnp | grep 400
  • Try recreating: docker compose up -d --force-recreate

Security Notes

  • .env contains your IBKR password in plain text — keep it secure
  • READ_ONLY_API=yes prevents accidental trades
  • VNC is bound to 127.0.0.1 (localhost only) by default
  • The container auto-restarts daily to maintain connection

Architecture

code
┌─────────────┐     ┌──────────────────┐     ┌─────────────┐
│  OpenClaw   │────►│  ibkr_client.py  │────►│ IB Gateway  │
│  Agent      │     │  (ib_async)      │     │  (Docker)   │
└─────────────┘     └──────────────────┘     └──────┬──────┘
                                                     │
                                              ┌──────▼──────┐
                                              │ IBKR Servers│
                                              │ (live data) │
                                              └─────────────┘

Credits

相关 Skills

Slack动图

by anthropics

Universal
热门

面向Slack的动图制作Skill,内置emoji/消息GIF的尺寸、帧率和色彩约束、校验与优化流程,适合把创意或上传图片快速做成可直接发送的Slack动画。

帮你快速做出适配 Slack 的动图,内置约束规则和校验工具,少踩上传与播放坑,做表情包和演示都更省心。

平台与服务
未扫描139.0k

MCP构建

by anthropics

Universal
热门

聚焦高质量 MCP Server 开发,覆盖协议研究、工具设计、错误处理与传输选型,适合用 FastMCP 或 MCP SDK 对接外部 API、封装服务能力。

想让 LLM 稳定调用外部 API,就用 MCP构建:从 Python 到 Node 都有成熟指引,帮你更快做出高质量 MCP 服务器。

平台与服务
未扫描139.0k

接口测试套件

by alirezarezvani

Universal
热门

扫描 Next.js、Express、FastAPI、Django REST 的 API 路由,自动生成覆盖鉴权、参数校验、错误码、分页、上传与限流场景的 Vitest 或 Pytest 测试套件。

帮你把API与集成测试自动化跑顺,减少回归漏测;能力全面,尤其适合复杂接口场景的QA团队。

平台与服务
未扫描15.8k

相关 MCP 服务

Slack 消息

编辑精选

by Anthropic

热门

Slack 是让 AI 助手直接读写你的 Slack 频道和消息的 MCP 服务器。

这个服务器解决了团队协作中需要 AI 实时获取 Slack 信息的痛点,特别适合开发团队让 Claude 帮忙汇总频道讨论或发送通知。不过,它目前只是参考实现,文档有限,不建议在生产环境直接使用——更适合开发者学习 MCP 如何集成第三方服务。

平台与服务
86.1k

by netdata

热门

io.github.netdata/mcp-server 是让 AI 助手实时监控服务器指标和日志的 MCP 服务器。

这个工具解决了运维人员需要手动检查系统状态的痛点,最适合 DevOps 团队让 Claude 自动分析性能数据。不过,它依赖 NetData 的现有部署,如果你没用过这个监控平台,得先花时间配置。

平台与服务
78.9k

by d4vinci

热门

Scrapling MCP Server 是专为现代网页设计的智能爬虫工具,支持绕过 Cloudflare 等反爬机制。

这个工具解决了爬取动态网页和反爬网站时的头疼问题,特别适合需要批量采集电商价格或新闻数据的开发者。不过,它依赖外部浏览器引擎,资源消耗较大,不适合轻量级任务。

平台与服务
52.8k

评论