帳戶
帳戶 API 讓您獲取帳戶列表、查詢餘額和檢查當前持倉。這些通常是下單前的第一步操作。
可用端點
| 端點 | 說明 |
|---|---|
| 帳戶列表 | 獲取您憑證下的所有帳戶 |
| 帳戶餘額 | 查詢特定帳戶的餘額、購買力和現金詳情 |
| 帳戶持倉 | 獲取特定帳戶的當前持倉和倉位資訊 |
典型工作流程
- 呼叫帳戶列表獲取您的
account_id - 使用
account_id查詢餘額或持倉 - 根據餘額和持倉決定交易策略
提示
帳戶列表回應包含與您憑證關聯的所有帳戶。股票和期權帳戶可能有不同的 Account ID。
程式碼範例
獲取帳戶列表
- Python
- Java
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']}")
import com.webull.openapi.core.http.HttpApiConfig;
import com.webull.openapi.trade.TradeClient;
HttpApiConfig config = HttpApiConfig.builder()
.appKey("<your_app_key>")
.appSecret("<your_app_secret>")
.regionId("hk")
.endpoint("<api_endpoint>")
.build();
TradeClient client = new TradeClient(config);
var accounts = client.getAccountList();
System.out.println("Accounts: " + accounts);
查詢帳戶餘額
- Python
- Java
account_id = "<your_account_id>"
res = trade_client.get_account_balance(account_id=account_id)
if res.status_code == 200:
print("Balance:", res.json())
String accountId = "<your_account_id>";
var balance = client.getAccountBalance(accountId);
System.out.println("Balance: " + balance);
查詢帳戶持倉
- Python
- Java
res = trade_client.get_account_positions(account_id=account_id)
if res.status_code == 200:
print("Positions:", res.json())
var positions = client.getAccountPositions(accountId);
System.out.println("Positions: " + positions);
下一步
- 訂單 — 使用 Account ID 下單和管理訂單