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
- A single connection to stream.testnet.binance.vision is only valid for 24 hours; expect to be disconnected at the 24 hour mark.
- A
serverShutdownevent will be sent when the server is about to shutdown, resulting in disconnection. Please establish a new connection as soon as possible to prevent interruption. - 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 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.
Server Shutdown
serverShutdown event is sent when the server is about to shut down.
rawstream:
{
"e": "serverShutdown", // Event type
"E": 1770123456789, // Event time
"T": 1770124000000 // Upcoming shutdown time
}
combinedstream:
{
"stream": "!serverShutdown",
"data": {
"e": "serverShutdown", // Event type
"E": 1770123456789, // Event time
"T": 1770124000000 // Upcoming shutdown time
}
}
Please establish a new connection as soon as possible to prevent interruption.
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
}