shioaji-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@shioaji-mcp show my open positions and their unrealized P&L"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
shioaji-mcp
永豐金證券 Shioaji API 的唯讀 MCP 伺服器。讓 Claude Code 等 MCP client 查詢行情與帳務資料。不提供任何下單工具,無法下單、改單或刪單。
需求
Python 3.12 以上
永豐金證券帳戶,並已在 API 管理頁面申請 API Key
Related MCP server: Psagot remote MCP
安裝
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"]
}
}
}環境變數
變數 | 必填 | 預設 | 說明 |
| 是 | — | 永豐 API 管理頁面取得的 API Key |
| 是 | — | 與 |
| 否 |
| 設 |
| 否 | — | 憑證檔( |
| 否 | — | 憑證密碼(通常是身分證字號) |
憑證只用來讓 ca_status 回報到期時間。查詢功能不需要憑證,憑證啟用失敗也不影響查詢。
第一次呼叫工具時才登入,之後整個程序共用同一個 session。
工具
商品與行情
工具 | 說明 |
| 商品資料(參考價、漲跌停、當沖、資券資訊) |
| 最新快照,一次最多 500 檔 |
| 指定日期區間的 1 分 K |
| 單日逐筆成交(全部、最後 N 筆或時間區間) |
| 排行:漲跌幅、漲跌價、振幅、成交量、成交金額、成交筆數 |
| 資券餘額 |
| 借券賣出餘額 |
| 處置股 |
| 注意股 |
| API 連線數與每日流量額度 |
帳務
工具 | 說明 |
| 證券/期貨帳戶 |
| 交割銀行帳戶餘額 |
| 交割款(T、T+1、T+2) |
| 證券交易額度、融資融券額度 |
| 期權權益數、保證金、風險指標 |
| 未實現損益與持倉明細 |
| 已實現損益 |
| 今日委託與成交 |
| 憑證啟用結果與到期時間 |
商品代碼格式:股票 2330、期貨近月連續 TXFR1、選擇權 TXO31200G6、指數 IX0001(加權指數)。
行情查詢會計入 Shioaji 每日流量額度,不要用來輪詢即時報價。
免責聲明
非官方專案,與永豐金證券無關。依現狀提供,不負任何擔保,使用風險自負。
授權
Available Tools
22 toolsaccount_balanceB
Settlement bank account balance (Sinopac bank, sub-account, LINE Bank only).
Inputs: no named parameters.
attention_stocksC
Attention stocks (注意股) announced by the exchange.
Inputs: no named parameters.
ca_statusC
Certificate (SJ_CA_PATH) activation result and expiry time.
Inputs: no named parameters.
credit_enquiresC
Margin purchase / short sale balances (資券餘額) for stocks.
Inputs: codes (required).
disposition_stocksC
Disposition stocks (處置股) currently under trading restrictions.
Inputs: no named parameters.
futures_marginC
Futures/options account equity, margin, risk indicator.
Inputs: no named parameters.
get_contractB
Contract details: name, reference, limit up/down, unit, day-trade, margin/short info... code: stock '2330', continuous futures 'TXFR1'/'TXFR2', option 'TXO31200G6', index 'IX0001' (TAIEX).
Inputs: code (required).
get_kbarsA
1-minute K bars, dates YYYY-MM-DD. ts is nanoseconds since epoch. History from 2020-03-02 (stocks/index), 2020-03-22 (futures). Use TXFR1 for expired futures.
Inputs: end (required), code (required), start (required).
get_snapshotsA
Latest snapshot (open/high/low/close, change, volume, best bid/ask) for up to 500 codes.
Inputs: codes (required).
get_ticksA
Ticks of one trading day (YYYY-MM-DD). Give last_count for the last N ticks, or time_start/time_end ('HH:MM:SS') for a range; otherwise the whole day.
Inputs: code (required), date (required), time_end, last_count, +1 more.
list_accountsB
Stock / futures accounts available after login.
Inputs: no named parameters.
list_position_detailB
Per-lot breakdown of one position (detail_id = position id from list_positions).
Inputs: detail_id (required), account_type.
list_positionsB
Open positions with unrealized PnL. unit applies to stocks: Common = lots, Share = shares. Each row's id can be passed to list_position_detail.
Inputs: unit, account_type.
list_profit_lossB
Realized PnL records between dates (YYYY-MM-DD). Each row's id works with list_profit_loss_detail.
Inputs: end_date (required), begin_date (required), account_type.
list_profit_loss_detailB
Breakdown of one realized PnL record (detail_id = id from list_profit_loss).
Inputs: detail_id (required), account_type.
list_profit_loss_summaryB
Realized PnL summarized per instrument plus totals, dates YYYY-MM-DD.
Inputs: end_date (required), begin_date (required), account_type.
list_tradesC
Today's orders and fills across all accounts.
Inputs: no named parameters.
scanC
Stock ranking (top gainers, volume, amount...). ascending=False gives the top; date YYYY-MM-DD, default today.
Inputs: scanner_type (required), date, count, ascending.
settlementsB
Upcoming stock settlement amounts (T, T+1, T+2).
Inputs: no named parameters.
short_stock_sourcesC
Shares available for short selling (借券賣出餘額) for stocks.
Inputs: codes (required).
trading_limitsC
Stock account trading, margin and short limits.
Inputs: no named parameters.
usageA
API connections and daily traffic used/limit/remaining (bytes). Quota resets 08:00 on trading days.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 22 tools
Most tools target clearly distinct resources or time granularities, such as snapshots vs. K-bars vs. ticks, and positions vs. position detail. The main overlap is the profit/loss family (records, detail, summary) and several account/status tools, but descriptions provide enough cues to select correctly.
Names are all snake_case, but conventions are mixed: get_* for market data, list_* for account/portfolio records, and bare nouns for status/reference tools. It remains readable but does not follow a single predictable verb_noun pattern, and the typo 'credit_enquires' adds inconsistency.
22 tools is on the heavy side for a single server, especially with three profit/loss variants and separate detail lookups. The breadth reflects covering market data, account status, positions, and PnL, but it lands in the 16–25 heavy range.
Read-only monitoring is extensive: contracts, market data, accounts, positions, PnL, and trades are covered. However, there are no order placement, cancellation, or modification tools, which is a significant gap for a Shioaji trading server and blocks core trading workflows.
Maintenance
Related MCP Connectors
Read-only market charts, OHLC, backtests and a view of your connected broker accounts
Read-only market research: index funds, event cards, CLOB data, fund analytics. No orders.
Read-only MCP server for Sidechair. Your assistant reads your lessons, price bars and watchlist.
Read-only access to your MetaTrader 4 and 5 accounts for AI agents: balances, open positions, trade history with win rate, live quotes, symbol specs and candles. It cannot place, modify or close orders.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables 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
- FlicenseNot gradedqualityBmaintenanceEnables 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.-
- AlicenseBqualityCmaintenanceEnables read-only access to Questrade accounts, portfolios, market data, transactions, technical analysis, and order history through MCP.1138 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables MCP clients to observe and inspect Sierra Chart chartbooks, charts, studies, drawings, and data, read diagnostics, and apply validated configuration changes via a local bridge, without any order execution or trading features.1MIT