Subscribe Trade Events
Interface Description
Trade events subscription is a persistent connection on which the server pushes trade events in real time. It is suitable for connecting Webull customers through the OpenAPI development platform. Two independent channels are available. Both deliver the same events with the same payload, choose one of them:
| Channel | Transport | Data format | Client dependency |
|---|---|---|---|
| gRPC Channel | gRPC server streaming over HTTP/2 | Protobuf | gRPC and Protobuf libraries |
| SSE Channel | HTTP/2 POST, response is text/event-stream (Server-Sent Events) | JSON | Any HTTP client that supports HTTP/2 |
Currently, the interface supports order status change message push, and the supported scenarios are as follows:
| scene_type | Description |
|---|---|
| FILLED | Partially filled |
| FINAL_FILLED | All filled |
| PLACE_FAILED | Order failed |
| MODIFY_SUCCESS | Change order successfully |
| MODIFY_FAILED | Change order failed |
| CANCEL_SUCCESS | Cancellation succeeded |
| CANCEL_FAILED | Cancellation failed |
Common Rules
One App Key can hold only one active subscription at a time, across gRPC and SSE. While a subscription is active, a new subscribe request of the same App Key is rejected and the active one is not affected. Close the existing subscription before switching channels.
gRPC
Trade events subscription is a server streaming persistent connection implemented based on gRPC, which is suitable for connecting Webull customers through the OpenAPI development platform. The trade events subscription fully follows the gRPC open source protocol, and you can refer to the gRPC open source library when using it.
Trade events subscribe Proto protocol definition.
Request Proto
message SubscribeRequest {
uint32 subscribeType = 1; // Subscription type
int64 timestamp = 2; // Timestamp
string contentType = 3; // Content type
string payload = 4; // Content
repeated string accounts = 5; // Account ID
}
Response Proto
message SubscribeResponse {
EventType eventType = 1; // Event type
uint32 subscribeType = 2; // Subscription type
string contentType = 3; // Subscription type
string payload = 4; // Content
string requestId = 5; // Request id
int64 timestamp = 6; // Timestamp
}
EventType enumeration
enum EventType {
SubscribeSuccess = 0; // Subscription succeeded
Ping = 1; // Heartbeat information
AuthError = 2; // Authentication error
NumOfConnExceed = 3; // Connection limit exceeded
SubscribeExpired = 4; // Subscription expired
}
Request Example
- Python
- Java
When using sdk request, subscribeType, timestamp, contentType, and payload can be ignored. Just pass in the accounts. subscribeType currently only supports =1. In the following case, the _on_log method is used to output the log. The my_on_events_message method is to receive order status change messages.
import logging
from webull.trade.events.types import ORDER_STATUS_CHANGED, EVENT_TYPE_ORDER
from webull.trade.trade_events_client import TradeEventsClient
your_app_key = "<your_app_key>"
your_app_secret = "<your_app_secret>"
account_id = "<your_account_id>"
region_id = "sg"
# PRD env host: events-api.webull.com.sg
# Test env host: sg-events-api.uat.webullbroker.com
optional_api_endpoint = "<event_api_endpoint>"
def _on_log(level, log_content):
print(logging.getLevelName(level), log_content)
def my_on_events_message(event_type, subscribe_type, payload, raw_message):
if EVENT_TYPE_ORDER == event_type and ORDER_STATUS_CHANGED == subscribe_type:
print('%s' % payload)
if __name__ == '__main__':
# Create EventsClient instance
trade_events_client = TradeEventsClient(your_app_key, your_app_secret, region_id)
# For non production environment, you need to set the domain name of the subscription service through eventsclient. For example, the domain name of the UAT environment is set here
# trade_events_client = TradeEventsClient(your_app_key, your_app_secret, region_id, host=optional_api_endpoint)
trade_events_client.on_log = _on_log
# Set the callback function when the event data is received.
# The data of order status change is printed here
trade_events_client.on_events_message = my_on_events_message
# Set the account ID to be subscribed and initiate the subscription. This method is synchronous
trade_events_client.do_subscribe([account_id])
The handleEventMessage method is to receive order status change messages.
import com.google.gson.reflect.TypeToken;
import com.webull.openapi.core.execption.ClientException;
import com.webull.openapi.core.execption.ServerException;
import com.webull.openapi.core.logger.Logger;
import com.webull.openapi.core.logger.LoggerFactory;
import com.webull.openapi.core.serialize.JsonSerializer;
import com.webull.openapi.samples.config.Env;
import com.webull.openapi.trade.events.subscribe.ISubscription;
import com.webull.openapi.trade.events.subscribe.ITradeEventClient;
import com.webull.openapi.trade.events.subscribe.message.EventType;
import com.webull.openapi.trade.events.subscribe.message.SubscribeRequest;
import com.webull.openapi.trade.events.subscribe.message.SubscribeResponse;
import java.util.Map;
public class TradeEventsClient {
private static final Logger logger = LoggerFactory.getLogger(TradeEventsClient.class);
public static void main(String[] args) {
try (ITradeEventClient client = ITradeEventClient.builder()
.appKey(Env.APP_KEY)
.appSecret(Env.APP_SECRET)
.regionId(Env.REGION_ID)
// .host("<event_api_endpoint>")
.onMessage(TradeEventsClient::handleEventMessage)
.build()) {
SubscribeRequest request = new SubscribeRequest("<your_account_id>");
ISubscription subscription = client.subscribe(request);
subscription.blockingAwait();
} catch (ClientException ex) {
logger.error("Client error", ex);
} catch (ServerException ex) {
logger.error("Sever error", ex);
} catch (Exception ex) {
logger.error("Unknown error", ex);
}
}
private static void handleEventMessage(SubscribeResponse response) {
if (SubscribeResponse.CONTENT_TYPE_JSON.equals(response.getContentType())) {
Map<String, String> payload = JsonSerializer.fromJson(response.getPayload(),
new TypeToken<Map<String, String>>(){}.getType());
if (EventType.Order.getCode() == response.getEventType() || EventType.Position.getCode() == response.getEventType()) {
logger.info("{}", payload);
}
}
}
}
Response Example
Transaction event scene type
- FILLED
- FINAL_FILLED
- PLACE_FAILED
- MODIFY_SUCCESS
- CANCEL_SUCCESS
{
"request_id": "1045473299175309312",
"account_id": "1245105122951680000",
"client_order_id": "5783758dc6c240c6811c0cbea60c72d8",
"instrument_id": "913256135",
"order_status": "SUBMITTED",
"symbol": "AAPL",
"qty": "10.00",
"filled_price": "180.00",
"filled_qty": "1.00",
"filled_time": "2025-11-21T06:23:28.601+0000",
"side": "BUY",
"scene_type": "FILLED",
"category": "US_STOCK",
"order_type": "LIMIT"
}
DEBUG response:eventType: Ping
subscribeType: 1
contentType: "text/plain"
requestId: "486daa2d-7be8-438f-b7fa-ecafa3d0e89f"
timestamp: 1763706218682
{
"request_id": "1045474398137483264",
"account_id": "1245105122951680000",
"client_order_id": "db74f19918054a7e9bb72067731c9ae4",
"instrument_id": "913256135",
"order_status": "FILLED",
"symbol": "AAPL",
"qty": "10.00",
"filled_price": "180.00",
"filled_qty": "10.00",
"filled_time": "2025-11-21T06:27:43.312+0000",
"side": "BUY",
"scene_type": "FINAL_FILLED",
"category": "US_STOCK",
"order_type": "LIMIT"
}
DEBUG response:eventType: Ping
subscribeType: 1
contentType: "text/plain"
requestId: "486daa2d-7be8-438f-b7fa-ecafa3d0e89f"
timestamp: 1763706478682
{
"request_id": "1045474643156140032",
"account_id": "1245105122951680000",
"client_order_id": "de2868b71c154bcaafd2baca61127966",
"instrument_id": "913256135",
"order_status": "FAILED",
"symbol": "AAPL",
"qty": "10.00",
"filled_qty": "0.000",
"side": "BUY",
"scene_type": "PLACE_FAILED",
"category": "US_STOCK",
"order_type": "LIMIT"
}
DEBUG response:eventType: Ping
subscribeType: 1
contentType: "text/plain"
requestId: "486daa2d-7be8-438f-b7fa-ecafa3d0e89f"
timestamp: 1763706538682
{
"request_id": "1045475396583161856",
"account_id": "1245105122951680000",
"client_order_id": "92ba046cd87f43c3a93e798877ae1bb8",
"instrument_id": "913256135",
"order_status": "SUBMITTED",
"symbol": "AAPL",
"qty": "10.00",
"filled_qty": "0.000",
"side": "BUY",
"scene_type": "MODIFY_SUCCESS",
"category": "US_STOCK",
"order_type": "LIMIT"
}
DEBUG response:eventType: Ping
subscribeType: 1
contentType: "text/plain"
requestId: "486daa2d-7be8-438f-b7fa-ecafa3d0e89f"
timestamp: 1763706758682
{
"request_id": "1045475396583161856",
"account_id": "1245105122951680000",
"client_order_id": "92ba046cd87f43c3a93e798877ae1bb8",
"instrument_id": "913256135",
"order_status": "CANCELLED",
"symbol": "AAPL",
"qty": "10.00",
"filled_qty": "0.000",
"side": "BUY",
"scene_type": "CANCEL_SUCCESS",
"category": "US_STOCK",
"order_type": "LIMIT"
}
DEBUG response:eventType: Ping
subscribeType: 1
contentType: "text/plain"
requestId: "486daa2d-7be8-438f-b7fa-ecafa3d0e89f"
timestamp: 1763706758682
SSE
The SSE channel delivers the same events as the gRPC channel over a standard HTTP long connection. The client sends one POST request, and the server keeps the response open as a text/event-stream. No gRPC or Protobuf library is required.
Request
POST https://<event_api_endpoint>/subscribe/sse
| Environment | Host |
|---|---|
| Production | events-api.webull.com.sg |
| Test | sg-events-api.uat.webullbroker.com |
Headers
The request is signed the same way as the OpenAPI HTTP APIs (x-app-key, x-request-id, x-timestamp, x-signature, x-signature-algorithm, x-signature-version, x-signature-nonce). The body digest of the signature is computed over the exact JSON bytes sent. In addition:
| Header | Value |
|---|---|
Content-Type | application/json |
Accept | text/event-stream (required, otherwise 400) |
Body
JSON, at most 1 MB.
| Field | Type | Required | Description |
|---|---|---|---|
subscribeType | integer | Yes | Event types to subscribe, 1 for order events. The SDK sends 7 by default, which also covers other event types, filter on eventType when consuming. |
timestamp | integer | Yes | Request time, Unix epoch in milliseconds. |
accounts | string array | Yes | Account IDs to subscribe, must not be empty. |
{"subscribeType":7,"timestamp":1795160102884,"accounts":["<your_account_id>"]}
Response
On success the server answers HTTP 200 and keeps writing frames. Each frame has an empty id: line, a data: line and an event: line, and frames are separated by a blank line. data is a JSON object with the fields below.
| Field | Type | Description |
|---|---|---|
eventType | integer | Business event type, only present on event frames. 1024 is an order event. |
subscribeType | integer | On subscribeSuccess, the subscribed bit mask (e.g. 7). On event frames, the type of this event, 1 for order events. |
contentType | string | text/plain or application/json. |
payload | string | Frame content. For application/json it is a JSON string, decode it a second time to get the event object. |
requestId | string | Request ID. |
timestamp | integer | Server time, Unix epoch in milliseconds. |
Stream example
id:
data: {"subscribeType":7,"contentType":"text/plain","payload":"3097531199108","requestId":"486daa2d-7be8-438f-b7fa-ecafa3d0e89f","timestamp":1763706208000}
event: subscribeSuccess
: heartbeat
id:
data: {"eventType":1024,"subscribeType":1,"contentType":"application/json","payload":"{\"request_id\":\"1045473299175309312\",\"account_id\":\"1245105122951680000\",\"client_order_id\":\"5783758dc6c240c6811c0cbea60c72d8\",\"instrument_id\":\"913256135\",\"order_status\":\"SUBMITTED\",\"symbol\":\"AAPL\",\"qty\":\"10.00\",\"filled_price\":\"180.00\",\"filled_qty\":\"1.00\",\"filled_time\":\"2025-11-21T06:23:28.601+0000\",\"side\":\"BUY\",\"scene_type\":\"FILLED\",\"category\":\"US_STOCK\",\"order_type\":\"LIMIT\"}","requestId":"486daa2d-7be8-438f-b7fa-ecafa3d0e89f","timestamp":1763706208601}
event: event
The payload of the event frame above, decoded:
{
"request_id": "1045473299175309312",
"account_id": "1245105122951680000",
"client_order_id": "5783758dc6c240c6811c0cbea60c72d8",
"instrument_id": "913256135",
"order_status": "SUBMITTED",
"symbol": "AAPL",
"qty": "10.00",
"filled_price": "180.00",
"filled_qty": "1.00",
"filled_time": "2025-11-21T06:23:28.601+0000",
"side": "BUY",
"scene_type": "FILLED",
"category": "US_STOCK",
"order_type": "LIMIT"
}
Request Example
- Python
- Java
import logging
from webull.trade.events.types import ORDER_STATUS_CHANGED, EVENT_TYPE_ORDER
from webull.trade.trade_events_sse_client import TradeEventsSseClient
your_app_key = "<your_app_key>"
your_app_secret = "<your_app_secret>"
account_id = "<your_account_id>"
region_id = "sg"
# PRD env host: events-api.webull.com.sg
# Test env host: sg-events-api.uat.webullbroker.com
optional_api_endpoint = "<event_api_endpoint>"
def _on_log(level, log_content):
print(logging.getLevelName(level), log_content)
def my_on_connect(client, payload, response):
print('subscribed, duration:%s ms' % payload)
def my_on_events_message(event_type, subscribe_type, payload, raw_message):
if EVENT_TYPE_ORDER == event_type and ORDER_STATUS_CHANGED == subscribe_type:
print('----request_id:%s----' % payload['request_id'])
print(payload)
def my_on_fatal_error(client, response):
print('subscription stopped, event:%s, reason:%s' % (response.event, response.payload))
# Return True to keep reconnecting, e.g. while the subscription is being renewed.
return False
if __name__ == '__main__':
# Create SSE EventsClient instance
trade_events_client = TradeEventsSseClient(your_app_key, your_app_secret, region_id)
# For non production environment, you need to set the domain name of the subscription service through eventsclient. For example, the domain name of the UAT environment is set here
# trade_events_client = TradeEventsSseClient(your_app_key, your_app_secret, region_id, host=optional_api_endpoint)
trade_events_client.on_log = _on_log
trade_events_client.on_connect = my_on_connect
trade_events_client.on_events_message = my_on_events_message
trade_events_client.on_fatal_error = my_on_fatal_error
# One App Key can hold only one active subscription across gRPC and SSE.
# Close the gRPC subscription first, otherwise the request is rejected with HTTP 429 and retried.
# This method is synchronous.
trade_events_client.do_subscribe([account_id])
import com.google.gson.reflect.TypeToken;
import com.webull.openapi.core.exception.ClientException;
import com.webull.openapi.core.exception.ServerException;
import com.webull.openapi.core.logger.Logger;
import com.webull.openapi.core.logger.LoggerFactory;
import com.webull.openapi.core.serialize.JsonSerializer;
import com.webull.openapi.core.sse.ISseClient;
import com.webull.openapi.core.sse.ISseSubscription;
import com.webull.openapi.core.sse.message.SseSubscribeRequest;
import com.webull.openapi.core.sse.message.SseSubscribeResponse;
import com.webull.openapi.samples.config.Env;
import com.webull.openapi.trade.TradeEventSseClient;
import com.webull.openapi.trade.events.subscribe.message.EventType;
import java.util.Map;
public class TradeEventsSseClient {
private static final Logger logger = LoggerFactory.getLogger(TradeEventsSseClient.class);
public static void main(String[] args) {
try (ISseClient client = TradeEventSseClient.builder()
.appKey(Env.APP_KEY)
.appSecret(Env.APP_SECRET)
.regionId(Env.REGION_ID)
// .host("<event_api_endpoint>")
.onMessage(TradeEventsSseClient::handleEventMessage)
.build()) {
SseSubscribeRequest request = new SseSubscribeRequest("<your_account_id>");
ISseSubscription subscription = client.subscribe(request);
subscription.blockingAwait();
} catch (ClientException ex) {
logger.error("Client error", ex);
} catch (ServerException ex) {
logger.error("Server error", ex);
} catch (Exception ex) {
logger.error("Unknown error", ex);
}
}
private static void handleEventMessage(SseSubscribeResponse response) {
if (SseSubscribeResponse.CONTENT_TYPE_JSON.equals(response.getContentType())) {
Map<String, Object> payload = JsonSerializer.fromJson(response.getPayload(),
new TypeToken<Map<String, Object>>(){}.getType());
if (EventType.Order.getCode() == response.getEventType()) {
logger.info("{}", payload);
}
}
}
}
Response Example
Transaction event scene type
- FILLED
- FINAL_FILLED
- PLACE_FAILED
- MODIFY_SUCCESS
- CANCEL_SUCCESS
{
"request_id": "1045473299175309312",
"account_id": "1245105122951680000",
"client_order_id": "5783758dc6c240c6811c0cbea60c72d8",
"instrument_id": "913256135",
"order_status": "SUBMITTED",
"symbol": "AAPL",
"qty": "10.00",
"filled_price": "180.00",
"filled_qty": "1.00",
"filled_time": "2025-11-21T06:23:28.601+0000",
"side": "BUY",
"scene_type": "FILLED",
"category": "US_STOCK",
"order_type": "LIMIT"
}
subscribeType: 1
contentType: "application/json"
requestId: "486daa2d-7be8-438f-b7fa-ecafa3d0e89f"
{
"request_id": "1045474398137483264",
"account_id": "1245105122951680000",
"client_order_id": "db74f19918054a7e9bb72067731c9ae4",
"instrument_id": "913256135",
"order_status": "FILLED",
"symbol": "AAPL",
"qty": "10.00",
"filled_price": "180.00",
"filled_qty": "10.00",
"filled_time": "2025-11-21T06:27:43.312+0000",
"side": "BUY",
"scene_type": "FINAL_FILLED",
"category": "US_STOCK",
"order_type": "LIMIT"
}
subscribeType: 1
contentType: "application/json"
requestId: "486daa2d-7be8-438f-b7fa-ecafa3d0e89f"
{
"request_id": "1045474643156140032",
"account_id": "1245105122951680000",
"client_order_id": "de2868b71c154bcaafd2baca61127966",
"instrument_id": "913256135",
"order_status": "FAILED",
"symbol": "AAPL",
"qty": "10.00",
"filled_qty": "0.000",
"side": "BUY",
"scene_type": "PLACE_FAILED",
"category": "US_STOCK",
"order_type": "LIMIT"
}
subscribeType: 1
contentType: "application/json"
requestId: "486daa2d-7be8-438f-b7fa-ecafa3d0e89f"
{
"request_id": "1045475396583161856",
"account_id": "1245105122951680000",
"client_order_id": "92ba046cd87f43c3a93e798877ae1bb8",
"instrument_id": "913256135",
"order_status": "SUBMITTED",
"symbol": "AAPL",
"qty": "10.00",
"filled_qty": "0.000",
"side": "BUY",
"scene_type": "MODIFY_SUCCESS",
"category": "US_STOCK",
"order_type": "LIMIT"
}
subscribeType: 1
contentType: "application/json"
requestId: "486daa2d-7be8-438f-b7fa-ecafa3d0e89f"
{
"request_id": "1045475396583161856",
"account_id": "1245105122951680000",
"client_order_id": "92ba046cd87f43c3a93e798877ae1bb8",
"instrument_id": "913256135",
"order_status": "CANCELLED",
"symbol": "AAPL",
"qty": "10.00",
"filled_qty": "0.000",
"side": "BUY",
"scene_type": "CANCEL_SUCCESS",
"category": "US_STOCK",
"order_type": "LIMIT"
}
subscribeType: 1
contentType: "application/json"
requestId: "486daa2d-7be8-438f-b7fa-ecafa3d0e89f"