XI

xiao81/ibkr-mcp-server

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

23 stars 10 forks 质量 56 趋势 0NOASSERTION

一个用于IBKR TWS API的MCP服务器

概览

一个用于交互式经纪商TWS API的模型上下文协议(MCP)服务器,使AI助手能够访问投资组合数据、账户信息和实时市场价格。 - get_portfolio() - 检索当前投资组合及持仓和损益表 - get_account_summary() - 获取账户余额和关键指标 - get_stock_price(代码) - 查询当前股价 - get_option_price(代码,到期日,行权价,右) - 获取期权价格 在TWS中,切换到→ → →:- ✅ - ✅ : 7497(纸质)或7496(有线) - ❌ (必须禁用) 添加到 ~/Library/Application Support/Claude/claude_desktop_config.json: - “分析我当前的投资组合表现” - “AAPL和MSFT的当前价格是多少?” - “给我看我的账户摘要” - 确保TWS/IB网关运行 - 检查TWS中的API设置是否启用 - 验证端口正确(7497 vs 7496) - 在TWS设置中禁用“只读API”- 在TWS全局配置中启用API。 ⚠️ :本软件仅供教育用途。使用请自行承担风险。

概述(AI 翻译)

一个用于交互式经纪商TWS API的模型上下文协议(MCP)服务器,使AI助手能够访问投资组合数据、账户信息和实时市场价格。

特色

  • get_portfolio() - 检索当前投资组合,包括头寸和损益表
  • get_account_summary() - 获取账户余额和关键指标
  • get_stock_price(symbol) - 查找当前股价
  • get_option_price(symbol, expiry, strike, right) - 获取期权价格

先修条件

  1. 互动经纪账户(纸面或实时)
  2. TWS(Trader工作站)或IB网关运行中
  3. Python 3.10+

快速启动

1.安装依赖

2.配置连接

3.配置TWS

在TWS中,选择配置 → 全局配置 →API →设置:

  • ✅ 启用ActiveX和套接字客户端
  • ✅ 插槽接口:7497(纸质)或7496(有线)
  • ❌ 只读API(必须禁用)

4.测试设置

5.运行服务器

6.Claude 桌面集成

添加到~/Library/Application Support/Claude/claude_desktop_config.json:

使用示例

  • “分析我当前的投资组合表现”
  • “AAPL和MSFT目前的价格是多少?”

本页由 AI 翻译,技术细节请以原文为准。

README

IBKR-MCP-Server

A Model Context Protocol (MCP) Server for Interactive Brokers TWS API that enables AI assistants to access portfolio data, account information, and real-time market prices.

Features

  • get_portfolio() - Retrieve current portfolio with positions and P&L
  • get_account_summary() - Get account balances and key metrics
  • get_stock_price(symbol) - Look up current stock prices
  • get_option_price(symbol, expiry, strike, right) - Get option prices

Prerequisites

  1. Interactive Brokers Account (Paper or Live)
  2. TWS (Trader Workstation) or IB Gateway running
  3. Python 3.10+

Quick Start

1. Install Dependencies

# Clone and setup
git clone https://github.com/your-username/IBKR-MCP-Server.git
cd IBKR-MCP-Server

# Install with UV (recommended)
curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync

# Or with pip
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -e .

2. Configure Connection

# Copy example config
cp env.example .env

# Edit .env file:
IBKR_HOST=127.0.0.1
IBKR_PORT=7497              # 7497 for paper, 7496 for live
IBKR_CLIENT_ID=1
IBKR_IS_PAPER=true          # true for paper, false for live

3. Configure TWS

In TWS, go to Configure → Global Configuration → API → Settings:

  • ✅ Enable ActiveX and Socket Clients
  • ✅ Socket port: 7497 (paper) or 7496 (live)
  • ❌ Read-Only API (must be disabled)

4. Test Setup

# Test connection
uv run python test_connection.py

5. Run Server

# Start the MCP server
uv run python src/ibkr_mcp/server.py

6. Claude Desktop Integration

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "ibkr": {
      "command": "uv",
      "args": ["run", "python", "src/ibkr_mcp/server.py"],
      "cwd": "/path/to/IBKR-MCP-Server",
      "env": {
        "IBKR_PORT": "7497",
        "IBKR_IS_PAPER": "true"
      }
    }
  }
}

Usage Examples

  • “Analyze my current portfolio performance”
  • “What’s the current price of AAPL and MSFT?”
  • “Show me my account summary”

Troubleshooting

Connection Issues:

  • Ensure TWS/IB Gateway is running
  • Check API settings are enabled in TWS
  • Verify correct port (7497 vs 7496)

Permission Issues:

  • Disable “Read-Only API” in TWS settings
  • Enable API in TWS global configuration

⚠️ Disclaimer: This software is for educational purposes. Use at your own risk. Start with paper trading.

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "ibkr": { "command": "uv", "args": ["run", "python", "src/ibkr_mcp/server.py"], "cwd": "/path/to/IBKR-MCP-Server", "env": { "IBKR_PORT": "7497", "IBKR_IS_PAPER": "true" } } } }