Interactive Brokers MCP Server
Interactive Brokers MCP 服务器
免责声明:这是一个非官方、社区开发的 MCP 服务器,不隶属于 Interactive Brokers,也未得到其认可。本软件处于Alpha 阶段,可能无法完美运行。
一个提供与 Interactive Brokers 交易平台集成的模型上下文协议 (MCP) 服务器。该服务器允许 AI 助手与您的 IB 账户交互,以获取市场数据、检查持仓和下单。
🔒 安全须知

Related MCP server: Interactive Brokers MCP Server
功能
Interactive Brokers API 集成:完整的交易功能,包括账户管理、持仓跟踪、实时市场数据和订单管理(市价单、限价单和止损单)
Flex Query 支持:执行 Flex 查询以获取账户报表、交易确认和历史数据。查询会自动保存以便轻松重复使用
灵活的身份验证:支持基于浏览器的 OAuth 身份验证或带有凭据的无头模式(适用于自动化环境)
简单设置:直接使用
npx运行 - 无需 Docker 或额外安装。包含适用于所有平台的预配置 IB Gateway 和 Java 运行时
安全须知
重要警告:
财务风险:交易涉及巨大的亏损风险。请务必先进行模拟交易测试。
安全性:本软件处理敏感的财务数据。请仅在本地运行,切勿在公共服务器上运行。
无担保:此非官方软件不提供任何担保。使用风险自负。
非财务建议:此工具仅用于自动化,而非财务建议。
先决条件
无需额外安装! 本软件包包含:
适用于所有平台(Linux、macOS、Windows)的预配置 IB Gateway
用于 IB Gateway 的 Java 运行时环境 (JRE),包括适用于 Alpine 容器(例如
node:lts-alpine,supergateway)的 musl-libc 构建版本所有必要的依赖项
您只需要:
Interactive Brokers 账户(模拟或实盘交易)
Node.js 18+(用于运行 MCP 服务器)
快速入门
将此 MCP 服务器添加到您的 Cursor/Claude 配置中:
{
"mcpServers": {
"interactive-brokers": {
"command": "npx",
"args": ["-y", "interactive-brokers-mcp"]
}
}
}首次使用该服务器时,Web 浏览器窗口将自动打开以进行 Interactive Brokers OAuth 身份验证流程。使用您的 IB 凭据登录以授权连接。
无头模式配置
对于自动化环境,或者当您不想使用浏览器进行身份验证时,可以通过在 MCP 服务器配置中进行配置来启用无头模式:
{
"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"
}
}
}
}
在无头模式下,服务器将自动使用您的凭据进行身份验证,而无需打开浏览器窗口。这适用于:
自动化交易系统
无显示器的服务器环境
CI/CD 流水线
不希望进行浏览器交互的情况
重要提示:即使在无头模式下,Interactive Brokers 可能仍需要双重身份验证 (2FA)。当触发 2FA 时,无头身份验证将等待您通过配置的方法(移动应用、短信等)完成 2FA 流程后再继续。
要启用模拟交易,请将 "IB_PAPER_TRADING": "true" 添加到您的环境变量中:
{
"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"
}
}
}
}安全提示:请安全存储凭据,切勿将其提交到版本控制系统中。考虑使用环境变量文件或安全凭据管理系统。
Flex Query 配置(可选)
要使用 Flex Query 获取账户报表和历史数据,您需要配置您的 Flex Web 服务令牌:
{
"mcpServers": {
"interactive-brokers": {
"command": "npx",
"args": ["-y", "interactive-brokers-mcp"],
"env": {
"IB_FLEX_TOKEN": "your_flex_token_here"
}
}
}
}如何获取您的 Flex 令牌:
转到 设置 (Settings) → 账户设置 (Account Settings)
导航到 报告 (Reporting) → Flex Web 服务 (Flex Web Service)
生成或获取您的 Flex Web 服务令牌
有关启用 Flex Web 服务的详细说明,请参阅 IB Flex Web 服务指南。
创建 Flex 查询:
在账户管理中转到 报告 (Reports) → Flex 查询 (Flex Queries)
创建或自定义您的查询模板
点击查询旁边的信息图标以查找其查询 ID
有关创建和自定义 Flex 查询的完整指南,请参阅 IB Flex 查询指南。
注意:当您首次执行 Flex 查询时,MCP 服务器会自动将其名称从 API 保存下来。以后的执行可以通过其 ID 或保存的名称来引用该查询。
Flex 查询功能:
自动记忆:当您执行 Flex 查询时,它会自动保存以供将来使用
轻松重用:记住之前使用的查询 - 无需重复复制查询 ID
友好名称:首次执行查询时,可选择提供友好名称
忘记查询:使用
forget_flex_query工具删除不再需要的查询
配置变量
功能 | 环境变量 | 命令行参数 |
用户名 |
|
|
密码 |
|
|
无头模式 |
|
|
模拟交易 |
|
|
身份验证超时 |
|
|
Flex 令牌 |
| N/A |
只读模式 |
|
|
可用的 MCP 工具
交易与账户管理
工具 | 描述 |
| 获取账户信息和余额 |
| 获取当前持仓和盈亏 (P&L) |
| 获取代码的实时市场数据 |
| 下市价单、限价单或止损单(仅在禁用只读模式时可用) |
| 检查订单执行状态 |
| 获取所有实时/未结订单以进行监控 |
Flex 查询(需要 IB_FLEX_TOKEN)
工具 | 描述 |
| 执行 Flex 查询并获取报表(自动保存以供重用) |
| 列出所有之前使用的 Flex 查询 |
| 从内存中删除已保存的 Flex 查询 |
故障排除
身份验证问题:
使用自动打开的 Web 界面
完成任何必需的双重身份验证
如果实盘交易失败,请尝试模拟交易模式
支持
本服务器:在此存储库中提交问题。
许可证
MIT 许可证 - 详情请参阅 LICENSE 文件。
感谢我们的贡献者
非常感谢所有为使本项目变得更好而做出贡献的人。
Available Tools
14 toolsactivate_alertA
Activate a previously created alert. Usage: { "accountId": "<id>", "alertId": "<alertId>" }.
Inputs: alertId (required), accountId (required).
authenticateA
Authenticate with Interactive Brokers. Usage: { "confirm": true }.
Inputs: confirm (required).
confirm_orderB
Manually confirm an order that requires confirmation. Usage: { "replyId": "742a95a7-55f6-4d67-861b-2fd3e2b61e3c", "messageIds": ["o10151", "o10153"] }.
Inputs: replyId (required), messageIds (required).
create_alertC
Create a new trading alert. Usage: { "accountId": "<id>", "alertRequest": { "alertName": "Price Alert", "conditions": [{ "conidex": "265598", "type": "price", "operator": ">", "triggerMethod": "last", "value": "150" }] } }.
Inputs: accountId (required), alertRequest (required).
delete_alertC
Delete an alert. Usage: { "accountId": "<id>", "alertId": "<alertId>" }.
Inputs: alertId (required), accountId (required).
get_account_infoB
Get account information and balances. Usage: { "confirm": true }.
Inputs: confirm (required).
get_alertsC
Get all trading alerts for an account. Usage: { "accountId": "<id>" }.
Inputs: accountId (required).
get_live_ordersA
Get all live/open orders for monitoring and validation. Usage: {} for all accounts or { "accountId": "<id>" } for a specific account. This is the recommended way to validate that market orders were executed successfully after placing them.
Inputs: accountId.
get_market_dataA
Get real-time market data. Usage: { "symbol": "AAPL" } or { "symbol": "AAPL", "exchange": "NASDAQ" }.
Inputs: symbol (required), exchange.
get_option_chainA
Get option expirations and strikes for an underlying symbol. Usage: { "symbol": "AAPL" } or { "symbol": "AAPL", "exchange": "SMART" }.
Inputs: symbol (required), exchange.
get_order_statusA
Get the status of a specific order. Usage: { "orderId": "12345" }.
Inputs: orderId (required).
get_positionsC
Get current positions. Usage: {} or { "accountId": "<id>" }.
Inputs: accountId (required).
place_orderA
Place a trading order. Examples:
Market buy:
{ "accountId":"abc","symbol":"AAPL","action":"BUY","orderType":"MKT","quantity":1 }Limit sell:
{ "accountId":"abc","symbol":"AAPL","action":"SELL","orderType":"LMT","quantity":1,"price":185.5 }Stop sell:
{ "accountId":"abc","symbol":"AAPL","action":"SELL","orderType":"STP","quantity":1,"stopPrice":180 }Option buy:
{ "accountId":"abc","symbol":"AAPL","secType":"OPT","expiry":"JAN27","strike":200,"right":"C","action":"BUY","orderType":"LMT","quantity":1,"price":4.5 }Option by conid:
{ "accountId":"abc","conid":123456789,"secType":"OPT","action":"BUY","orderType":"MKT","quantity":1 }Suppress confirmations:
{ "accountId":"abc","symbol":"AAPL","action":"BUY","orderType":"MKT","quantity":1,"suppressConfirmations":true }
Inputs: action (required), quantity (required), accountId (required), orderType (required), +11 more.
resolve_option_conidA
Resolve a specific option contract conid. Usage: { "symbol": "AAPL", "expiry": "JAN27", "strike": 200, "right": "C" } or add { "exchange": "SMART" }.
Inputs: right (required), expiry (required), strike (required), symbol (required), +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 14 tools
Most tools have distinct purposes (alerts vs orders vs account data), but get_live_orders and get_order_status could be confused since both relate to order monitoring. get_alerts vs create/activate/delete_alert are clear, and get_option_chain vs resolve_option_conid are related but distinct enough.
The naming follows a consistent verb_noun pattern (get_, create_, activate_, delete_, place_, confirm_). Minor deviation: 'authenticate' lacks a noun object, and 'resolve_option_conid' is slightly more verbose than the others, but overall the pattern is predictable.
14 tools is well-scoped for a trading platform server covering authentication, account info, market data, orders, and alerts. Each tool addresses a distinct workflow need without excessive overlap or bloat.
The server covers core trading workflows: authentication, account/position queries, market data, order placement/status/confirmation, and alert lifecycle (create, activate, delete, list). Missing order cancellation/modification and position closing are notable gaps, but the primary use cases are covered.
Maintenance
Related MCP Connectors
Connect brokerage accounts to AI assistants: holdings, orders, asset lookup, and approved trading.
Unified financial infrastructure connecting AI agents directly to trade live/demo brokerage accounts, Web3 non-custodial wallets, real-time market data across equities, ETFs, crypto, forex, options, DeFi swaps, and prediction markets, institutional research feeds, and algorithmic strategy backtesters.
AI agents backtest, paper trade and live trade via your broker. Free to connect; OAuth.
Send trade alerts from AI agents to your broker: stocks, options, futures, crypto and perps.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides AI models with secure access to Interactive Brokers trading data and functionality, enabling account management, market data retrieval, and trading operations through natural language interactions.18MIT
- FlicenseNot gradedqualityDmaintenanceConnects AI assistants to Interactive Brokers for intelligent portfolio management, options analysis, risk monitoring, and automated trading strategy suggestions. Enables real-time account tracking, Greeks calculations, option chain analysis, and playbook-based risk adjustments through natural language.5-
- AlicenseAqualityDmaintenanceEnables AI agents to trade on Interactive Brokers: check quotes, balance, positions, and execute buy/sell orders (including fractional shares by dollar amount) via the Client Portal API.2015MIT
- AlicenseAqualityDmaintenanceEnables LLM agents to interact with Interactive Brokers accounts for market data, account info, and order entry with built-in risk controls and a two-step confirmation flow.9MIT