Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Shioaji Taiwan financial trading API guide. Use when trading stocks/futures/options on Taiwan markets, subscribing to real-time market data, querying account info, or building automated trading systems. Shioaji 台灣金融交易 API 指南。適用於:股票/期貨/選擇權交易、即時行情訂閱、帳務查詢、自動交易系統開發。
.claude/skills/nicepkg-shioaji/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 92% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 32% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 93% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 22% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 49% | 0% |
Shioaji is SinoPac's Python API for trading Taiwan financial markets (stocks, futures, options). Shioaji 是永豐金證券提供的 Python 交易 API,支援台灣股票、期貨、選擇權市場。
Official Docs 官方文檔: https://sinotrade.github.io/ LLM Reference: https://sinotrade.github.io/llms-full.txt
| Topic 主題 | File 檔案 | Description 說明 | |------------|-----------|------------------| | Preparation 準備 | PREPARE.md | Account setup, API keys, testing 開戶/金鑰申請/測試 | | Contracts 合約 | CONTRACTS.md | Stocks, Futures, Options contracts 股票/期貨/選擇權合約 | | Orders 下單 | ORDERS.md | Place, modify, cancel, combo orders 下單/改單/刪單/組合單 | | Reserve 預收 | RESERVE.md | Reserve orders for disposition stocks 處置股預收券款 | | Streaming 行情 | STREAMING.md | Real-time tick & bidask data 即時 Tick/BidAsk 資料 | | Market Data 市場資料 | MARKET_DATA.md | Historical, snapshot, credit, scanners 歷史資料/快照/資券/掃描器 | | Accounting 帳務 | ACCOUNTING.md | Balance, margin, P&L, trading limits 餘額/保證金/損益/額度 | | Advanced 進階 | ADVANCED.md | Quote binding, non-blocking, stop orders 報價綁定/非阻塞/觸價 | | Troubleshooting 問題排解 | TROUBLESHOOTING.md | Common issues and solutions 常見問題與解決 |
bash# pip pip install shioaji # uv (recommended 推薦) uv add shioaji # with speed optimization 速度優化版 uv add shioaji --extra speed # Docker docker run -it sinotrade/shioaji:latest
pythonimport shioaji as sj api = sj.Shioaji() # Login with API Key 使用 API Key 登入 accounts = api.login( api_key="YOUR_API_KEY", secret_key="YOUR_SECRET_KEY" ) # Activate CA certificate 啟用憑證 (required for placing orders 下單必須) api.activate_ca( ca_path="/path/to/Sinopac.pfx", ca_passwd="YOUR_CA_PASSWORD", )
Test API without real money. 使用模擬環境測試 API。
pythonimport shioaji as sj api = sj.Shioaji(simulation=True) api.login(api_key="YOUR_KEY", secret_key="YOUR_SECRET")
Available in simulation 模擬模式可用功能:
python# Get contract 取得合約 contract = api.Contracts.Stocks["2330"] # TSMC 台積電 # Create order 建立訂單 order = api.Order( price=580, quantity=1, action=sj.constant.Action.Buy, price_type=sj.constant.StockPriceType.LMT, order_type=sj.constant.OrderType.ROD, account=api.stock_account, ) # Place order 下單 trade = api.place_order(contract, order)
pythonsj.constant.Action.Buy # 買進 sj.constant.Action.Sell # 賣出
pythonsj.constant.StockPriceType.LMT # Limit 限價 sj.constant.StockPriceType.MKT # Market 市價 sj.constant.StockPriceType.MKP # Range Market 範圍市價
pythonsj.constant.FuturesPriceType.LMT # Limit 限價 sj.constant.FuturesPriceType.MKT # Market 市價 sj.constant.FuturesPriceType.MKP # Range Market 範圍市價
pythonsj.constant.OrderType.ROD # Rest of Day 當日有效 sj.constant.OrderType.IOC # Immediate or Cancel 立即成交否則取消 sj.constant.OrderType.FOK # Fill or Kill 全部成交否則取消
pythonsj.constant.StockOrderLot.Common # Regular 整股 (1000 shares) sj.constant.StockOrderLot.Odd # After-hours odd lot 盤後零股 sj.constant.StockOrderLot.IntradayOdd # Intraday odd lot 盤中零股 sj.constant.StockOrderLot.Fixing # Fixing 定盤
pythonsj.constant.StockOrderCond.Cash # Cash 現股 sj.constant.StockOrderCond.MarginTrading # Margin 融資 sj.constant.StockOrderCond.ShortSelling # Short 融券
pythonsj.constant.QuoteType.Tick # Tick data 逐筆成交 sj.constant.QuoteType.BidAsk # Bid/Ask data 五檔報價
python# Stock account 股票帳戶 api.stock_account # Futures account 期貨帳戶 api.futopt_account # List all accounts 列出所有帳戶 api.list_accounts()
| Category 類別 | Limit 限制 | |---------------|------------| | Daily Traffic 每日流量 | 500MB - 10GB (based on trading volume 依交易量) | | Quote Query 行情查詢 | 50 requests / 5 sec | | Accounting Query 帳務查詢 | 25 requests / 5 sec | | Connections 連線數 | 5 per person ID | | Daily Logins 每日登入 | 1000 times |
python# Subscribe tick data 訂閱逐筆成交 api.quote.subscribe( api.Contracts.Stocks["2330"], quote_type=sj.constant.QuoteType.Tick ) # Subscribe bidask 訂閱五檔 api.quote.subscribe( api.Contracts.Stocks["2330"], quote_type=sj.constant.QuoteType.BidAsk ) # Set callback 設定回調 @api.quote.on_quote def quote_callback(topic, quote): print(f"Topic: {topic}, Quote: {quote}")
python# Stock positions 股票持倉 positions = api.list_positions(api.stock_account) # Futures positions 期貨持倉 positions = api.list_positions(api.futopt_account)
pythonapi.cancel_order(trade)
python# Change price 改價 api.update_order(trade=trade, price=590) # Reduce quantity 減量 (can only reduce 只能減少) api.update_order(trade=trade, qty=1)
pythontry: trade = api.place_order(contract, order) except Exception as e: print(f"Order failed: {e}") # Check order status 檢查訂單狀態 api.update_status(api.stock_account) for trade in api.list_trades(): print(trade.status)
pythonapi.logout()
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 15,645 | 12,890 | -18% | 1 | 1 | 0% | 2,884 | 4,267 | +48% | 0 | 0 | — |
case-02 | fail→pass | 10,000 | 9,495 | -5% | 1 | 1 | 0% | 2,013 | 3,870 | +92% | 0 | 0 | — |
case-07 | fail→pass | 12,577 | 3,448 | -73% | 1 | 1 | 0% | 1,953 | 2,575 | +32% | 0 | 0 | — |
case-03 | pass→pass | 9,572 | 6,179 | -35% | 1 | 1 | 0% | 1,627 | 3,211 | +97% | 0 | 0 | — |
case-04 | pass→pass | 8,784 | 4,736 | -46% | 1 | 1 | 0% | 1,486 | 2,829 | +90% | 0 | 0 | — |
case-05 | fail→pass | 8,596 | 6,274 | -27% | 1 | 1 | 0% | 1,629 | 3,138 | +93% | 0 | 0 | — |
case-06 | fail→pass | 14,491 | 5,077 | -65% | 1 | 1 | 0% | 2,390 | 2,906 | +22% | 0 | 0 | — |
case-08 | pass→pass | 8,224 | 3,342 | -59% | 1 | 1 | 0% | 1,414 | 2,631 | +86% | 0 | 0 | — |
case-09 | fail→pass | 9,934 | 3,999 | -60% | 1 | 1 | 0% | 1,772 | 2,635 | +49% | 0 | 0 | — |
case-10 | pass→pass | 12,822 | 6,769 | -47% | 1 | 1 | 0% | 2,157 | 3,231 | +50% | 0 | 0 | — |
case-11 | pass→pass | 6,111 | 4,242 | -31% | 1 | 1 | 0% | 1,098 | 2,779 | +153% | 0 | 0 | — |
case-16 | fail→pass | 5,104 | 2,244 | -56% | 1 | 1 | 0% | 778 | 2,429 | +212% | 0 | 0 | — |
case-12 | pass→pass | 11,543 | 4,988 | -57% | 1 | 1 | 0% | 1,999 | 2,950 | +48% | 0 | 0 | — |
case-13 | fail→pass | 13,014 | 6,552 | -50% | 1 | 1 | 0% | 2,123 | 3,136 | +48% | 0 | 0 | — |
case-14 | fail→pass | 10,169 | 3,236 | -68% | 1 | 1 | 0% | 1,638 | 2,573 | +57% | 0 | 0 | — |
case-15 | fail→pass | 10,330 | 4,465 | -57% | 1 | 1 | 0% | 1,606 | 2,814 | +75% | 0 | 0 | — |
case-17 | fail→pass | 10,778 | 3,210 | -70% | 1 | 1 | 0% | 1,723 | 2,580 | +50% | 0 | 0 | — |
case-18 | pass→pass | 3,668 | 2,775 | -24% | 1 | 1 | 0% | 517 | 2,427 | +369% | 0 | 0 | — |
case-19 | fail→pass | 16,245 | 4,571 | -72% | 1 | 1 | 0% | 2,649 | 2,739 | +3% | 0 | 0 | — |
case-20 | fail→fail | 10,822 | 5,365 | -50% | 1 | 1 | 0% | 2,010 | 3,005 | +50% | 0 | 0 | — |
case-21 | pass→pass | 8,812 | 6,998 | -21% | 1 | 1 | 0% | 1,492 | 3,233 | +117% | 0 | 0 | — |
case-22 | pass→fail | 11,653 | 7,684 | -34% | 1 | 1 | 0% | 2,081 | 3,439 | +65% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +45 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.