Webull CLI
面向 AI Agent、量化開發者及機構客戶的命令列交易工具。支援港股、美股/ETF、美股期權及中國 A 股(滬深港通)。
原始碼:webull-inc/webull-openapi-cli
什麼是 Webull CLI
Webull CLI(webull)是一個 Go 語言編寫的單一可執行檔命令列工具,將 Webull OpenAPI 封裝為結構化的命令列介面,透過 HMAC 簽名的 REST 請求存取多市場交易及行情資料。
能力概覽
| 資產類別 | 交易 | 行情 |
|---|---|---|
| 美股/ETF | ✓ | ✓ |
| 美股期權 | ✓ | — |
| 港股/ETF | ✓ | ✓ |
| A 股(滬深港通) | ✓ | ✓ |
架構概覽
前置條件
API 憑證
- 生產環境
- 測試環境
無需申請,使用公開的測試憑證即可立即開始。詳見 SDKs and Tools。
其他要求
- Go 1.21+(用於
go install)或直接下載預編譯檔案 - Webull App(如需二次驗證)
- 行情訂閱(用於實時報價):訂閱指南
設定步驟
步驟 1:安裝 Go 環境
檢查是否已安裝 Go:
go version
如未安裝或版本低於 1.21,請安裝 Go:
# macOS (Homebrew)
brew install go
# Linux
wget https://go.dev/dl/go1.22.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.22.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
# Windows — 從 https://go.dev/dl/ 下載安裝程式
步驟 2:安裝 Webull CLI
go install github.com/webull-inc/webull-openapi-cli/cmd/webull@latest
或從 GitHub Releases 下載預編譯檔案。
確保 $GOPATH/bin 在 PATH 中:
export PATH=$PATH:$(go env GOPATH)/bin
驗證安裝:
webull version
步驟 3:認證
webull auth login --region hk
Enter App Key: <your-app-key>
Enter App Secret: <hidden>
Checking 2FA configuration...
✓ Profile "default" created (region: hk, auth: ak_sk)
步驟 4:驗證連線
webull doctor
步驟 5:驗證帳戶存取
webull account list
使用範例
行情資料:
# 港股快照
webull data stock snapshot --symbol 00700,09988 --category HK_STOCK
# 美股快照
webull data stock snapshot --symbol AAPL,TSLA --category US_STOCK
# A 股快照
webull data stock snapshot --symbol 600519 --category CN_STOCK
# 港股日線
webull data stock bars --symbol 00700 --category HK_STOCK --timespan D --count 200
# 批量 K 線
webull data stock batch-bars --symbol 00700,09988 --category HK_STOCK --timespan M5 --count 100
# 買賣盤深度
webull data stock quotes --symbol 00700 --category HK_STOCK --depth 10
# 逐筆成交
webull data stock tick --symbol 00700 --category HK_STOCK --count 100
# 大單足跡
webull data stock footprint --symbol AAPL --category US_STOCK --timespan M1 --count 200
交易:
# 港股增強限價盤
webull order stock submit --account-id <account-id> --symbol 00700 \
--side BUY --qty 100 --type ENHANCED_LIMIT --limit-price 380.00 \
--market HK --time-in-force DAY
# 港股競價盤
webull order stock submit --account-id <account-id> --symbol 00700 \
--side BUY --qty 100 --type AT_AUCTION \
--market HK --time-in-force DAY
# 美股限價單
webull order stock submit --account-id <account-id> --symbol AAPL \
--side BUY --qty 10 --type LIMIT --limit-price 185.00 \
--market US --time-in-force DAY
# 美股期權
webull order option submit --account-id <account-id> --symbol AAPL \
--side BUY --qty 1 --option-type CALL --strike 190 --expiry 2026-04-17
# A 股限價單
webull order stock submit --account-id <account-id> --symbol 600519 \
--side BUY --qty 100 --type LIMIT --limit-price 1800.00 \
--market CN --time-in-force DAY
訂單管理:
webull order open --account-id <account-id>
webull order stock replace --account-id <account-id> \
--client-order-id cli_stock_123456 --limit-price 385.00
webull order cancel --account-id <account-id> --client-order-id cli_stock_123456 -y
webull order history --account-id <account-id>
帳戶:
webull account balance --account-id <account-id>
webull account positions --account-id <account-id>
可用命令
訂單
| 命令 | 描述 |
|---|---|
order stock submit | 下股票訂單(支援港股、美股及 A 股訂單類型) |
order stock preview | 預覽訂單費用 |
order stock replace | 修改股票訂單 |
order option submit | 下美股期權單 |
order option preview | 預覽期權費用 |
order option replace | 修改期權單 |
order cancel | 取消未成交訂單 |
order open | 查詢未完成訂單 |
order detail | 查詢訂單詳情 |
order history | 查詢歷史訂單 |
行情
| 命令 | 描述 |
|---|---|
data stock snapshot | 實時快照(港股/美股/A股) |
data stock bars | K 線(單一標的) |
data stock batch-bars | 批量 K 線 |
data stock quotes | 買賣盤深度 |
data stock tick | 逐筆成交 |
data stock footprint | 大單足跡 |
港股特有訂單類型
| 訂單類型 | 描述 |
|---|---|
ENHANCED_LIMIT | 增強限價盤 |
AT_AUCTION | 競價盤 |
AT_AUCTION_LIMIT | 競價限價盤 |
STOP_LOSS | 止損 |
STOP_LOSS_LIMIT | 止損限價 |
TRAILING_STOP_LOSS | 追蹤止損 |
TRAILING_STOP_LOSS_LIMIT | 追蹤止損限價 |
TOUCH_MKT | 觸價市價盤 |
TOUCH_LMT | 觸價限價盤 |
設定
環境端點
詳見 API Environments 了解生產及測試環境端點。
全域選項
| 選項 | 描述 |
|---|---|
--profile | 選擇設定檔 |
--region | 覆蓋地區 |
--env | 環境切換(prod / uat) |
--csv | CSV 格式輸出 |
-q, --quiet | 靜默模式 |
--verbose | 顯示請求摘要 |
--debug | 顯示完整請求回應 |
--timeout | HTTP 逾時秒數(預設 30) |
-y, --yes | 跳過確認提示 |
安全建議
- 切勿在聊天中分享 App Key、App Secret 或 Token
- 使用
--dry-run驗證參數,不會發起網路請求 - 下單前先使用
order preview預估費用 - 正式下單需確認,傳入
-y可跳過 - 建議先於測試環境驗證,再切換至生產環境
免責聲明
證券及期權交易涉及重大虧損風險。所有交易決策由閣下自行負責。下單前請核實訂單詳情。本軟件按「現狀」提供,不作任何保證。