General WSS information
General WebSocket Information
Base URL: wss://fstream.x.group/ws/market (Public channels; no listenKey required)
Request Headers
When initiating the HTTP upgrade for the WebSocket connection, it is recommended to enable the per‑message compression extension:
Sec-Websocket-Extensions: permessage-deflate
Subscription Steps
- Establish a WebSocket connection.
- To subscribe to a public channel event, send:
{
"method": "SUBSCRIBE",
"params": ["{topic}@{symbol_you_follow}"],
"id": "id_field_could_call_whatever_you_want"
}
Request Message Format
Subscribe / Unsubscribe example
{
"method": "SUBSCRIBE/UNSUBSCRIBE",
"params": ["{topic1}@{arg1},{arg2}", "{topic2}@{arg}"],
"id": "id_field_could_call_whatever_you_want" // callback ID
}
Response Message Format
{
"id": "{id}", // callback ID
"code": 1, // result 0=success; 1=failure; 2=listenKey invalid
"msg": ""
}
Push Message Format
{
"topic": "topic",
"event": "{topic}@{symbol}", // title
"data": {}
}
{
"topic": "trade",
"event": "trade@btc_usdt",
"data": {
"s": "btc_usdt",
"i": 6316559590087222000,
"t": 1655992403617,
"p": "43000",
"q": "0.21",
"b": true
}
}
Heartbeat
Each client connection must periodically send a text ping message. The server will reply with a text pong.
If the server does not receive a ping within 30 seconds, it will proactively close the connection.
Error Codes
| Error code | Description |
|---|---|
| 400 | Bad request payload. Please check it. |
Order Book Management
How to maintain a local order book correctly
- Connect to
wss://fstream.xt.com/ws/market, and subscribe todepth_update@btc_usdt. - Buffer the events received from the stream.
- Fetch a depth snapshot:
https://fapi.xt.com/future/market/v1/public/depth?symbol=btc_usdt&level=500. - Discard any event where
u <= lastUpdateIdin the snapshot. - The first processed event should satisfy
fu <= lastUpdateId + 1andu >= lastUpdateId + 1. - While listening to the stream, each new event must have
fu == previous.u + 1. - The data in each event is the absolute quantity at each price level.
- If the quantity is
0, remove that price level. - Receiving deletion of a price level that does not exist locally may happen and is normal.
Notes
Because the depth snapshot limits the number of levels, levels that have no changes after the initial snapshot will not be updated in the incremental depth stream. Therefore, even if you apply all updates correctly, those levels will not appear in the local order book, which may cause minor differences from the actual order book. For most use cases, a 500‑level snapshot is sufficient to understand the market and trade effectively.