paper-trader-mcp

paper-trader-mcp

A simulation-only MCP server for recording US-equity order intents and estimating outcomes from historical Alpaca NBBO quotes, without placing live orders.

Category
访问服务器

README

Paper Trader MCP

A local, durable, simulation-only MCP server for recording US-equity order intents and later estimating outcomes from historical Alpaca SIP NBBO quotes. It never places live orders or Alpaca paper-broker orders. There is no order endpoint, broker SDK, generic fetch tool, trades endpoint, GTC, extended-hours, fractional-share, or partial-fill support.

Install and run

Requirements: Python 3.14, uv, and Alpaca data credentials with historical SIP access.

./setup.sh
export APCA_API_KEY_ID='...'
export APCA_API_SECRET_KEY='...'
./run.sh

The scripts are executable and run.sh uses only this project's .venv. Credentials are read from the environment (the server does not load .env). Recording, listing, and closing intents work without credentials; evaluation requires them because it reads Alpaca's quote and calendar APIs. The database defaults to ~/.local/share/paper-trader/paper-trader.sqlite3; set PAPER_TRADER_DB to override it. See .env.example for bounded quote-policy and commission options.

Defaults you may want to configure

Setting Default Meaning
Commission per order $0 Applied to every simulated fill
Commission per share $0 Applied to every simulated fill
Order latency 250 ms Override per order with latency_ms
Quote lookback 120 s Search window for prevailing top-of-book quote
Maximum quote age 30 s Older quotes are unusable
Additional slippage beyond spread $0 Buys still cross to ask; sells cross to bid

Current sell-side SEC Section 31 and FINRA TAF fees are automatic and itemized. Set the commission variables only when modeling a broker that is not commission-free. Short borrow costs, margin interest, dividends, venue fees, rebates, and taxes are not configurable or modeled.

MCP configuration

Claude Code (~/.claude.json, within the desired project entry) or Desktop / Cowork (claude_desktop_config.json) can use the same stdio configuration:

{
  "mcpServers": {
    "paper-trader": {
      "command": "/absolute/path/to/paper-trader-mcp/run.sh",
      "env": {
        "APCA_API_KEY_ID": "YOUR_DATA_KEY",
        "APCA_API_SECRET_KEY": "YOUR_DATA_SECRET"
      }
    }
  }
}

Prefer launching the client from a shell containing credentials rather than writing secrets into configuration. The five tools are paper_trade_record, paper_trade_get, paper_trade_list, paper_trade_evaluate, and paper_trade_close. Mutation calls require a caller-generated unique request_id; exact retries replay while changed input conflicts. submitted_at is accepted only with backtest=true. Evaluation without as_of explicitly selects now - 16 minutes.

Model and safety caveats

This is an intentionally conservative estimate, not an execution simulator. It crosses one complete top-of-book quote (ask to buy, bid to sell), requires the displayed size to cover the entire order, assumes zero additional slippage, and declares resting limits or insufficient depth indeterminate. There is no L2/depth. Quotes must be regular-session, fresh, complete, non-crossed, SIP-feed records on or after 2025-11-03 (Alpaca changed quote-size units then). Equal timestamps retain API ordering and raw nanosecond timestamps. Temporary SIP embargoes use pending_data; model limitations that prevent a defensible fill use the distinct terminal state indeterminate.

DAY eligibility uses Alpaca's New York calendar, including holidays and early closes. Data newer than the 15-minute entitlement plus a one-minute guard is never queried or clamped. Weekend, pre-open, and after-close marks use the most recent session. Multi-session results do not model splits, dividends, ticker changes, short borrow/availability and fees, dividends owed by shorts, halts/LULD, auctions, or quote corrections.

Accounting uses decimal text and cash-flow logic. Configured commissions apply per fill. Sell fees include FINRA's published 2025-2029 equity TAF schedule and the SEC Section 31 rate (zero through 2026-04-03; 0.00002060 thereafter in the verified 2026 period); dates outside explicit SEC ranges produce warnings. TAF is calculated at the published per-share rate without an invented penny minimum or per-fill rounding, capped per trade, and exempted when execution price is below the applicable per-share rate. Results expose commissions, SEC fees, and FINRA fees separately. Snapshots are immutable. SQLite uses WAL, foreign keys, busy timeout, explicit short transactions, and one connection per operation; network requests occur before write transactions.

The only HTTP destinations implemented are redirect-disabled GET requests to:

  • https://data.alpaca.markets/v2/stocks/quotes (always feed=sip, one symbol)
  • https://paper-api.alpaca.markets/v2/calendar

Authoritative references: Alpaca historical stock quotes, historical stock data, and calendar API.

Tests

Core tests use only the standard library and fake providers, so MCP need not be installed:

PYTHONPATH=src python3 -m unittest discover -s tests -v

No test uses credentials or network access.

License

Copyright 2026 Emile Fortier.

Licensed under the Apache License 2.0.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选