WebSocket Streams for Binance SPOT Testnet
General WSS information
- The base endpoint is: wss://stream.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=MICROSECONDortimeUnit=microsecondin 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 frameevery 20 seconds.- If the WebSocket server does not receive a
pong frameback 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 framesare 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
- The base endpoint wss://data-stream.binance.vision can be subscribed to receive only market data messages.
User data stream is NOT available from this URL. - All time and timestamp related fields are milliseconds by default. To receive the information in microseconds, please add the parameter
timeUnit=MICROSECOND or timeUnit=microsecondin the URL.- For example:
/stream?streams=btcusdt@trade&timeUnit=MICROSECOND
- For example:
- If your request contains a symbol name containing non-ASCII characters, then the stream events may contain non-ASCII characters encoded in UTF-8.
- [All Market Mini Tickers Stream](#all-market-mini-tickers-stream and All Market Rolling Window Statistics Streams events may contain non-ASCII characters encoded in UTF-8.
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
idis 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
resultreceived isnullthis 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
} -
Response
{
"result": null,
"id": 5
}