User data streams are private WebSocket connections that deliver real-time account-level events: order fills and updates, balance changes, position adjustments, and margin calls. Unlike public market data streams, they require authentication and are specific to your account. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/binance/llms.txt
Use this file to discover all available pages before exploring further.
WebsocketClient exposes a dedicated subscribe method for each product group, and once connected the SDK handles everything else — listenKey creation, periodic refresh, reconnection, and re-subscription.
Available Stream Methods
Each method opens a dedicated WebSocket connection for the corresponding product group’s user data feed.| Method | Product | Events delivered |
|---|---|---|
subscribeSpotUserDataStream() | Spot (deprecated for new integrations — prefer WebsocketAPIClient.subscribeUserDataStream()) | Account position updates, order execution reports, balance updates |
subscribeCrossMarginUserDataStream() | Cross Margin | Margin account updates, order fills, balance deltas |
subscribeIsolatedMarginUserDataStream(symbol) | Isolated Margin | Per-symbol isolated margin account and order events |
subscribeMarginRiskUserDataStream() | Margin Risk | Margin risk data events (liquidation warnings, risk notifications) |
subscribeUsdFuturesUserDataStream() | USD-M Futures | Position changes, order updates, account balance updates, margin calls |
subscribeCoinFuturesUserDataStream() | COIN-M Futures | Position changes, order updates, account balance updates |
subscribePortfolioMarginUserDataStream() | Portfolio Margin | Portfolio margin account events |
unsubscribe* methods (unsubscribeSpotUserDataStream(), unsubscribeCrossMarginUserDataStream(), unsubscribeIsolatedMarginUserDataStream(symbol), unsubscribeMarginRiskUserDataStream(), unsubscribeUsdFuturesUserDataStream(), unsubscribeCoinFuturesUserDataStream(), unsubscribePortfolioMarginUserDataStream()) cleanly close the dedicated connection and stop the listenKey keepalive cycle.
listenKey Lifecycle
Internally, most user data streams are initiated using a listenKey — a session token that Binance issues via REST and that must be kept alive with periodic pings. The SDK manages this automatically:Fetch listenKey
On the first call to a subscribe method, the SDK uses the embedded REST client to obtain a listenKey for your account on the appropriate product.
Open the connection
A dedicated WebSocket connection is opened using the listenKey URL. This connection is separate from any public market data connections.
Refresh every 30 minutes
The SDK schedules automatic
PUT keepalive calls on the listenKey to prevent it from expiring. For margin markets, set keepMarginListenTokenRefreshed: true (default) in WebsocketAPIClient to enable proactive refreshing.For Spot markets, Binance has deprecated the listenKey workflow in favour of the WebSocket API
userDataStream.subscribe command. The recommended approach for new Spot integrations is to use WebsocketAPIClient.subscribeUserDataStream(WS_KEY_MAP.mainWSAPI) instead of WebsocketClient.subscribeSpotUserDataStream().Receiving Events
User data events arrive on the sameWebsocketClient event emitters as market data. Use the formattedMessage event (requires beautify: true) together with the provided type guards for clean event handling, or use the raw message event for unprocessed JSON.
| Event | Description |
|---|---|
formattedMessage | Beautified event with human-readable field names. Filter by type guard. |
formattedUserDataMessage | Alias dedicated to user data events (same data, separate emitter). |
message | Raw parsed JSON directly from Binance, with wsKey appended. |
Code Example: Subscribe and Handle User Data Events
- TypeScript
- JavaScript
Spot User Data via WebsocketAPIClient (Recommended)
For Spot markets, useWebsocketAPIClient.subscribeUserDataStream() with the WebSocket API approach instead of the listenKey workflow:
WebsocketAPIClient will automatically re-subscribe to the user data stream after any reconnection. Disable this behaviour by setting resubscribeUserDataStreamAfterReconnect: false in the constructor.
Unsubscribing
Close any user data stream cleanly when you no longer need it:Reconnection Behaviour
If a user data stream connection drops for any reason — network interruption, Binance-side timeout, or a stale listenKey — the SDK will:- Emit the
reconnectingevent with the affectedwsKey. - Fetch a new listenKey via REST (if required by the stream type).
- Open a new WebSocket connection and re-establish the stream.
- Emit the
reconnectedevent once the new connection is confirmed.
reconnected fires on a user data wsKey.