Shioaji MCP Server
About
Access the Shioaji trading API for financial data and trading operations, requiring a SinoPac Securities account.
Details
- Author
- offbeat-studio
- Categories
- Other, Finance, API
Jump to
Setup
Install Shioaji MCP Server in your MCP client (Claude Desktop, Cursor, Windsurf, and others).
Repository: https://github.com/offbeat-studio/shioaji-mcp
Follow the installation instructions in the repository README, then restart your MCP client.
提供永豐金證券 Shioaji 交易 API 功能的模型上下文協議 (MCP) 伺服器,透過標準化工具存取交易功能。
- search_contracts- 根據關鍵字、交易所或類別搜尋交易合約
- get_snapshots- 取得指定合約的即時市場快照
- get_kbars- 取得合約的歷史 K 線資料
- place_order- 使用指定參數下單買賣(需要權限)
- cancel_order- 根據訂單 ID 取消現有訂單(需要權限)
- list_orders- 列出所有訂單及其狀態
- get_positions- 取得目前持倉和損益(支援股票、期貨或全部帳戶)
- get_account_balance- 取得帳戶餘額和保證金資訊(支援股票、期貨或全部帳戶)
⚠️ 交易安全性:交易操作(place_order、cancel_order)預設為停用。設定SHIOAJI_TRADING_ENABLED=true來啟用交易功能。
- check_terms_status- 檢查服務條款簽署狀態和 API 測試完成情況
- run_api_test- 執行服務條款合規的 API 測試(登入和訂單測試)
- 永豐金證券帳戶:您需要一個永豐金證券帳戶
- API 憑證:申請並取得 API Key 和 Secret Key
- 服務條款:完成文件簽署和 API 測試(詳見docs/SERVICE_TERMS.md)
關於使用 GitHub Container Registry 的 Docker 映像詳細資訊,請參閱docs/CONTAINER_REGISTRY.md。
使用 GitHub Container Registry 預建的 Docker 映像是最簡單的方式:
# 拉取最新穩定版映像 docker pull ghcr.io/musingfox/shioaji-mcp:latest # 執行 MCP 伺服器(唯讀模式) docker run --rm -i --platform=linux/amd64 \ -e SHIOAJI_API_KEY=your_api_key \ -e SHIOAJI_SECRET_KEY=your_secret_key \ -e SHIOAJI_TRADING_ENABLED=false \ ghcr.io/musingfox/shioaji-mcp:latest # 執行 MCP 伺服器並啟用交易功能 docker run --rm -i --platform=linux/amd64 \ -e SHIOAJI_API_KEY=your_api_key \ -e SHIOAJI_SECRET_KEY=your_secret_key \ -e SHIOAJI_TRADING_ENABLED=true \ ghcr.io/musingfox/shioaji-mcp:latest
- latest- 主分支的最新穩定發布版
- vX.Y.Z(如v0.1.0)- 特定版本發布
- dev- 最新開發版本(可能包含實驗性功能)
# 建置 Docker 映像 docker build -t shioaji-mcp . # 執行 MCP 伺服器(唯讀模式) docker run --rm -i --platform=linux/amd64 \ -e SHIOAJI_API_KEY=your_api_key \ -e SHIOAJI_SECRET_KEY=your_secret_key \ -e SHIOAJI_TRADING_ENABLED=false \ shioaji-mcp
{ "mcpServers": { "shioaji": { "command": "docker", "args": [ "run", "--rm", "-i", "--platform=linux/amd64", "-e", "SHIOAJI_API_KEY=your_api_key", "-e", "SHIOAJI_SECRET_KEY=your_secret_key", "-e", "SHIOAJI_TRADING_ENABLED=false", "ghcr.io/musingfox/shioaji-mcp:latest" ] } } }
- 設定SHIOAJI_TRADING_ENABLED=false(預設)為唯讀模式
- 設定SHIOAJI_TRADING_ENABLED=true啟用交易操作
"-e", "SHIOAJI_TRADING_ENABLED=true"
"ghcr.io/musingfox/shioaji-mcp:dev"
我們提供 Python 客戶端範例,示範如何程式化使用 Shioaji MCP 伺服器:
# 安裝 MCP 客戶端程式庫 pip install mcp-client # 設定您的 API 憑證 export SHIOAJI_API_KEY=your_api_key export SHIOAJI_SECRET_KEY=your_secret_key # 執行範例 ./examples/python_client.py
- 連接到 Shioaji MCP 伺服器
- 取得帳戶資訊
- 搜尋合約
- 取得即時市場資料
- 取得歷史 K 線資料
- 檢索持倉和帳戶餘額
# 複製專案 git clone <repository-url> cd shioaji-mcp # 安裝相依套件 uv sync # 設定環境變數 export SHIOAJI_API_KEY=your_api_key export SHIOAJI_SECRET_KEY=your_secret_key # 執行 MCP 伺服器 uv run python -m shioaji_mcp.server
# 安裝開發相依套件 uv sync --extra dev # 設定環境變數(如需本地開發) export SHIOAJI_API_KEY=your_api_key export SHIOAJI_SECRET_KEY=your_secret_key
# 執行測試 uv run pytest # 測試覆蓋率 uv run pytest --cov=src/shioaji_mcp
# 檢查和格式化程式碼 uv run ruff check --fix src/ tests/ uv run ruff format src/ tests/ # 型別檢查 uv run mypy src/
# 建置開發 Docker 映像 docker build -t shioaji-mcp-dev . # 測試 Docker 容器 docker run --rm -i --platform=linux/amd64 \ -e SHIOAJI_API_KEY=test_key \ -e SHIOAJI_SECRET_KEY=test_secret \ shioaji-mcp-dev
src/shioaji_mcp/ ├── server.py # MCP 伺服器主程式 ├── tools/ # 工具模組 │ ├── contracts.py # 合約搜尋 │ ├── market_data.py # 市場資料 │ ├── orders.py # 訂單操作 │ ├── positions.py # 持倉查詢 │ └── terms.py # 服務條款 └── utils/ # 工具程式 ├── auth.py # 身份驗證管理 ├── formatters.py # 資料格式化 └── shioaji_wrapper.py # Shioaji 包裝器
- 此 MCP 伺服器連接到真實的永豐金證券 API
- 所有交易操作都會執行真實訂單
- 請確保您在交易前了解風險
- 建議先以小額進行測試
- 本軟體以「現況」提供,不提供任何形式的保證
- 使用者需負責自己的交易決策和法規遵循
- Python 3.10-3.12
- 建議在 Linux 環境或 Docker 中執行
- macOS 使用者應使用 Docker
我們提供腳本來測試您的 Docker 設定是否與 Shioaji MCP 伺服器相容:
# 使腳本可執行 chmod +x scripts/test_docker_setup.sh # 執行測試腳本 ./scripts/test_docker_setup.sh
# 使用 Docker 解決 docker run --platform=linux/amd64 ...
# 檢查環境變數 echo $SHIOAJI_API_KEY echo $SHIOAJI_SECRET_KEY # 檢查 API 憑證是否有效 docker run --rm -i --platform=linux/amd64 \ -e SHIOAJI_API_KEY=your_key \ -e SHIOAJI_SECRET_KEY=your_secret \ shioaji-mcp python -c "from shioaji_mcp.utils.auth import auth_manager; print(auth_manager.is_connected())"
我們歡迎貢獻來改善 Shioaji MCP 伺服器!請參閱CONTRIBUTING.md了解如何為此專案貢獻的詳細指南。
- Fork 此專案
- 建立功能分支
- 進行變更並加入測試
- 執行程式碼檢查和測試
- 提交 Pull Request
Manage stock and crypto portfolios, place trades, and access market data via the Alpaca Trading API.
An MCP server for brokerage functionalities, built with the MCP framework.
A simple MCP server to interact with prediction market Kalshi
A server for performing trading operations using the Kite Connect API.
Korea Investment & Securities (KIS) REST API
Provides stock trading and market data using the Korea Investment & Securities (KIS) REST API.
An unofficial server to integrate with the Questrade API, providing access to trading accounts, market data, and portfolio information.
A MCP server for integrating with the Upstox trading API by Upstox.
A Model Context Protocol (MCP) server that integrates with the Upstox Trading API, enabling AI agents like Claude to securely access Indian stock market data, perform technical analysis, and view account information in read-only mode.
The Capital.com MCP Server lets your AI assistant talk to your trading account directly. Market data, position checks, trade previews – all in plain language, without leaving your AI tool.
US/HK markets — 110 tools: real-time quotes, options, orders, fundamentals, alerts, DCA & portfolio
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.




