Subscribe to WebSocket
Public Channels
Transport
| Direction | format | Description |
|---|---|---|
| upward (client → server) | Text JSON | sub / unsub / ping |
| downward (server → client) | Text JSON | |
| Heartbeat | Text JSON | {"op":"ping","ts":...} → {"op":"pong","ts":...,"sts":...} |
Heartbeat example
The client sends a Text JSON; ts is a required client timestamp in milliseconds.
{"op":"ping","ts":1780372400759}
The server returns text JSON. For ts, the request timestamp is echoed. For sts, the server timestamp in milliseconds is returned.
{"op":"pong","ts":1780372400759,"sts":1780372400800}
Market Type
tps.ch | Market |
|---|---|
spot | Spot |
linear | U-index futures |
Subscription example
{
"op": "sub",
"ts": 1780372400759,
"tid": "a8b187e07b477eadab84ea29d9dd67c0",
"tps": [{
"t": "depth",
"ch": "linear",
"p": {
"pairs": ["BTCUSDT"],
"l": 25
}
}]
}
Subscription fields
| Field | Type | Required | Description |
|---|---|---|---|
op | string | Yes | sub (subscribe) / unsub (unsubscribe) |
ts | long | Recommended | Request timestamp (milliseconds) |
tid | string | Recommended | trace ID |
tps | array | Yes | Subscription list, supports multiple elements |
tps[] sub-field
| Field | Type | Required | Description |
|---|---|---|---|
t | string | Yes | Topic type: tick / trade / depth / kline |
ch | string | Yes | spot / linear |
p | object | Yes | Subscription parameters |
p{} subfield
| Field | Type | Required | Description |
|---|---|---|---|
pairs | array | Yes | List of trading pairs subscribed within a single tps element,Up to 30 |
Unsubscribe
Must include: t, ch, p.pairs. Depth also requires p.l. Kline also requires p.pd.
{
"op": "unsub",
"ts": 1780372405000,
"tps": [{
"t": "depth",
"ch": "linear",
"p": { "pairs": ["BTCUSDT"], "l": 25 }
}]
}
Subscription and Unsubscription Response
data.op indicates an operation (sub or unsub), data.code indicates a number, 200 indicates success.
A single request may receive multiple responses. Process each response by the topic and trading pair specified in tps.
Cancel subscription success example
{
"ts": 1780372405090,
"sessionId": "example-session-id",
"tps": {
"t": "depth",
"ch": "linear",
"p": { "pairs": ["BTCUSDT"], "l": 25 }
},
"data": { "code": 200, "message": "success", "op": "unsub" }
}
Subscription Succeeded
{
"ts": 1780372400800,
"tid": "a8b187e07b477eadab84ea29d9dd67c0",
"sessionId": "example-session-id",
"tps": {
"t": "depth",
"ch": "linear",
"p": { "pairs": ["BTCUSDT"], "l": 25 }
},
"data": { "code": 200, "message": "success", "op": "sub" }
}
Subscription Failed
{
"ts": 1780372400800,
"tid": "sub-err-1",
"tps": {
"t": "depth",
"ch": "linear",
"p": { "pairs": ["BTCUSDT"], "l": 30 }
},
"data": { "code": 40001, "message": "invalid depth limit, allowed: 25", "op": "sub" }
}
Market Data Push
{
"ts": 1780372401000,
"tps": {
"t": "depth",
"ch": "linear",
"p": { "pairs": ["BTCUSDT"], "l": 25 }
},
"data": {
"s": "BTCUSDT",
"l": 25,
"b": [["65000.10", "1.5"], ["65000.00", "2.0"]],
"a": [["65000.20", "0.8"]],
"t": 1780372401000,
"q": 123456789
}
}
Private Channels
Connection flow
Establish WebSocket connection → send login request → receive successful response → send sub subscription request → receive pushed data
Maximum client online connection count: 50
| Properties | Description |
|---|---|
| Transport | WebSocket: uses fixed JSON format and does not support binary frames. |
| Message code | UTF-8 |
| Authentication | API Key + signature, authentication completed on the server side |
| Heartbeat | The client must send {"op":"ping"} every 20 seconds, and the server will respond with {"op":"pong"}. |
| All data | All are private and isolated by user |
Log In
After connection establishment, authentication must be completed first. Otherwise, subscription requests will be rejected.
Request Fields
| Field | Type | Description |
|---|---|---|
op | string | Fixed value "login" |
tps | array | Authentication parameter array. Contains exactly 1 element. |
isPrivate | bool | boolean value true |
tid | string | Tracking string |
ts | int64 | Request timestamp (milliseconds) |
tps[0].p.api_key | string | API Key, applied on the platform |
tps[0].p.sign | string | Signature string |
tps[0].p.timestamp | int64 | Current timestamp in milliseconds, string type. The server validates a time window. Requests outside the range are rejected (recommended error margin no more than ±5 seconds) |
Request Example
{
"op": "login",
"isPrivate": true,
"ts": 1781583084280,
"tid": "login-001",
"tps": [
{
"p": {
"api_key": "70010d16-cd53-448f-94cc-cab8a6561188",
"timestamp": 1781583084279,
"sign": "6b52feebfdfc96b6abbb410acb274c97c45c57db252fc66719b537c008ce1487"
}
}
]
}
Signing Algorithms
The server supports two signature methods, based on the account settings for the corresponding API Key.
Step 1: Build the Signing Input
Extract all parameters from tps[0].p except signSort by key in alphabetical orderkey=value&key=value
api_key=your-api-key&openId=LBA9I81613×tamp=1710000000000
Step two: MD5 processing (to obtain the canonical string)
canonical = MD5(concatenatedString).toUpperCase()
// Example output: A3F2C1D4E5B6F7A8C9D0E1F2A3B4C5D6
Step 3: Sign the canonical string using the signing method configured for your account
| Signature Method | Algorithm | Output format |
|---|---|---|
| HmacSHA256 | HmacSHA256(canonical, secretKey) | Lowercase hexadecimal string |
| RSA | SHA256WithRSA(canonical, privateKey) | Base64 string |
Response Fields
| Field | Type | Description |
|---|---|---|
op | string | Fixed value "login" |
data.code | int | Response code, see error code table below |
data.message | string | response description |
tps.p | string | Same subscription |
tid | string | LP mode returns empty string "" |
ts | int64 | server processing timestamp (milliseconds) |
sts | int64 | server response timestamp (milliseconds) |
Successful Response Example
{
"op": "login",
"data": {
"code": 200,
"message": "success"
},
"tid": "login-001",
"ts": 1781583084411,
"sts": 1781583084411,
"tps": {
"p": {
"api_key": "70010d16-cd53-448f-94cc-cab8a6565588",
"openId": "LBA9I81613",
"sign": "6b52feebfdfc96b6abbb410acb274c97c45c57db252fc66719b537c008ce1487",
"timestamp": 1781583084279
}
}
}
Failed Response Example
{
"op": "login",
"data": {
"code": 1000001,
"message": "authentication failed"
},
"tid": "login-001",
"ts": 1781583084411,
"sts": 1781583084411,
"tps": {
"p": {
"api_key": "70010d16-cd53-448f-94cc-cab8a6565588",
"openId": "LBA9I81613",
"sign": "6b52feebfdfc96b6abbb410acb274c97c45c57db252fc66719b537c008ce1487",
"timestamp": 1781583084279
}
}
}
Error Code
| code | Meaning |
|---|---|
| 200 | Login successful |
| 1000001 | Authentication failure (signature error / IP not in whitelist / nonce replay / timestamp out of window / invalid API key) |
Subscribe
After logging in, send a subscription request to start receiving pushes. Each request can subscribe to 1 topic.
Request Fields
| Field | Type | Required | Description |
|---|---|---|---|
op | string | Yes | "sub" subscribe / "unsub" unsubscribe |
tps | array | Yes | List of topics, each element representing a subscription item. Multiple subscriptions can be subscribed simultaneously |
tps[].t | string | Yes | topic name |
tps[].ch | string | Yes | Fixed value "tradingMaker" |
tps[].p | object | Yes | additional parameters, private message passed as empty object {} |
ts | int64 | Yes | Request timestamp (milliseconds) |
tid | string | Yes | Unique request ID, returned exactly by the server for response matching |
Request Example
{
"op": "sub",
"ts": 1781583085296,
"tid": "sub-001",
"tps": [
{
"t": "futureTradingOrders",
"ch": "tradingMaker",
"p": {
}
}
]
}
Cancel subscription example
{
"op": "unsub",
"ts": 1781583085296,
"tid": "sub-001",
"tps": [
{
"t": "futureTradingOrders",
"ch": "tradingMaker",
"p": {
}
}
]
}
Response Fields
| Field | Type | Description |
|---|---|---|
isSubResponse | bool | fixed to true, indicating this is a subscription response (different from push messages) |
op | string | "sub" or "unsub" |
data.code | int | Response code |
data.message | string | response description |
tps[] | string | corresponding request parameter TPS |
tid | string | Corresponds to the tid in the request |
ts | int64 | server response timestamp (milliseconds) |
Successful Response Example
{
"isSubResponse": true,
"data": {
"code": 200,
"message": "success"
},
"op": "sub",
"ts": 1781583085398,
"tid": "sub-001",
"tps": {
"t": "futureTradingOrders",
"ch": "tradingMaker",
"p": {
}
}
}
Failure response example (not logged in)
{
"isSubResponse": true,
"op": "sub",
"data": {
"code": 40001,
"message": "Unauthorized: please login first"
},
"tps": {
"t": "spotTradingOrders",
"ch": "tradingMaker"
},
"tid": "req-002"
}
Error Code
| code | Meaning |
|---|---|
| 200 | Subscription Succeeded |
| 40001 | Unauthenticated or unauthorized |
Heartbeat
Send a Ping request every 30 seconds to keep the connection open.
Ping request
{
"op": "ping",
"ts": 1710000000000
}
Pong response
{
"op": "pong",
"ts": 1710000000000,
"sTs": 1710000000052
}