跳至主要内容

快速開始

要求

需要安裝Python 3.7或以上版本。

SDK 說明

包依賴說明

無論使用哪個產品的開發工具包,必須安裝的包

  • webull-python-sdk-core

使用行情訂閱產品,必須安裝的包

  • webull-python-sdk-quotes-core

使用交易事件檢閱產品,必須安裝的包

  • webull-python-sdk-trade-events-core

對行情sdk的完整使用,默認需要安裝的包

  • webull-python-sdk-core
  • webull-python-sdk-quotes-core
  • webull-python-sdk-mdata

對香港交易sdk的完整使用,默認需要安裝的包

  • webull-python-sdk-core
  • webull-python-sdk-trade-events-core
  • webull-python-sdk-trade

SDK 安裝

通過pip方式安裝

pip3 install --upgrade webull-python-sdk-core
pip3 install --upgrade webull-python-sdk-quotes-core
pip3 install --upgrade webull-python-sdk-mdata
pip3 install --upgrade webull-python-sdk-trade-events-core
pip3 install --upgrade webull-python-sdk-trade

API Host

提示

Http API地址用於普通Http請求。

交易消息推送地址用於訂單狀態變化等實時消息推送。

行情消息推送地址用於實時行情消息推送。

測試環境

HTTP API: hk-openapi.uat.webullbroker.com
交易消息推送: hk-openapi-events-api.uat.webullbroker.com
行情消息推送: hk-openapi-quotes-api.uat.webullbroker.com

生產環境

HTTP API: api.webull.hk
交易消息推送: events-api.webull.hk
行情消息推送: quotes-api.webull.hk

調用測試API

測試環境 App Key 和 App Secret獲取方式:

首先需要在測試環境的香港官網開戶,開戶完成後,需要申請API,並聯繫Webull產品經理審核。審核通過後註冊應用,並生成App Key, App Secret。 詳細步驟參考API申請

聯繫郵箱:webull-api@webull.hk

提示

也可以使用以下示列中的App Key和App Secret來嘗試使用Webull SDK。

測試環境 HTTP請求示列:

import uuid

from webullsdkcore.client import ApiClient
from webullsdktrade.api import API
from webullsdkcore.common.region import Region

optional_api_endpoint = "hk-openapi.uat.webullbroker.com"
your_app_key = "8adaccd222bced60420814f0c0585bdd"
your_app_secret = "45c597c1e21af91829b3959ebeac57dc"
api_client = ApiClient(your_app_key, your_app_secret, Region.HK.value)
api_client.add_endpoint(Region.HK.value, optional_api_endpoint)


class TestOrder(object):
def __init__(self):
self.api = API(api_client)

def order(self):
res = self.api.account.get_app_subscriptions()
account_id = None
if res.status_code == 200:
print('app subscriptions:', res.json())
result = res.json()
account_id = result[0]['account_id']
print("account id:", account_id)

if account_id is None:
print("account id is null")
return

client_order_id = uuid.uuid4().hex
print('client order id:', client_order_id)
stock_order = {
"account_id": account_id,
"stock_order": {
"client_order_id": client_order_id,
"instrument_id": "913256409",
"side": "BUY",
"tif": "DAY",
"order_type": "AT_AUCTION",
# "limit_price": "385.000",
"qty": "1",
"extended_hours_trading": False
}
}
res = self.api.order.place_order(stock_order['account_id'], **stock_order['stock_order'])
if res.status_code == 200:
print('place order res:', res.json())


if __name__ == '__main__':
openapi = TestOrder()
openapi.order()

測試環境gRPC連接:

import logging

from webullsdkcore.client import ApiClient
from webullsdktradeeventscore.events_client import EventsClient
from webullsdktrade.api import API
from webullsdkcore.common.region import Region

optional_api_endpoint = "hk-openapi.uat.webullbroker.com"
your_app_key = "8adaccd222bced60420814f0c0585bdd"
your_app_secret = "45c597c1e21af91829b3959ebeac57dc"
api_client = ApiClient(your_app_key, your_app_secret, Region.HK.value)
api_client.add_endpoint(Region.HK.value, optional_api_endpoint)
PRE_HOST = "hk-openapi-events-api.uat.webullbroker.com"


def _on_log(level, log_content):
print(logging.getLevelName(level), log_content)


if __name__ == '__main__':
api = API(api_client)
res = api.account.get_app_subscriptions()
account_id = None
if res.status_code == 200:
print('app subscriptions:', res.json())
result = res.json()
account_id = result[0]['account_id']
print("account id:", account_id)
if account_id:
client = EventsClient(your_app_key, your_app_secret, host=PRE_HOST)
client.on_log = _on_log
print("subscribe account", [account_id])
client.do_subscribe([account_id])
else:
print("account id is null")

測試環境MQTT連接:

from webullsdkmdata.common.category import Category
from webullsdkmdata.common.subscribe_type import SubscribeType
from webullsdkmdata.quotes.subscribe.default_client import DefaultQuotesClient
from webullsdkcore.common.region import Region

your_app_key = "8adaccd222bced60420814f0c0585bdd"
your_app_secret = "45c597c1e21af91829b3959ebeac57dc"
optional_quotes_endpoint = "hk-openapi-quotes-api.uat.webullbroker.com"

def pt_logs(client, userdata, level, buf):
print("userdata:%s, level:%s, buf:%s" % (userdata, level, buf))


def on_message(client, userdata, message):
print("Received message '" + str(message.payload) + "' on topic '"
+ message.topic + "' with QoS " + str(message.qos))


if __name__ == '__main__':
client = DefaultQuotesClient(your_app_key, your_app_secret, Region.HK.value, optional_quotes_endpoint)
client.init_default_settings('00700', Category.HK_STOCK.name, SubscribeType.SNAPSHOT.name)
client.on_log = pt_logs
client.on_message = on_message
client.connect_and_loop_forever()

其他測試賬號

App KeyApp Secret
045dd49a719bc5a657e4ecd76a9d83606bfc5fac8e5a7ec51c1dfb0454847cf9
b77c552aaae16b1b77fcdd5eda7020cf6eca68d856df3278065f09cb2ec3f7be
37c7f5233086dc9cc5e50eecf267fdd32f44f072ea491747a67604ac7986efb8
f7f8f01b36cd62ffd88e49b33b078b0d25109c4bc6c117c4a085749d8aaa8642
8adaccd222bced60420814f0c0585bdd45c597c1e21af91829b3959ebeac57dc

反饋與溝通

  1. 可通過Webull API服務郵箱聯繫到我們工作人員,郵箱地址是:webull-api@webull.hk

  2. 官方WhatsApp群

    qrcode