跳至主要内容

訂單

Webull 提供訂單 API,讓開發者能透過 HTTP 協議執行訂單與查詢。更多細節請參考 訂單介面

在調用訂單 API 前,您需要擁有 App KeyApp Secret

  • 個人用戶請參考 這裡
  • 機構用戶請參考 這裡
注意

根據香港的安全與合規要求,除了需透過 App Key 及 App Secret 進行身份驗證外,OpenAPI 還要求使用 Token 進行身份驗證。 有關 Token 的產生與驗證,請參考:Token 產生與驗證

1. 支援市場

交易 API 支援下列市場:

市場產品類型
美國美國股票產品(股票、期權——不含指數期權)
香港香港股票產品(包括股票、ETF)
中國大陸滬深港通股票

2. 基礎 URL

  • 正式環境: https://api.webull.hk/
  • 沙盒環境: https://api.sandbox.webull.hk

3. 範例

3.1 股票訂單

import uuid
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)


# simple order
client_order_id = uuid.uuid4().hex
print('client order id:', client_order_id)
new_simple_orders = [
{
"client_order_id": client_order_id,
"symbol": "BULL",
"instrument_type": "EQUITY",
"market": "US",
"order_type": "LIMIT",
"limit_price": "26",
"quantity": "1",
"support_trading_session": "CORE",
"side": "BUY",
"time_in_force": "DAY",
"entrust_type": "QTY"
}
]

# For hk stock place params
new_hk_stock_simple_orders = [
{
"client_order_id": client_order_id,
"symbol": "00700",
"instrument_type": "EQUITY",
"market": "HK",
"order_type": "ENHANCED_LIMIT",
"limit_price": "612",
"quantity": "100",
"side": "BUY",
"time_in_force": "DAY",
"entrust_type": "QTY"
}
]

res = trade_client.order_v2.preview_order(account_id, new_simple_orders)
if res.status_code == 200:
print('preview order res:', res.json())

res = trade_client.order_v2.place_order(account_id, new_simple_orders)
if res.status_code == 200:
print('place order res:', res.json())

modify_simple_orders = [
{
"client_order_id": client_order_id,
"quantity": "2",
"limit_price": "25"
}
]
res = trade_client.order_v2.replace_order(account_id, modify_simple_orders)
if res.status_code == 200:
print('replace order res:', res.json())

res = trade_client.order_v2.cancel_order(account_id, client_order_id)
if res.status_code == 200:
print('cancel order res:', res.json())

res = trade_client.order_v2.get_order_detail(account_id, client_order_id)
if res.status_code == 200:
print('order detail:', res.json())

3.2 期權訂單

import uuid
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)

# Options
# For option order inquiries, please use the V2 query interface: api.order_v2.get_order_detail(account_id, client_order_id).
client_order_id = uuid.uuid4().hex
option_new_orders = [
{
"client_order_id": client_order_id,
"combo_type": "NORMAL",
"order_type": "LIMIT",
"quantity": "1",
"limit_price": "21.25",
"option_strategy": "SINGLE",
"side": "BUY",
"time_in_force": "GTC",
"entrust_type": "QTY",
"legs": [
{
"side": "BUY",
"quantity": "1",
"symbol": "TSLA",
"strike_price": "400",
"option_expire_date": "2025-11-26",
"instrument_type": "OPTION",
"option_type": "CALL",
"market": "US"
}
]
}
]

# preview
res = trade_client.order_v2.preview_option(account_id, option_new_orders)
if res.status_code == 200:
print("preview option res:", res.json())

# place
res = trade_client.order_v2.place_option(account_id, option_new_orders)
if res.status_code == 200:
print("place option res:" , res.json())

option_modify_orders = [
{
"client_order_id": client_order_id,
"quantity": "2",
"limit_price": "21.25"
}
]
res = trade_client.order_v2.replace_option(account_id, option_modify_orders)
if res.status_code == 200:
print("Replace option order res:" , res.json())

res = trade_client.order_v2.cancel_option(account_id, client_order_id)
if res.status_code == 200:
print("Replace option order res:" , res.json())

res = trade_client.order_v2.get_order_detail(account_id, client_order_id)
if res.status_code == 200:
print("Option order detail order res:" , res.json())