Skip to main content
Glama
shioaji-mcp

shioaji-mcp

by xianyuntang

shioaji-mcp

永豐金證券 Shioaji API 的唯讀 MCP 伺服器。讓 Claude Code 等 MCP client 查詢行情與帳務資料。不提供任何下單工具,無法下單、改單或刪單。

需求

  • Python 3.12 以上

  • uv

  • 永豐金證券帳戶,並已在 API 管理頁面申請 API Key

Related MCP server: Webull MCP Server

安裝

git clone https://github.com/xianyuntang/shioaji-mcp.git
cd shioaji-mcp
uv sync

在專案根目錄建立 .env(已列入 .gitignore):

SJ_API_KEY=你的_api_key
SJ_SEC_KEY=你的_secret_key
SJ_PRODUCTION=false
# 選填,只有 ca_status 會用到
SJ_CA_PATH=/絕對路徑/Sinopac.pfx
SJ_CA_PASSWD=憑證密碼

加入 Claude Code:

claude mcp add shioaji -- uv --directory /path/to/shioaji-mcp run --env-file .env main.py

其他 MCP client(JSON 設定):

{
  "mcpServers": {
    "shioaji": {
      "command": "uv",
      "args": ["--directory", "/path/to/shioaji-mcp", "run", "--env-file", ".env", "main.py"]
    }
  }
}

環境變數

變數

必填

預設

說明

SJ_API_KEY

是

—

永豐 API 管理頁面取得的 API Key

SJ_SEC_KEY

是

—

與 SJ_API_KEY 配對的 Secret Key

SJ_PRODUCTION

否

false

設 true 登入正式帳戶,否則使用模擬環境

SJ_CA_PATH

否

—

憑證檔(.pfx)的絕對路徑

SJ_CA_PASSWD

否

—

憑證密碼(通常是身分證字號)

憑證只用來讓 ca_status 回報到期時間。查詢功能不需要憑證,憑證啟用失敗也不影響查詢。

第一次呼叫工具時才登入,之後整個程序共用同一個 session。

工具

商品與行情

工具

說明

get_contract

商品資料(參考價、漲跌停、當沖、資券資訊)

get_snapshots

最新快照,一次最多 500 檔

get_kbars

指定日期區間的 1 分 K

get_ticks

單日逐筆成交(全部、最後 N 筆或時間區間)

scan

排行:漲跌幅、漲跌價、振幅、成交量、成交金額、成交筆數

credit_enquires

資券餘額

short_stock_sources

借券賣出餘額

disposition_stocks

處置股

attention_stocks

注意股

usage

API 連線數與每日流量額度

帳務

工具

說明

list_accounts

證券/期貨帳戶

account_balance

交割銀行帳戶餘額

settlements

交割款(T、T+1、T+2)

trading_limits

證券交易額度、融資融券額度

futures_margin

期權權益數、保證金、風險指標

list_positions / list_position_detail

未實現損益與持倉明細

list_profit_loss / list_profit_loss_detail / list_profit_loss_summary

已實現損益

list_trades

今日委託與成交

ca_status

憑證啟用結果與到期時間

商品代碼格式:股票 2330、期貨近月連續 TXFR1、選擇權 TXO31200G6、指數 IX0001(加權指數)。

行情查詢會計入 Shioaji 每日流量額度,不要用來輪詢即時報價。

免責聲明

非官方專案,與永豐金證券無關。依現狀提供,不負任何擔保,使用風險自負。

授權

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Read-only MCP server that lets a verified client connect their own AI to their trading account to read account data without order execution.
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables MCP clients to read Webull account balances, positions, orders, stock quotes, historical bars, and US option market data, with live equity trading available only as an explicitly enabled opt-in.
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables MCP clients to securely access read-only Psagot Trade account and market information through authenticated HTTP endpoints. It exposes only read-only tools, with no trade-submission capabilities.
      -
    • A
      license
      B
      quality
      C
      maintenance
      Enables read-only access to Questrade accounts, portfolios, market data, transactions, technical analysis, and order history through MCP.
      11
      MIT