Web Socket Streams for Binance SPOT Testnet
Last Updated: 2025-02-05
General WSS information
- The base endpoint is: wss://testnet.binance.vision/ws.
- Streams can be accessed either in a single raw stream or in a combined stream
- Raw streams are accessed at /ws/<streamName>
- Combined streams are accessed at /stream?streams=<streamName1>/<streamName2>/<streamName3>
- Combined stream events are wrapped as follows: {"stream":"<streamName>","data":<rawPayload>}
- All symbols for streams are lowercase
- All time and timestamp related fields are milliseconds by default. To receive the information in microseconds, please add the parameter
timeUnit=MICROSECOND
ortimeUnit=microsecond
in the URL.- For example:
/stream?streams=btcusdt@trade&timeUnit=MICROSECOND
- For example:
- A single connection to stream.binance.com is only valid for 24 hours; expect to be disconnected at the 24 hour mark
- The websocket server will send a
ping frame
every 20 seconds.- If the websocket server does not receive a
pong frame
back from the connection within a minute, the connection will be disconnected. - When you receive a ping, you must send a pong with a copy of ping's payload as soon as possible.
- Unsolicited
pong frames
are allowed, but will not prevent disconnection. It is recommended that the payload for these pong frames are empty.
- If the websocket server does not receive a
Websocket Limits
- WebSocket connections have a limit of 5 incoming messages per second. A message is considered:
- A PING frame
- A PONG frame
- A JSON controlled message (e.g. subscribe, unsubscribe)
- A connection that goes beyond the limit will be disconnected; IPs that are repeatedly disconnected may be banned.
- A single connection can listen to a maximum of 1024 streams.
- There is a limit of 300 connections per attempt every 5 minutes per IP.
Live Subscribing/Unsubscribing to streams
- The following data can be sent through the websocket instance in order to subscribe/unsubscribe from streams. Examples can be seen below.
- The
id
is used as an identifier to uniquely identify the messages going back and forth. The following formats are accepted:- 64-bit signed integer
- alphanumeric strings; max length 36
null
- In the response, if the
result
received isnull
this means the request sent was a success for non-query requests (e.g. Subscribing/Unsubscribing).
Subscribe to a stream
-
Request
{
"method": "SUBSCRIBE",
"params": [
"btcusdt@aggTrade",
"btcusdt@depth"
],
"id": 1
} -
Response
{
"result": null,
"id": 1
}
Unsubscribe to a stream
-
Request
{
"method": "UNSUBSCRIBE",
"params": [
"btcusdt@depth"
],
"id": 312
} -
Response
{
"result": null,
"id": 312
}
Listing Subscriptions
-
Request
{
"method": "LIST_SUBSCRIPTIONS",
"id": 3
} -
Response
{
"result": [
"btcusdt@aggTrade"
],
"id": 3
}
Setting Properties
Currently, the only property that can be set is whether combined
stream payloads are enabled or not.
The combined property is set to false
when connecting using /ws/
("raw streams") and true
when connecting using /stream/
.
-
Request
{
"method": "SET_PROPERTY",
"params": [
"combined",
true
],
"id": 5
}