/shioaji:shioajifrom shioaji
Provides guidance on using the Shioaji API (SinoPac/永豐金證券) for trading Taiwan stocks/options and US stocks via Python, CLI, or HTTP API with SSE streaming.
Ships in shioaji. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Shioaji is SinoPac's cross-language, cross-platform trading API for Taiwan financial markets (TWSE/TPEX/TAIFEX). It includes Python bindings, a CLI, and an HTTP API server that lets any programming language trade Taiwan markets.
Shioaji 是永豐金證券的跨語言、跨平台交易 API,提供 Python 綁定、CLI 與 HTTP API 伺服器,讓任何程式語言都能透過 HTTP API 交易台灣市場。
US stocks 美股 (1.8.0). US stock contracts, orders, active reports, accounting, realtime quotes, snapshots and historical ticks / K-bars are supported from 1.8.0. Install it with
uv add "shioaji==1.8.*"; a project pinned toshioaji==1.7.*must switch its pin the same way, becauseuv sync -P shioajionly upgrades within the pinned line. US trading needs an Intl (H, 複委託) account. HK and other markets are not supported. Start from US stock references. 1.8.0 起支援美股(商品檔、下單、回報、帳務、即時行情、快照與歷史逐筆/K 棒),用uv add "shioaji==1.8.*"安裝;已鎖shioaji==1.7.*的專案也要用同一個指令換版本線,uv sync -P shioaji只會在原版本線內升級。美股要用複委託(H)帳戶;港股等其他市場不支援。
Three access layers / 三種存取層:
import shioaji) for best performance, sync and asyncshioaji command-line tool for server management, trading, and data querieslocalhost:8080, accessible from JS/TS, Go, C/C++, C#, Rust, Java/Kotlin, or any HTTP clientReasoning about connections, timeouts, processes, or state? Read CONCEPTS.md first. It is the shared mental model these three layers assume — which timeout applies on which path, why Python needs no server but CLI/HTTP share one daemon, the per-person connection cap, streaming vs request-reply. Answer those questions from CONCEPTS.md instead of guessing. 推理連線、逾時、行程或狀態時,先讀 CONCEPTS.md。 這是三個存取層共用的心智模型 — 哪個 timeout 在哪條路徑生效、為何 Python 不需 server 而 CLI/HTTP 共用一個 daemon、每人連線上限、串流 vs 請求-回覆。這類問題從 CONCEPTS.md 找答案,不要猜。
Answer users directly from the bundled references. Do not route users to external documentation pages as a substitute for answering. The stable 1.5 API remains the compatibility baseline, while 1.7 features that intentionally change the interface—especially Contract V2—must follow their functional reference. Use MIGRATION.md only for legacy/deprecated idioms. Response handling always belongs in the matching functional reference. When an exact command flag, request field, or response schema must be confirmed, use installed CLI --help or the running server's /openapi.json.
First-time-user response / 首次使用者回應:
https://www.sinotrade.com.tw/newweb/PythonAPIKey/; signing pages do not issue API keys. After signing, do not jump straight to CA; confirm API credentials and run the required simulation login/order tests first. CA download is from the API management page, not the signing pages.https://www.sinotrade.com.tw/openact?strProd=0254&strWeb=0684&s=013299&utm_source=shioaji; API Key and CA use https://www.sinotrade.com.tw/newweb/PythonAPIKey/; stock signing uses https://www.sinotrade.com.tw/newweb/signCenter/S_openAPI/; futures/options signing uses https://www.sinotrade.com.tw/newweb/signCenter/F_openApi/. Never write "same page"/"同上頁面" for API Key or CA when the previous row is a signing page..env, .venv, uv sync, code examples, local file inspection, or order examples until the user confirms the relevant onboarding gates are done or explicitly asks for that technical step.只有在知道或明顯推斷使用者沒用過 Shioaji、第一次使用、不知道怎麼開始、或尚未完成永豐 API 開通時,才走首次使用者流程。不要把所有寬泛「我想用 shioaji」都預設為零經驗。確認/推定為首次使用者後,「請一步一步帶我」「慢慢來」「從零開始」代表沿著開通流程逐步確認,不是允許檢查 workspace 或建立本機入門專案。使用者回答第一個開通問題前,不要執行命令、列出檔案、提 Python 版本、提既有專案、提本機環境。第一步是資格/開通確認,不是技術設定:先確認是否已有永豐證券/期貨帳戶、要用證券或期貨/選擇權、API Key/Secret、API 約定書簽署、模擬登入/下單測試、正式環境 CA、正式就緒檢查。開戶後先確認/建立 API Key 與 Secret Key;簽署頁不會發 API Key,也不可稱為申請金鑰頁。簽署完成後不要直接跳 CA,先確認 API 憑證並跑模擬登入/下單測試。CA 下載在 API 管理頁,不是簽署頁。整理步驟表時每列都要寫明正確 URL;開戶不可使用永豐首頁,必須使用指定開戶頁;API Key 與 CA 不可寫「同上頁面」指向簽署頁。絕對不要要求使用者把 API Key、Secret Key、CA 密碼或憑證內容貼到對話,即使說只暫時使用也不行。除非使用者確認相關前置已完成或明確要求該技術步驟,否則不要進入安裝、.env、.venv、uv sync、程式碼範例、專案檔案檢查或下單範例。
Cross-access-layer response guardrails / 跨層回應守則:
success=false, an error code, or an operation status/message, branch on that field before continuing.PendingSubmit are not final failure/success signals; check the matching functional reference before deciding the next step.Token-efficient lookup / 精簡載入:
Response and Decision Summary, Prerequisites.For most tasks, load only 1-2 files. Use both axes: what (task) + how (access method).
Routing rule: choose the functional reference first, then add the access-method reference only when needed. Functional references own the workflow, payload rules, response shapes, and decision logic for that task. Language references explain how to send requests, receive responses, stream SSE, add auth headers, handle errors, and generate typed clients; they must not restate endpoint-specific business rules. Use HTTP_API.md for endpoint inventory and /openapi.json for exact installed-server schemas.
| Task | Load File |
|---|---|
| Understand the architecture: process model, connections, timeout layering, streaming vs request-reply, state | CONCEPTS.md |
| Migrate legacy code or fix deprecated Shioaji idioms | MIGRATION.md |
| Install, login, API keys, CA cert, simulation, env vars, constants | PREPARE.md |
| Install this Shioaji plugin/skill into Claude, Codex, Cursor, or another agent environment | AGENTS.md |
Use or troubleshoot agent_harness, approval capabilities, protected HTTP mutations, X-Shioaji-Agent-Capability, or mutation 403 responses | AGENT_HARNESS.md + the matching order/reserve reference |
Contract V2 lookup, typed info, lazy cache behavior, update events, or 1.5 api.Contracts compatibility | CONTRACTS.md (+ CONTRACT_FIELDS.md for full Info field lists) |
| Orders, callbacks/HTTP SSE, event IDs, historical empty IDs, deduplication and sequence gaps / 股票/期貨/選擇權/美股下單、改單、刪單;主動回報、事件 ID、歷史空 ID、去重與跳號 | ORDERS.md |
Build or enumerate combo contracts with api.contracts.combo_futures; validate managed BaseContract vs legacy directed ComboBase legs; subscribe/query futures combo market data; place, price, cancel, or troubleshoot combo orders; derive canonical leg order/actions and combo_type; use update_combostatus / list_combotrades | COMBO_ORDERS.md |
| Reserve shares for disposition/attention stocks | RESERVE.md |
| Subscribe real-time quotes, tick/bidask/quote/index callbacks, realtime KBar 即時K棒, SSE streams | STREAMING.md |
| Query authoritative index components or subscribe enriched index data 即時加值資料: calculated index 自算指數, index-components rankings/group projections 成分股排行與產業群組投影, legacy index/industry contribution | STREAMING_ENRICHED.md |
| Subscribe market signals 市場訊號: price-limit alerts 漲跌停訊號, rapid price moves 急拉急殺, volume burst 爆量大單, simtrade/suspend status filter 試撮/暫停 | STREAMING_SIGNALS.md |
Historical ticks, K-bars (date-range query 歷史K棒區間查詢), snapshots, ranking scanners 盤後排行 api.scanners, credit enquiry | MARKET_DATA.md |
| Account balance, margin, positions, P&L, settlements, limits, US (IntlAccount) positions/P&L/dividends | ACCOUNTING.md |
| Manage watchlists (CRUD, add/remove contracts) | WATCHLIST.md |
| Non-blocking mode, quote binding, stop orders, advanced patterns | ADVANCED.md |
| Interpret an error code / error message the user received, order rejection reasons | ERROR_CODES.md (+ TROUBLESHOOTING.md) |
| Errors, connection issues, troubleshooting | TROUBLESHOOTING.md |
| Inspect Server dashboard request rates, per-endpoint latency/errors, desired subscriptions versus physical topics, or configure Parquet monitoring history | OBSERVABILITY.md |
US stocks (1.8.0) reuse the same functions; each functional reference has a US section. Load the one for the task: 美股(1.8.0 起)沿用同一組函式,各功能文件都有美股一節,依任務載入:
| US task 美股任務 | Load |
|---|---|
Look up US contracts, UsStockInfo fields, exchanges, code tables 美股商品檔 | CONTRACTS.md § US Stocks + CONTRACT_FIELDS.md § UsStockInfo |
| Place / reduce / cancel US orders, IntlAccount, price and time-in-force rules, local errors, reservation orders 美股下單、減量、刪單 | ORDERS.md § US Stock Orders |
US order reports IntlOrder / IntlDeal, event_id gaps, reconciliation with update_status 美股回報與對帳 | ORDERS.md § US Order Reports |
| US positions, tax lots, realized P&L, dividends; what IntlAccounts cannot query yet 美股庫存、損益、股利 | ACCOUNTING.md § IntlAccount |
US tick / bid-ask quotes (QuoteType.Tick = trimmed: regular-session last-price trades plus extended-hours round-lot trades, QuoteType.TickFull = every trade incl. odd lots, US only), halts, quote freshness 美股即時報價(Tick 精簡、TickFull 全部成交)、暫停、新鮮度 | STREAMING.md § US Quotes |
US snapshots (UsSnapshot, mixed with Taiwan), historical ticks (UsTicks, UTC times, 100000-row cap) and K-bars 美股快照、歷史逐筆與 K 棒 | MARKET_DATA.md § US Market Data |
| US stocks in watchlists 美股自選股 | WATCHLIST.md § US Stocks |
| US over CLI / HTTP | CLI.md / HTTP_API.md (search US / Intl) |
HK and US options/futures are not supported. 港股與美股期權、期貨不支援。
Common confusions 容易混淆(選檔前先看):
| Want 要的 | Not 不是 | Load |
|---|---|---|
Realtime KBar push 即時K棒推送 (QuoteType.KBar, SSE stream/data/kbar) | Historical K-bars 歷史K棒查詢 (api.kbars(), POST /api/v1/data/kbars) | STREAMING.md; historical → MARKET_DATA.md |
Realtime signal push 即時訊號推送 (subscribe_scanner: 漲跌停/急變/爆量/試撮) | Ranking query 盤後排行查詢 (api.scanners(ScannerType…)) | STREAMING_SIGNALS.md; ranking → MARKET_DATA.md |
KBar/enriched dedicated HTTP routes 專屬端點 (/stream/subscribe/kbars, /stream/subscribe/calculated_index, …) | Generic 通用 /stream/subscribe (tick/bidask/quote only) | STREAMING.md / STREAMING_ENRICHED.md |
| Access Method | Additional File | Notes |
|---|---|---|
| Python (sync or async) | None — task refs include Python examples | Default path |
CLI (shioaji command) | CLI.md | Task ref (concept) + CLI.md (commands) |
| HTTP API (any language) | HTTP_API.md | Canonical endpoint inventory |
| JavaScript/TypeScript | JAVASCRIPT.md | HTTP/SSE client patterns |
| Go | GO.md | HTTP/SSE client patterns |
| C/C++ | CPP.md | HTTP/SSE client patterns |
| C# | CSHARP.md | HTTP/SSE client patterns |
| Rust | RUST.md | HTTP/SSE client patterns |
| Java/Kotlin | JAVA.md | HTTP/SSE client patterns |
Python users: load only the task reference (Axis 1).
CLI users: load the task reference + CLI.md.
Other languages: load the task reference + language reference. For example, "use JS to place an order" means load ORDERS.md for payload and Trade decision logic, plus JAVASCRIPT.md for fetch/SSE implementation patterns.
For installation, first-use setup, API keys, signing, CA, login, and readiness checks, load PREPARE.md. 安裝、首次開通、API 金鑰、簽署、CA、登入與就緒檢查請讀 PREPARE.md。
WARNING 警告: Always verify the server mode before placing orders. Production mode executes real trades with real money. 下單前務必確認伺服器模式。正式環境會使用真實資金進行真實交易。
shioaji server check (CLI) or GET /api/v1/info (HTTP — returns simulation field)shioaji server start --production or SJ_PRODUCTION=trueshioaji server stop then shioaji server start (without --production)Treat limits as guardrails, not as the starting point for API design. Start from the correct Shioaji workflow: keep one logged-in client/server session per user process, reuse subscriptions instead of polling, batch or cache repeated lookups when the functional reference recommends it, and retry only after checking the response meaning. Correct usage should stay far away from these limits; hitting them usually means a loop, reconnection pattern, polling design, or error-retry path is wrong and should be fixed rather than worked around.
使用限制是防濫用邊界,不是設計用法的出發點。回答或實作時先從正確 Shioaji 使用方式開始:每個使用者行程維持一個已登入 client/server session、用訂閱取代輪詢、依功能參考建議批次或快取重複查詢,並且先判斷 response 意義再 retry。正確用法會離這些限制很遠;若碰到限制,通常代表 迴圈、重連、輪詢或錯誤重試路徑有問題,應修正用法而不是設法貼著限制跑。
| Category | Limit |
|---|---|
| Daily Traffic | 500MB–10GB (based on trading volume) |
| Quote Query | 50 requests / 10 sec |
| Accounting Query | 25 requests / 5 sec |
| Connections | 5 per person ID |
| Daily Logins | 1000 times |
Source 來源:Shioaji 使用限制
Exchange trading rules in this skill (sessions, order type combinations, odd lots, price changes) summarize the official pages below; when they disagree, the official page wins. 本 skill 中的交易規則(交易時段、委託組合、零股、改價)摘錄自以下官方網頁;如有出入,以官方網頁為準。
HTTP API returns JSON errors: {"code": 400, "message": "...", "details": "..."}
Check the task reference before retrying. For example, empty market-data responses, PendingSubmit order status, and success=false subscription responses each require different next steps.
api.logout()
For task examples, see the functional reference (Axis 1). For transport and client patterns, see the language reference (Axis 2). 任務範例請見功能參考(軸 1);傳輸與客戶端模式請見語言參考(軸 2)。
references/ACCOUNTING.md (opens in a new tab)references/ADVANCED.md (opens in a new tab)references/AGENTS.md (opens in a new tab)references/AGENT_HARNESS.md (opens in a new tab)references/CLI.md (opens in a new tab)references/COMBO_ORDERS.md (opens in a new tab)references/CONCEPTS.md (opens in a new tab)references/CONTRACTS.md (opens in a new tab)references/CONTRACT_FIELDS.md (opens in a new tab)references/CPP.md (opens in a new tab)references/CSHARP.md (opens in a new tab)references/ERROR_CODES.md (opens in a new tab)references/GO.md (opens in a new tab)references/HTTP_API.md (opens in a new tab)references/JAVA.md (opens in a new tab)references/JAVASCRIPT.md (opens in a new tab)references/MARKET_DATA.md (opens in a new tab)references/MIGRATION.md (opens in a new tab)references/OBSERVABILITY.md (opens in a new tab)references/ORDERS.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub sinotrade/shioaji --plugin shioajiOther plugins' skills for the same job