Binance Web3 API provides real-time data streaming over WebSocket. Connections are protected by an API Key. Please apply for an API Key before connecting, and use the WebSocket Auth API to obtain a token when establishing the connection.
How to Connect
Stream domain: wss://web3-stream.binance.com/w3w/stream
Before connecting, please Get WebSocket Auth Token and append the token to the URL as a query parameter.
Example:
Code
How to Subscribe
Once connected, you can subscribe or unsubscribe to streams.
Subscription Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | int | Yes | Randomly generated at connection time; remains unchanged for the lifetime of the connection |
method | String | Yes | Accepted values: SUBSCRIBE / UNSUBSCRIBE |
params | List<String> | Yes | The streams to subscribe to. Stream definitions are provided in the WebSocket documentation for each feature module |
Example:
Code
Response Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
stream | String | Yes | Same as the subscribed stream |
data | Object | Yes | Response data |
Example:
Code
Notes
- Each connection is valid for no more than 24 hours. Please handle reconnection logic appropriately.
- The server sends a ping frame every 3 minutes. The client must reply with a pong frame within 10 minutes, otherwise the server will close the connection. Unpaired pong frames are allowed (i.e. the client may send pong frames more frequently than once every 15 minutes to keep the connection alive).
- The WebSocket server accepts a maximum of 10 subscription messages per second.
- If a client exceeds this limit, the connection will be closed. IPs that are repeatedly disconnected may be blocked by the server.
- A single connection can subscribe to a maximum of 1024 streams.
Last modified on