interactive-brokers-mcp

作者 code-rabi

Interactive Brokers MCP Server

210
Stars
49
Forks
JavaScript
语言
2026/8/23
添加时间

⚠️ 第三方软件声明

本 Skill 为第三方开源软件,独立托管于 GitHub。SkillTip 仅为信息目录,不控制或维护底层仓库。所显示的安全检查为自动化且范围有限,安装前请自行审查源码。

阅读服务条款

安装

添加到你的 Claude Code skills 目录:

# Add to your Claude Code skills
git clone https://github.com/code-rabi/interactive-brokers-mcp

快速入门

使用 interactive-brokers-mcp 等 Skills 的指南。

安全报告

已验证

上次扫描:—

{
  "status": "PASSED",
  "issues": []
}

README.md

Interactive Brokers MCP Server

Interactive Brokers

DISCLAIMER: This is an unofficial, community-developed MCP server and is NOT affiliated with or endorsed by Interactive Brokers. This software is in Alpha state and may not work perfectly.

A Model Context Protocol (MCP) server that provides integration with Interactive Brokers' trading platform. This server allows AI assistants to interact with your IB account to retrieve market data, check positions, and place trades.

Interactive Brokers Server MCP server

🔒 Security Notice

Showcase of Interactive Brokers MCP

Features

  • Interactive Brokers API Integration: Full trading capabilities including account management, position tracking, real-time market data, and order management (market, limit, and stop orders)
  • Flex Query Support: Execute Flex Queries to retrieve account statements, trade confirmations, and historical data. Queries are automatically remembered for easy reuse
  • Flexible Authentication: Choose between browser-based OAuth authentication or headless mode with credentials for automated environments, including fully automated TOTP 2FA override. See TOTP 2FA Strategy Document for detailed configuration and important risk warnings.
  • Simple Setup: Run directly with npx - no Docker or additional installations required. Includes pre-configured IB Gateway and Java runtime for all platforms

Security Notice

IMPORTANT WARNINGS:

  • Financial Risk: Trading involves substantial risk of loss. Always test with paper trading first.
  • Security: This software handles sensitive financial data. Only run locally, never on public servers.
  • No Warranty: This unofficial software comes with no warranties. Use at your own risk.
  • Not Financial Advice: This tool is for automation only, not financial advice.

Prerequisites

No additional installations required for mainstream platforms. This package includes:

  • Pre-configured IB Gateway for all platforms (Linux, macOS, Windows)
  • Java Runtime Environment (JRE) for macOS, Windows, and standard Linux builds
  • Automatic first-run musl JRE download for Alpine-based containers (e.g. node:lts-alpine, supergateway)
  • All necessary dependencies

You only need:

  • Interactive Brokers account (paper or live trading)
  • Node.js 18+ (for running the MCP server)

Quick Start

Add this MCP server to your Cursor/Claude configuration:

{
  "mcpServers": {
    "interactive-brokers": {
      "command": "npx",
      "args": ["-y", "interactive-brokers-mcp"]
    }
  }
}

When you first use the server, a web browser window will automatically open for the Interactive Brokers OAuth authentication flow. Log in with your IB credentials to authorize the connection.

Headless Mode Configuration

For automated environments or when you prefer not to use a browser for authentication, you can enable headless mode by configuring it in your MCP server configuration:

{
  "mcpServers": {
    "interactive-brokers": {
      "command": "npx",
      "args": ["-y", "interactive-brokers-mcp"],
      "env": {
        "IB_HEADLESS_MODE": "true",
        "IB_USERNAME": "your_ib_username",
        "IB_PASSWORD_AUTH": "your_ib_password"
      }
    }
  }
}

In headless mode, the server will automatically authenticate using your credentials without opening a browser window. This is useful for:

  • Automated trading systems
  • Server environments without a display
  • CI/CD pipelines
  • Situations where browser interaction is not desired

Important: Even in headless mode, Interactive Brokers may still require two-factor authentication (2FA). When 2FA is triggered, the headless authentication will wait up to 60 seconds for you to complete the 2FA process through your configured method (mobile app, SMS, etc.) before returning an AUTHENTICATION_PENDING response. Wait for approval to complete, then check account info again.

To enable paper trading, add "IB_PAPER_TRADING": "true" to your environment variables:

{
  "mcpServers": {
    "interactive-brokers": {
      "command": "npx",
      "args": ["-y", "interactive-brokers-mcp"],
      "env": {
        "IB_HEADLESS_MODE": "true",
        "IB_USERNAME": "your_ib_username",
        "IB_PASSWORD_AUTH": "your_ib_password",
        "IB_PAPER_TRADING": "true"
      }
    }
  }
}

Security Note: Store credentials securely and never commit them to version control. Consider using environment variable files or secure credential management systems.

Flex Query Configuration (Optional)

To use Flex Queries for retrieving account statements and historical data, you need to configure your Flex Web Service Token:

{
  "mcpServers": {
    "interactive-brokers": {
      "command": "npx",
      "args": ["-y", "interactive-brokers-mcp"],
      "env": {
        "IB_FLEX_TOKEN": "your_flex_token_here"
      }
    }
  }
}

How to Get Your Flex Token:

  1. Log in to Interactive Brokers Account Management
  2. Go to SettingsAccount Settings
  3. Navigate to ReportingFlex Web Service
  4. Generate or retrieve your Flex Web Service Token

For detailed instructions on enabling Flex Web Service, see the IB Flex Web Service Guide.

Creating Flex Queries:

  1. Go to ReportsFlex Queries in Account Management
  2. Create or customize your query template
  3. Click the info icon next to your query to find its Query ID

For a complete guide on creating and customizing Flex Queries, see the IB Flex Queries Guide.

Note: When you execute a Flex Query for the first time, the MCP server automatically saves it with its name from the API. Future executions can reference the query by either its ID or its saved name.

Flex Query Features:

  • Automatic Memory: When you execute a Flex Query, it's automatically saved for future use
  • Easy Reuse: Previously used queries are remembered - no need to copy query IDs repeatedly
  • Friendly Names: Optionally provide a friendly name when first executing a query
  • Forget Queries: Remove queries you no longer need with the forget_flex_query tool

Configuration Variables

FeatureEnvironment VariableCommand Line Argument
UsernameIB_USERNAME--ib-username
PasswordIB_PASSWORD_AUTH--ib-password-auth
Headless ModeIB_HEADLESS_MODE--ib-headless-mode
Paper TradingIB_PAPER_TRADING--ib-paper-trading
Auth TimeoutIB_AUTH_TIMEOUT--ib-auth-timeout
Auth Wait SecondsIB_AUTH_WAIT_SECONDS--ib-auth-wait-seconds
Auth Poll SecondsIB_AUTH_POLL_SECONDS--ib-auth-poll-seconds
Force standalone bundled gatewayIB_FORCE_STANDALONE_GATEWAYN/A
Flex TokenIB_FLEX_TOKENN/A
Read-only modeIB_READ_ONLY_MODE--ib-read-only-mode
2FA StrategyIB_TWO_FA_STRATEGYN/A
TOTP Secret KeyIB_TOTP_SECRETN/A
Login page selector overridesIB_SELECTOR_USERNAME, IB_SELECTOR_PASSWORD, IB_SELECTOR_LOGIN_SUBMITN/A
TOTP form selector overridesIB_SELECTOR_TOTP_INPUT, IB_SELECTOR_TOTP_SUBMITN/A

See the TOTP 2FA Strategy Document for details on the 2FA and selector-override variables.

Gateway Lifecycle

On startup, the MCP first probes reachable local Gateway endpoints on the configured port and common Client Portal Gateway ports. If a healthy existing Gateway is found, the MCP attaches to it and does not start another bundled Gateway.

When no suitable existing Gateway is reachable, the MCP starts the bundled Java Gateway as a durable detached process. Runtime coordination files are stored under ib-gateway/.runtime/:

  • gateway-session.json records the MCP-managed Gateway pid, port, version, and log paths.
  • gateway-session.lock prevents two MCP processes from starting duplicate managed Gateways at the same time.
  • gateway.stdout.log and gateway.stderr.log receive the Gateway process output.

Normal MCP shutdown detaches from the Gateway and leaves it running so later MCP runs can reuse it. If IB_FORCE_STANDALONE_GATEWAY=true is set, the MCP skips unrelated external Gateway discovery, but it still reuses or coordinates through the durable MCP-managed session metadata and lock files.

To reset the managed Gateway session, stop the Gateway process recorded in ib-gateway/.runtime/gateway-session.json, then remove ib-gateway/.runtime/gateway-session.json and any stale ib-gateway/.runtime/gateway-session.lock. The MCP automatically removes stale metadata when the recorded pid no longer exists.

Available MCP Tools

Trading & Account Management

ToolDescription
get_account_infoRetrieve account information and balances
get_positionsGet current positions and P&L
get_market_dataReal-time market data for symbols
place_orderPlace market, limit, or stop orders (only if read-only mode is disabled)
get_order_statusCheck order execution status
get_live_ordersGet all live/open orders for monitoring

Flex Queries (Requires IB_FLEX_TOKEN)

ToolDescription
get_flex_queryExecute a Flex Query and retrieve statements (auto-saves for reuse)
list_flex_queriesList all previously used Flex Queries
forget_flex_queryRemove a saved Flex Query from memory

Troubleshooting

Authentication Problems:

  • Use the web interface that opens automatically
  • Complete any required two-factor authentication
  • Try paper trading mode if live trading fails

Gateway Discovery Problems:

  • If another IB Gateway is already listening on a local port but should not be reused, set IB_FORCE_STANDALONE_GATEWAY=true
  • Existing gateways are only reused when the MCP process can reach them over HTTPS; otherwise the bundled standalone gateway is started on an available port
  • For MCP-managed Gateway startup issues, inspect ib-gateway/.runtime/gateway.stdout.log, ib-gateway/.runtime/gateway.stderr.log, and ib-gateway/.runtime/gateway-session.json
  • To clear a stale managed startup lock, confirm no MCP process is currently starting Gateway, then remove ib-gateway/.runtime/gateway-session.lock

Support

  • This Server: Open an issue in this repository.

License

MIT License - see LICENSE file for details.

Thanks to our contributors

A big thank you to everyone who has contributed to making this project better.

Contributors

常见问题

What is interactive-brokers-mcp?

interactive-brokers-mcp is an open-source mcp servers skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by code-rabi. Interactive Brokers MCP Server. It has 210 GitHub stars.

Is interactive-brokers-mcp safe to use?

interactive-brokers-mcp failed SkillsLLM's automated security scan, which flagged one or more high-severity issues. Review the Security Report section carefully before using it.

How do I install interactive-brokers-mcp?

Clone the repository with "git clone https://github.com/code-rabi/interactive-brokers-mcp" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is interactive-brokers-mcp written in?

interactive-brokers-mcp is primarily written in JavaScript. It is open-source under code-rabi on GitHub, so you can review or fork the full source.

Are there alternatives to interactive-brokers-mcp?

Yes. SkillsLLM lists many other MCP Servers skills you can browse and compare side by side. Open the MCP Servers category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh interactive-brokers-mcp against similar tools.

评论 (0)

暂无评论,成为第一个分享想法的人!

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP 服务器apisai-tools
查看详情

Scrapling

by D4Vinci

🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl!

75,9137,581Python
MCP 服务器
查看详情

TrendRadar

by sansan0

⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的 AI 舆情监控助手与热点筛选工具!聚合多平台热点 + RSS 订阅,支持关键词精准筛选。AI 智能筛选新闻 + AI 翻译 + AI 分析简报直推手机,也支持接入 MCP 架构,赋能 AI 自然语言对话分析、情感洞察与趋势预测等。支持 Docker ,数据本地/云端自持。集成微信/飞书/钉钉/Telegram/邮件/ntfy/bark/slack 等渠道智能推送。

61,65224,883Python
MCP 服务器
查看详情

context7

by upstash

Context7 Platform -- Up-to-date code documentation for LLMs and AI code editors

61,0602,938TypeScript
MCP 服务器
查看详情

High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 158 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.

39,9393,219C
MCP 服务器
查看详情

开发者还喜欢

基于喜欢此 Skill 的开发者投票和收藏

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP 服务器apisai-tools
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情