跳到主要内容

快速开始

要求

需要安装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: api.webull.com
交易消息推送: events-api.webull.com
行情消息推送: usquotes-api.webullfintech.com

调用示列

注意

以下接口示列,默认连接地址为生产环境。

Http接口示列

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

your_app_key = "<your_app_key>"
your_app_secret = "<your_app_secret>"
api_client = ApiClient(your_app_key, your_app_secret, Region.US.value)
api = API(api_client)
if __name__ == '__main__':
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 is None:
print("account id is null")

交易消息推送示列

import logging

from webullsdktradeeventscore.events_client import EventsClient
from webullsdkcore.common.region import Region

your_app_key = "<your_app_key>"
your_app_secret = "<your_app_secret>"
account_id = "<your_account_id>"


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


if __name__ == '__main__':
client = EventsClient(your_app_key, your_app_secret, Region.US.value)
client.on_log = _on_log
print("subscribe account", [account_id])
client.do_subscribe([account_id])

行情消息推送示列

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 = "<your_app_key>"
your_app_secret = "<your_app_secret>"


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.US.value)
client.init_default_settings('AAPL', Category.US_STOCK.name, SubscribeType.SNAPSHOT.name)
client.on_log = pt_logs
client.on_message = on_message
client.connect_and_loop_forever()

反馈与沟通

可通过Webull API服务邮箱联系到我们工作人员,邮箱地址是:api@webull-us.com