| 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 指南。適用於:股票/期貨/選擇權交易、即時行情訂閱、帳務查詢、自動交易系統開發。
npx skills add https://github.com/nicepkg/ai-workflow --skill shioaji
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 常見問題與解決 |
# pip
pip install shioaji
# uv (recommended 推薦)
uv add shioaji
# with speed optimization 速度優化版
uv add shioaji --extra speed
# Docker
docker run -it sinotrade/shioaji:latest
import 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。
import shioaji as sj
api = sj.Shioaji(simulation=True)
api.login(api_key="YOUR_KEY", secret_key="YOUR_SECRET")
Available in simulation 模擬模式可用功能:
# 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)
sj.constant.Action.Buy # 買進
sj.constant.Action.Sell # 賣出
sj.constant.StockPriceType.LMT # Limit 限價
sj.constant.StockPriceType.MKT # Market 市價
sj.constant.StockPriceType.MKP # Range Market 範圍市價
sj.constant.FuturesPriceType.LMT # Limit 限價
sj.constant.FuturesPriceType.MKT # Market 市價
sj.constant.FuturesPriceType.MKP # Range Market 範圍市價
sj.constant.OrderType.ROD # Rest of Day 當日有效
sj.constant.OrderType.IOC # Immediate or Cancel 立即成交否則取消
sj.constant.OrderType.FOK # Fill or Kill 全部成交否則取消
sj.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 定盤
sj.constant.StockOrderCond.Cash # Cash 現股
sj.constant.StockOrderCond.MarginTrading # Margin 融資
sj.constant.StockOrderCond.ShortSelling # Short 融券
sj.constant.QuoteType.Tick # Tick data 逐筆成交
sj.constant.QuoteType.BidAsk # Bid/Ask data 五檔報價
# 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 |
# 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}")
# Stock positions 股票持倉
positions = api.list_positions(api.stock_account)
# Futures positions 期貨持倉
positions = api.list_positions(api.futopt_account)
api.cancel_order(trade)
# Change price 改價
api.update_order(trade=trade, price=590)
# Reduce quantity 減量 (can only reduce 只能減少)
api.update_order(trade=trade, qty=1)
try:
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)
api.logout()
Automatically organizes invoices and receipts for tax preparation by reading messy files, extracting key information, renaming them consistently, and sorting them into logical folders. Turns hours of manual bookkeeping into minutes of automated organization.
Expert guidance for systematic backtesting of trading strategies. Use when developing, testing, stress-testing, or validating quantitative trading strategies. Covers "beating ideas to death" methodology, parameter robustness testing, slippage modeling, bias prevention, and interpreting backtest results. Applicable when user asks about backtesting, strategy validation, robustness testing, avoiding overfitting, or systematic trading development.
This skill calculates key financial ratios and metrics from financial statement data for investment analysis
This skill provides an advanced financial modeling suite with DCF analysis, sensitivity testing, Monte Carlo simulations, and scenario planning for investment decisions
Crypto wallet operations via the awal CLI — sign in, check balances, send USDC/ETH/POL/SOL, trade tokens, fund the wallet, and use the x402 payment protocol to discover paid services, pay for API calls, monetize an API, or query onchain data. Use whenever the user mentions signing in, login, authentication, wallet status, balance, address, sending money, paying someone, transferring tokens, ENS names, swapping/trading/converting tokens, funding/topping up/onramp, USDC, ETH, POL, SOL, the x402 bazaar, paid APIs, monetizing an endpoint, or querying onchain data on Base.
Access real-time and historical stock market data, forex rates, cryptocurrency prices, commodities, economic indicators, and 50+ technical indicators via the Alpha Vantage API. Use when fetching stock prices (OHLCV), company fundamentals (income statement, balance sheet, cash flow), earnings, options data, market news/sentiment, insider transactions, GDP, CPI, treasury yields, gold/silver/oil prices, Bitcoin/crypto prices, forex exchange rates, or calculating technical indicators (SMA, EMA, MACD, RSI, Bollinger Bands). Requires a free API key from alphavantage.co.
Braintree Automation: manage payment processing via Stripe-compatible tools for customers, subscriptions, payment methods, and transactions
Coinbase Automation: list and manage cryptocurrency wallets, accounts, and portfolio data via Coinbase CDP SDK
Take nicepkg/shioaji from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference pip, docker.
Without those the skill loads but fails at the first command.