跳至主要内容

帳戶

帳戶 API 讓您獲取帳戶列表、查詢餘額和檢查當前持倉。這些通常是下單前的第一步操作。

可用端點

端點說明
帳戶列表獲取您憑證下的所有帳戶
帳戶餘額查詢特定帳戶的餘額、購買力和現金詳情
帳戶持倉獲取特定帳戶的當前持倉和倉位資訊

典型工作流程

  1. 呼叫帳戶列表獲取您的 account_id
  2. 使用 account_id 查詢餘額持倉
  3. 根據餘額和持倉決定交易策略
提示

帳戶列表回應包含與您憑證關聯的所有帳戶。股票和期權帳戶可能有不同的 Account ID。

程式碼範例

獲取帳戶列表

from webull.core.client import ApiClient
from webull.trade.trade_client import TradeClient

api_client = ApiClient("<your_app_key>", "<your_app_secret>", "hk")
api_client.add_endpoint("hk", "<api_endpoint>")

trade_client = TradeClient(api_client)
res = trade_client.get_account_list()
if res.status_code == 200:
accounts = res.json()
for account in accounts:
print(f"Account ID: {account['account_id']}, Type: {account['account_type']}")

查詢帳戶餘額

account_id = "<your_account_id>"
res = trade_client.get_account_balance(account_id=account_id)
if res.status_code == 200:
print("Balance:", res.json())

查詢帳戶持倉

res = trade_client.get_account_positions(account_id=account_id)
if res.status_code == 200:
print("Positions:", res.json())

下一步

  • 訂單 — 使用 Account ID 下單和管理訂單