/ 目錄 / 演練場 / Alpaca
● 官方 alpacahq 🔑 需要你的金鑰

Alpaca

作者 alpacahq · alpacahq/alpaca-mcp-server

讓 Claude 透過 Alpaca 研究、回測並執行股票、ETF、選擇權及加密貨幣的交易——預設使用模擬帳戶,不會讓你的真實資金血本無歸。

Alpaca 官方 MCP 封裝了 Alpaca 交易與市場資料 API。可查詢報價、K 線、基本面資料及持倉;也可下單、修改或取消訂單。預設為模擬交易,這正是你學習的最佳方式。只有在策略經過驗證後,才切換至真實帳戶。

為什麼要用

核心特性

即時演示

實際使用效果

alpaca.replay ▶ 就緒
0/0

安裝

選擇你的客戶端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "alpaca": {
      "command": "uvx",
      "args": [
        "alpaca-mcp-server"
      ]
    }
  }
}

開啟 Claude Desktop → Settings → Developer → Edit Config。儲存後重啟應用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "alpaca": {
      "command": "uvx",
      "args": [
        "alpaca-mcp-server"
      ]
    }
  }
}

Cursor 使用與 Claude Desktop 相同的 mcpServers 格式。專案級設定優先於全域。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "alpaca": {
      "command": "uvx",
      "args": [
        "alpaca-mcp-server"
      ]
    }
  }
}

點擊 Cline 側欄中的 MCP Servers 圖示,然後選 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "alpaca": {
      "command": "uvx",
      "args": [
        "alpaca-mcp-server"
      ]
    }
  }
}

格式與 Claude Desktop 相同。重啟 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "alpaca",
      "command": "uvx",
      "args": [
        "alpaca-mcp-server"
      ]
    }
  ]
}

Continue 使用伺服器物件陣列,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "alpaca": {
      "command": {
        "path": "uvx",
        "args": [
          "alpaca-mcp-server"
        ]
      }
    }
  }
}

加入 context_servers。Zed 儲存後熱重載。

claude mcp add alpaca -- uvx alpaca-mcp-server

一行命令搞定。用 claude mcp list 驗證,claude mcp remove 移除。

使用場景

實戰用法: Alpaca

為你的自選清單產生每日盤前摘要

👤 積極的散戶交易者 ⏱ ~10 min beginner

何時使用: 你希望在開盤前用 30 秒瀏覽自選的 20 檔標的——包含隔夜漲跌、財報及明顯新聞。

前置條件
  • Alpaca 帳號(免費模擬帳戶) — alpaca.markets → 註冊 → 在儀表板取得 API 金鑰
  • 自選股清單 — 純文字清單,例如 [AAPL, MSFT, NVDA, ...]
步驟
  1. 取得隔夜 K 線資料
    For my watchlist [symbols], get yesterday's close and the latest pre-market quote. Compute % gap.✓ 已複製
    → 表格:symbol、prev_close、pre_open、gap_pct
  2. 標記異常標的
    Which tickers are gapping more than 2% in either direction? Rank by gap magnitude.✓ 已複製
    → 簡短的「需注意」清單
  3. 補充背景資訊
    For each outlier, pull the latest news headlines from Alpaca news endpoint.✓ 已複製
    → 每檔標的附帶可能原因的重點說明

結果: 一份每日一頁的盤前摘要,每天格式固定,無需手動點擊。

注意事項
  • 免費市場資料僅限 IEX,有延遲,報價可能與你的券商不符 — 用於隔夜或收盤後分析沒問題;若需要 SIP 即時資料,請升級至 Alpaca 付費資料方案
搭配使用: notion

用模擬帳戶執行簡單的規則型策略

👤 演算法交易初學者 ⏱ ~30 min intermediate

何時使用: 你有一條規則,例如「當 SPY 的 5 日報酬 < -3% 時買進,獲利 +2% 或持有 5 個交易日後賣出」,並希望用模擬資金即時運行。

前置條件
  • 已設定模擬帳戶金鑰 — Use APCA_API_BASE_URL=https://paper-api.alpaca.markets
  • 書面規則 — 進場、出場、倉位大小、最大虧損——在寫任何程式碼之前都要明確定義
步驟
  1. 查看帳戶與持倉
    Show my paper account equity, buying power, and current open positions.✓ 已複製
    → 清晰的帳戶快照
  2. 評估今日進場條件
    Get SPY's last 5 daily bars. Compute 5-day return. If it's < -3% and I don't already hold SPY, place a market buy for $5000 notional. Otherwise do nothing.✓ 已複製
    → 回傳訂單 ID 或明確的「不執行」訊息
  3. 記錄今日決策
    Append a row to /trades/journal.csv: date, condition_met, action, order_id, fill_price.✓ 已複製
    → 日誌列寫入完成

結果: 一份可稽核的每日模擬交易執行紀錄,附帶可供事後檢視的日誌。

注意事項
  • 測試時不小心使用真實帳戶金鑰 — 在開頭加一個非常明顯的檢查:確認帳號號碼與你的模擬帳戶一致,才能下任何訂單
  • Claude 忘記昨日持倉而重複買進 — 在評估進場條件前,務必先查詢目前持倉;絕不依賴記憶
搭配使用: filesystem

將投資組合再平衡至目標配置

👤 有目標配置的自主投資者 ⏱ ~20 min intermediate

何時使用: 每季執行:將 60/30/10(美股/國際股/債券)拉回目標,無需手動計算股數。

前置條件
  • 已定義目標配置 — 例如 VTI 60%、VXUS 30%、BND 10%
步驟
  1. 衡量偏離程度
    Get my positions and current prices. Compute current weight per symbol vs target [paste targets]. Show drift in $ and %.✓ 已複製
    → 每檔標的偏離程度表格
  2. 提出交易建議
    Propose the minimum set of buys/sells to bring weights within 1% of target. Show expected commissions (likely $0) and estimated slippage.✓ 已複製
    → 訂單計畫
  3. 確認後執行
    Before placing: summarize the plan in 3 lines and wait for my 'yes'. On yes, submit as market-on-open orders.✓ 已複製
    → 訂單已送出並附帶 ID;權益配置符合目標,誤差在 1% 以內

結果: 一份乾淨的季度再平衡紀錄,並附有每筆交易的原因說明。

注意事項
  • 應稅帳戶:每次再平衡都會觸發資本利得或虧損 — 優先使用新資金投入再平衡,或採用稅務批次感知的出場方式;如不確定,請僅在 IRA 帳戶中執行
搭配使用: filesystem

掃描選擇權鏈尋找短天期賣權權利金

👤 選擇權收益交易者(現金擔保賣出賣權 / 備兌買權) ⏱ ~25 min advanced

何時使用: 你想在每週願意持有的標的中,找出最佳的現金擔保賣出賣權。

前置條件
  • 已開通選擇權的 Alpaca 帳戶 — 在帳戶設定中啟用;模擬帳戶可用於學習
步驟
  1. 取得選擇權鏈與希臘字母
    Get the options chain for [ticker] expiring next Friday, puts only, strikes within 5% of spot. Include bid, ask, mid, delta, IV.✓ 已複製
    → 選擇權鏈表格
  2. 依年化報酬率排名
    Compute annualized return-on-cash for each strike assuming assignment. Filter delta between -0.15 and -0.30. Rank top 5.✓ 已複製
    → 排名後的精選清單
  3. 以中間價掛限價賣出開倉
    Place a sell-to-open limit order for 1 contract of the #1 strike at the mid. GTC, day-only.✓ 已複製
    → 回傳訂單 ID

結果: 一套可重複執行的每週收益操作流程,並附有保守的風險篩選機制。

注意事項
  • 對你不願意持有的公司賣出賣權 — 硬性規定:此策略只適用於你事先批准為長期持有的 10 檔標的
  • 流動性不足的履約價買賣價差極大,掛中間價幾乎不會成交 — 排名前先篩選 open_interest > 500 且買賣價差 < 中間價的 5%
搭配使用: notion

組合

與其他 MCP 搭配,撬動十倍槓桿

alpaca + notion

將每日盤前摘要自動推送至 Notion 頁面

Run my pre-market scan for watchlist and create a Notion page in 'Trading / Daily' with the results.✓ 已複製
alpaca + filesystem

交易日誌:將每筆訂單與原因附加寫入本機 CSV 檔案

After any place_order, append {ts, symbol, side, qty, reason} to /trading/journal.csv.✓ 已複製
alpaca + postgres

儲存每日權益曲線以供策略回測使用

Every evening, INSERT today's account equity into the equity_curve table.✓ 已複製

工具

此 MCP 暴露的能力

工具輸入參數何時呼叫成本
get_account 每次作業的第一個呼叫——確認你使用的是模擬還是真實帳戶 free
get_positions 在執行任何進場邏輯前,先查看目前持倉 free
get_bars symbol, timeframe, start, end, limit? 取得歷史 OHLCV 資料用於分析與訊號產生 free (IEX) or paid (SIP)
get_latest_quote symbol 下單前取得即時價格 free
place_order symbol, qty|notional, side, type, time_in_force, limit_price? 送出新訂單(務必先在模擬帳戶測試) free (commission-free)
cancel_order order_id 在訂單成交前取消未成交委託 free
get_options_chain underlying, expiration, side? 掃描履約價以規劃選擇權策略 free on Alpaca

成本與限制

運行它的成本

API 配額
資料 API 免費方案每分鐘 200 次請求;交易 API 在散戶規模下實際上不受限制
每次呼叫 Token 數
帳戶/持倉:200–500 tokens。K 線資料:隨 limit 參數增加而增加。
費用
Alpaca 免收手續費。SIP 即時資料付費方案約每月 $9;免費的 IEX 資料對大多數散戶來說已足夠。
提示
每個新策略至少模擬交易 4 週後,再動用真實資金。模擬帳戶完全免費。

安全

權限、密鑰、影響範圍

最小權限: Account API key + secret — Alpaca doesn't have sub-scopes
憑證儲存: APCA_API_KEY_IDAPCA_API_SECRET_KEYAPCA_API_BASE_URL 存放於環境變數中
資料出站: All calls to api.alpaca.markets or paper-api.alpaca.markets
切勿授予: Sharing live keys with any third-party service, including code hosts

故障排查

常見錯誤與修復

403 forbidden.insufficient-permissions

你的金鑰對應的環境不正確(真實帳戶 vs 模擬帳戶)。請確認 APCA_API_BASE_URL 與金鑰組相符。

驗證: curl -H 'APCA-API-KEY-ID: ...' -H 'APCA-API-SECRET-KEY: ...' $APCA_API_BASE_URL/v2/account
422 buying_power insufficient

你的模擬帳戶已重置,或交易規模超過可用現金。請呼叫 get_account 並重新計算倉位大小。

Bars return empty for recent timestamp

免費方案的 IEX 資料有約 15 分鐘延遲,且並非所有標的都有資料。請升級至 SIP 或等待延遲過後再查詢。

Order rejected: market closed

預設的 TIF 為 day;在收盤後下單需設定 time_in_force='opg''cls',或在限價單上加上 extended_hours=true 以支援盤後交易。

替代方案

Alpaca 對比其他方案

替代方案何時用它替代權衡
Interactive Brokers MCP你需要國際市場或期貨交易驗證流程較複雜(需要 gateway 應用程式);學習曲線較陡
Polygon.io MCP你只需要市場資料,不需要下單功能無法執行訂單;完整資料覆蓋需付費

更多

資源

📖 閱讀 GitHub 上的官方 README

🐙 查看未解決的 issue

🔍 瀏覽全部 400+ MCP 伺服器和 Skills