資產
Webull的資產API允許開發者通過HTTP獲取資產信息。 詳細內容請參閱 API Reference。
在調用資產 API 前,您需要擁有App Key 與 App Secret。
注意
根據香港的安全與合規要求,除了需透過 App Key 及 App Secret 進行身份驗證外,OpenAPI 還要求使用 Token 進行身份驗證。 有關 Token 的產生與驗證,請參考:Token 產生與驗證
1. 基礎 URL
- 正式環境:
https://api.webull.hk/ - 沙盒環境:
https://api.sandbox.webull.hk
2. 範例
- Python
- Java
from webull.core.client import ApiClient
from webull.trade.trade_client import TradeClient
optional_api_endpoint = "<webull_api_host>" # PRD env host: api.webull.hk. Test env host: api.sanbox.webull.hk
your_app_key = "<your_app_key>"
your_app_secret = "<your_app_secret>"
region_id = "hk"
account_id = "<your_account_id>" # Use account_list interface to get account info
api_client = ApiClient(your_app_key, your_app_secret, region_id)
api_client.add_endpoint(region_id, optional_api_endpoint)
if __name__ == '__main__':
trade_client = TradeClient(api_client)
res = trade_client.account_v2.get_account_balance(account_id)
if res.status_code == 200:
print('get account balance info:', res.json())
res = trade_client.account_v2.get_account_position(account_id)
if res.status_code == 200:
print('get account positions info:', res.json())
import com.webull.openapi.core.http.HttpApiConfig;
import com.webull.openapi.core.logger.Logger;
import com.webull.openapi.core.logger.LoggerFactory;
import com.webull.openapi.samples.account.AccountList;
import com.webull.openapi.samples.config.Env;
import com.webull.openapi.trade.response.v2.AccountBalanceInfo;
import com.webull.openapi.trade.response.v2.AccountPositionsInfo;
import java.util.List;
public class AssetsClient {
private static final Logger logger = LoggerFactory.getLogger(AssetsClient.class);
public static void main(String[] args) throws InterruptedException {
HttpApiConfig apiConfig = HttpApiConfig.builder()
.appKey("<your_app_key>") //<your_app_key>
.appSecret("<your_app_secret>") //<your_app_secret>
.regionId("hk") //<your_region_id> @see com.webull.openapi.core.common.Region
.endpoint("<webull_api_host>") //PRD env host: api.webull.hk. Test env host: api.sanbox.webull.hk
.build();
com.webull.openapi.trade.TradeClientV2 apiService = new com.webull.openapi.trade.TradeClientV2(apiConfig);
// Use getAccountList interface to get account info
String accountId = "#{accountId}";
// get account balance information
AccountBalanceInfo balanceInfo = apiService.balanceAccount(accountId);
logger.info("BalanceInfo: {}", balanceInfo);
List<AccountPositionsInfo> positionsInfos = apiService.positionsAccount(accountId);
logger.info("PositionsInfos: {}", positionsInfos);
}
}