Skip to main content

Quick Start

Requirements

Requires Python 3.7 and above.

SDK Description

Package Dependency Description

Packages that must be installed regardless of which product's development kit is used.

  • webull-python-sdk-core

Packages that must be installed to use market subscription products.

  • webull-python-sdk-quotes-core

Packages that must be installed when subscribing to products using trade events.

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

Packages that need to be installed by default for the complete use of quotes SDK.

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

Packages that need to be installed by default for the complete use of the trading sdk in Hong Kong.

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

SDK Installation

Install via 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

tip

The Http API address is used for normal Http requests.

The trading alerts is used for real-time pushes such as order status changes.

The push address for the market news is used for receiving the pushes for real-time market news.

Test Environment

HTTP API: hk-openapi.uat.webullbroker.com
Trading news push: hk-openapi-events-api.uat.webullbroker.com
Market news push: hk-openapi-quotes-api.uat.webullbroker.com

Production Environment

HTTP API: api.webull.hk
Trading news push: events-api.webull.hk
Market news push: quotes-api.webull.hk

Requesting API for Testing

The acquisition method of App Key and App Secret in the Test Environment:

First, you need to open an account on the Hong Kong official website in the test environment. After the account opening is completed, you need to apply for the API and contact the Webull Product Manager for review. After passing the review, you can register the app, and generate App Key and App Secret. For detailed steps, please refer to API Application.

Contact Email: webull-api@webull.hk

tip

You can also try the Webull SDK using the App Key and App Secret listed below.

Test Environment HTTP Request List:

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 = "10b6dd1348e0e8e977442c3efcd6fc0b"
your_app_secret = "03ce640a7752eb68bc53f908caf58892"
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()

Test Environment gRPC Connection:

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 = "10b6dd1348e0e8e977442c3efcd6fc0b"
your_app_secret = "03ce640a7752eb68bc53f908caf58892"
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")

Test Environment MQTT Connection:

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 = "10b6dd1348e0e8e977442c3efcd6fc0b"
your_app_secret = "03ce640a7752eb68bc53f908caf58892"
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()

Other Test Accounts

App KeyApp Secret
b6bbdf3dce431f7d309b7be25d32596432b6c5aec9c9f7e965a96dc4d5ec1509
954d4b3b802ba2cda36c6bbe62b1c33c716521e2aea3a256cd5382503e97bf7e
245b4a95a5e13f0dcdc259bad99cb456513fb06c4d41998b18dd50936574e16f
8f2da6d3beb1c1bffdc89620cfa1d38a05805471676bc73879556ecff0e95c0f
10b6dd1348e0e8e977442c3efcd6fc0b03ce640a7752eb68bc53f908caf58892

Feedback and Communication

  1. You can contact us through the Webull API service email address: webull-api@webull.hk

  2. Official WhatsApp group

    qrcode