WebSocket Streams — General Info
Hong Kong stocks real-time data is delivered over WebSocket in two independent parts. Both are one-way push (server → client).
| Part | Credential | Purpose |
|---|---|---|
| Order report push | listenKey | Your own order events |
| Market data streams | wss-token | Price / quote / kline / depth / market phase / tradability, etc. |
listenKeyandwss-tokenare different mechanisms and cannot replace each other.
Base URL
| Environment | Base URL |
|---|---|
| Production | wss://nbstream.binance.com/equity |
Order Report Push
Create / renew a listenKey with POST /sapi/v1/equity-hk/listenKey (TTL 1 hour), then subscribe:
Code
For the event structure and field tables, see the Hong Kong WebSocket order report documentation. Below are only the points that are easy to get wrong and cannot be seen from the field table.
1. The stream name has no @hk suffix
orderReportV3 is one stream shared by all three markets, not Hong Kong-specific. Adding @hk
gives a different stream that Hong Kong messages are never pushed to, with no error.
| Market | ac value |
|---|---|
| US stocks | us_equity |
| US options | us_option |
| Hong Kong | hk_equity |
Always filter by ac. If the same account trades US and Hong Kong stocks, both markets' events
are on this stream with the same field names but different amount denominations (Hong Kong HKD, US
USD); without filtering the numbers get mixed.
2. b is a bare symbol today and will become an asset code
The protocol defines b as an asset code (EQ_HK_00700), but Hong Kong is currently in a degraded
state: the asset-code backfill is not implemented and the actual push is the bare symbol (00700).
On the day it goes live b becomes EQ_HK_00700. Both are valid strings and nothing throws — an
implementation that hardcodes "b is five digits" will silently break on that day.
Treat b as an opaque string. Do not parse its format and do not match it against the symbol
returned by REST (REST always uses the ticker). To correlate, use i (orderId) or ci
(clientOrderId).
3. A missing ol key equals null
ol (odd-lot flag) is a Hong Kong-only key and does not appear in US messages at all. Hong Kong
gives null when it cannot tell. In both cases show no odd-lot label, rather than showing "whole
lot".
4. Push is best-effort, not reliable delivery
A failed push is not retried. Nothing is pushed when:
| Case | Description |
|---|---|
User has no valid listenKey | No WS connected; silently skipped |
| Redelivered terminal event | A terminal state is pushed once and is not re-sent |
| State is neither open nor terminal | Nothing changed for the order, so nothing is pushed |
On reconnect or when returning from background, re-fetch the full list from /order/open-orders;
increments only update rows already in the list. Always reconcile against REST queries.
5. Case and status vocabulary
S (side), o (orderType) and s (status) on the push are all lowercase, and Hong Kong uses the
same vocabulary as US stocks (the broker's raw Hong Kong values are normalized before the push):
| Open states | Terminal states | |
|---|---|---|
hk_equity | pending_new, new, partially_filled, pending_cancel | filled, canceled, rejected, expired |
us_equity / us_option | Same as above, plus US-only values such as accepted | Same as above, plus US-only values such as done_for_day |
Note: REST query endpoints (
/order/detail,/order/history,/order/open-orders,/trade/history) return uppercase (BUY/LIMIT/PARTIALLY_FILLED), unlike the push. If you consume both, compare case-insensitively; do not correlate with plain string equality.
The Hong Kong broker does not report "partially filled" itself: partially_filled is derived from
0 < filled quantity < ordered quantity. To tell whether anything has filled you can also check
fq > 0 directly.
pending_cancel: a cancel submitted in the first half of the lunch break (12:00–12:30) is held by
the broker until 12:30 before it is sent to the exchange. Meanwhile the order is still on the market
and its status shows as "cancelling". When the cancel succeeds the terminal canceled is pushed; if
the cancel is rejected the order returns to its previous status.
Market Data Streams
Market streams (price / quote / kline / 10-level depth / market phase / auction / tradability, etc.) are not pushed by SAPI; they are pushed directly to the stream gateway. SAPI only issues the credential needed to subscribe. The full event structure and stream list are in the Hong Kong market WebSocket documentation.
Login is required
HKEX requires real-time Hong Kong quotes to be viewed by logged-in users. Market data itself is free — this is a login requirement, not a paywall. The stream gateway cannot see the caller's session, so it needs a short-lived JWT, issued by Binance, to attest that the user is logged in.
US price / quote streams do not need this credential and can be subscribed anonymously. The difference comes from HKEX rules, not a phased rollout.
Connection sequence
Code
Do not connect to Hong Kong streams with the stream name in the path
(wss://.../equity/ws/{stream}) — it is rejected at handshake, and the HTTP 400
Stream not allowed for tier is the message of the options path and will mislead you (Hong Kong
credentials have no tier concept). Connect to the base endpoint, then SUBSCRIBE.
Supported actions: SUBSCRIBE, UNSUBSCRIBE, LIST_SUBSCRIPTIONS, SET_PROPERTY, GET_PROPERTY,
AUTHENTICATE, UNAUTHENTICATE.
The token is valid for 1 hour, so calling /wss-token once an hour is enough. Do not fetch a new
one per subscription: one connection authenticates once, after which any number of streams can be
SUBSCRIBEd to without re-authenticating. expiresIn is remaining seconds, not an expiry
timestamp.
listenKey vs wss-token
listenKey | wss-token | |
|---|---|---|
| What it is | A subscription address | A connection-level login state |
| Form | Random UUID | HS256 JWT |
| How it is used | Put into the stream name: {listenKey}@orderReportV3 | Submitted with the AUTHENTICATE verb |
| How the gateway treats it | Not verified; plain string routing | Signature verified |
| What it covers | Order push | Market data subscriptions |
You never "authenticate" with a listenKey; you subscribe to a stream named after it. A listenKey
is a bare UUID with no signature or claims, so there is nothing to verify — sending a UUID to
AUTHENTICATE returns -1122. Order push keeps using listenKey and is unaffected by the token.
Related error codes
| code | msg | Meaning |
|---|---|---|
-1124 | Login required for one or more Hong Kong market data streams | Subscribed to a Hong Kong stream on an unauthenticated connection |
-1125 | — | Authenticated but entity is not CN; L2 depth only; the whole batch is rejected |
-1122 | Invalid or expired auth token | AUTHENTICATE token failed verification or expired |
Streams at a glance
| Stream | Tier | CN entity required |
|---|---|---|
{symbol}@quote@hk | L1 | No |
price@hk | L1 | No |
{symbol}@kline_*@hk | L1 | No |
{symbol}@depth_10@hk | L2 | Yes |
market_phase@hk / tradability@hk | Metadata | No (and no token needed) |
L2 depth is limited by entity
The 10-level depth {symbol}@depth_10@hk is open to CN-entity users only. Both channels are
implemented:
| Channel | Rule | When blocked |
|---|---|---|
WSS @depth_10@hk | Logged in to Hong Kong and token country == "CN" | Not logged in -1124; logged in non-CN -1125 |
| HTTP depth query | Logged in and entity on the whitelist (default CN) | Returns available: false |
The gateway also handles renewal downgrade: when a renewed token changes from CN to non-CN, existing depth pushes are stopped, not only checked on first subscription.
L1 is not affected. quote / price / kline only require login, not a CN entity — a user blocked
by the CN gate can still subscribe to them, so getting -1125 does not mean the credential is
invalid, only that this one stream is unavailable.
The entity on the SAPI side comes from the account service, looked up server-side by userId; no
header is read (for a public API a header is caller-controlled, and reading it would hand the L2
gate to the caller). If the account service cannot be reached it falls back to a non-CN default —
the failure direction is losing L2, not gaining it for free.
About {symbol}@depth_10@hk
The stream carries both full snapshots and incremental updates and is not throttled (unlike
quote, which has a 200 ms per-symbol minimum interval).
The server does not maintain a full order book — the client is responsible for rebuilding the local
book from a snapshot and applying increments by version continuity. On a version gap, re-fetch the
snapshot (GET /sapi/v1/equity-hk/market/depth, whitelist only); do not keep applying increments
across the gap.