交易212协议服务器

为Trading 212提供多账户支持的模型上下文协议(MCP)服务器

  • by giuliodambrosio
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 giuliodambrosio/mcp-server-trading-212

使用说明

MCP 212交易服务器

具有多账户支持的用于交易的模型上下文协议(MCP)服务器212。

设置

自动引导(推荐)

运行:

./setup.sh

什么 setup.sh 做:

  • 安装依赖项(uv 如果可用,否则 pip)
  • 配置多帐户 .env 交互式(isa, invest,或两者皆有)
  • 可以更新Claude Desktop MCP配置(可选提示)

手动设置(可选)

  1. 安装依赖项:
    uv sync
    
  2. 创建本地env文件:
    cp .env.template .env
    
  3. 编辑 .env 随着 isa, invest或两者皆有。
  4. 运行服务器:
    uv run python main.py
    

环境配置

支持的帐户别名固定为:

  • isa
  • invest

您可以配置两者的任意组合。

两个账户:

212_ACCOUNTS=isa,invest
212_DEFAULT_ACCOUNT=isa

212_ISA_API_KEY_ID=...
212_ISA_API_KEY_SECRET=...
212_ISA_API_BASE_LIVE_URL=https://live.trading212.com/api/v0/

212_INVEST_API_KEY_ID=...
212_INVEST_API_KEY_SECRET=...
212_INVEST_API_BASE_LIVE_URL=https://live.trading212.com/api/v0/

仅限ISA:

212_ACCOUNTS=isa
212_DEFAULT_ACCOUNT=isa

212_ISA_API_KEY_ID=...
212_ISA_API_KEY_SECRET=...
212_ISA_API_BASE_LIVE_URL=https://live.trading212.com/api/v0/

仅投资:

212_ACCOUNTS=invest
212_DEFAULT_ACCOUNT=invest

212_INVEST_API_KEY_ID=...
212_INVEST_API_KEY_SECRET=...
212_INVEST_API_BASE_LIVE_URL=https://live.trading212.com/api/v0/

MCP资源

所有资源都是帐户范围的:

  • trading212://accounts/{account}/info
  • trading212://accounts/{account}/balance
  • trading212://accounts/{account}/portfolio
  • trading212://accounts/{account}/portfolio/{ticker}
  • trading212://accounts/{account}/orders
  • trading212://accounts/{account}/orders/{order_id}
  • trading212://accounts/{account}/pies
  • trading212://accounts/{account}/pies/{pie_id}
  • trading212://accounts/{account}/dividends
  • trading212://accounts/{account}/metadata/exchanges
  • trading212://accounts/{account}/metadata/instruments/tickers
  • trading212://accounts/{account}/metadata/instruments/{ticker}

使用 {account} 作为要么 isa 或 invest.

MCP工具

突变工具需要 account (isa 或 invest):

  • place_market_order(account, ticker, quantity, extended_hours)
  • place_limit_order(account, ticker, quantity, limit_price, time_validity)
  • place_stop_order(account, ticker, quantity, stop_price, time_validity)
  • place_stop_limit_order(account, ticker, quantity, stop_price, limit_price, time_validity)
  • cancel_order(account, order_id)
  • create_pie(account, name, dividend_destination, instrument_shares, end_date, goal)
  • update_pie(account, pie_id, name, dividend_destination, instrument_shares, end_date, goal)
  • delete_pie(account, pie_id)

其他工具:

  • list_accounts()
  • read_resource(uri)
  • mcp_capabilities()

read_resource 兼容性别名(也支持):

  • trading212://accounts/{account}/account/overview ->帐户信息
  • trading212://accounts/{account}/account/info ->帐户信息
  • trading212://accounts/{account}/account/balance ->账户余额

Claude桌面集成(可选)

本节仅适用于Claude Desktop用户。
如果您使用另一个MCP客户端,则可以跳过此步骤,直接配置您的客户端以运行此服务器。

选项A:让安装脚本更新Claude配置

./setup.sh --update-claude-config auto

这将保持您现有的非-212-trading 仅MCP条目和更新 mcpServers["212-trading"].

选项B:手动输入Claude配置

将此服务器添加到 mcpServers 在Claude桌面配置中:

{
  "command": "uv",
  "args": ["--directory", "/ABS/PATH/TO/mcp-server-212-trading", "run", "main.py"]
}

克劳德的第二个账户接线

如果克劳德已经运行了这个仓库(uv --directory <repo> run main.py),仅更新 .env:

212_ACCOUNTS=isa,invest
212_DEFAULT_ACCOUNT=isa

212_INVEST_API_KEY_ID=<your invest account key id>
212_INVEST_API_KEY_SECRET=<your invest account key secret>
212_INVEST_API_BASE_LIVE_URL=https://live.trading212.com/api/v0/

然后重新启动Claude Desktop并使用:

  • account=invest 用于工具
  • trading212://accounts/invest/... 资源

帮助克劳德正确使用它

与Claude聊天时,让它按照以下顺序进行:

  1. 呼叫 list_accounts()
  2. 挑选 isa 或 invest
  3. 仅使用 trading212://accounts/{account}/... 资源
  4. 包括 account 在每次不断变化的工具调用中

有用的入门信息:

Before doing anything, call list_accounts(). Then use account=isa (or account=invest) explicitly in every tool call and trading212://accounts/{account}/... resource URI.

测试

uv run pytest