Skip to main content

Subscribe to WebSocket

Public Channels​

Transport

DirectionformatDescription
upward (client → server)Text JSONsub / unsub / ping
downward (server → client)Text JSON
HeartbeatText 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.chMarket
spotSpot
linearU-index futures

Subscription example

{
"op": "sub",
"ts": 1780372400759,
"tid": "a8b187e07b477eadab84ea29d9dd67c0",
"tps": [{
"t": "depth",
"ch": "linear",
"p": {
"pairs": ["BTCUSDT"],
"l": 25
}
}]
}

Subscription fields

FieldTypeRequiredDescription
opstringYessub (subscribe) / unsub (unsubscribe)
tslongRecommendedRequest timestamp (milliseconds)
tidstringRecommendedtrace ID
tpsarrayYesSubscription list, supports multiple elements

tps[] sub-field

FieldTypeRequiredDescription
tstringYesTopic type: tick / trade / depth / kline
chstringYesspot / linear
pobjectYesSubscription parameters

p{} subfield

FieldTypeRequiredDescription
pairsarrayYesList 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

PropertiesDescription
TransportWebSocket: uses fixed JSON format and does not support binary frames.
Message codeUTF-8
AuthenticationAPI Key + signature, authentication completed on the server side
HeartbeatThe client must send {"op":"ping"} every 20 seconds, and the server will respond with {"op":"pong"}.
All dataAll are private and isolated by user

Log In

After connection establishment, authentication must be completed first. Otherwise, subscription requests will be rejected.

Request Fields

FieldTypeDescription
opstringFixed value "login"
tpsarrayAuthentication parameter array. Contains exactly 1 element.
isPrivateboolboolean value true
tidstringTracking string
tsint64Request timestamp (milliseconds)
tps[0].p.api_keystringAPI Key, applied on the platform
tps[0].p.signstringSignature string
tps[0].p.timestampint64Current 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&timestamp=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 MethodAlgorithmOutput format
HmacSHA256HmacSHA256(canonical, secretKey)Lowercase hexadecimal string
RSASHA256WithRSA(canonical, privateKey)Base64 string

Response Fields

FieldTypeDescription
opstringFixed value "login"
data.codeintResponse code, see error code table below
data.messagestringresponse description
tps.pstringSame subscription
tidstringLP mode returns empty string ""
tsint64server processing timestamp (milliseconds)
stsint64server 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

codeMeaning
200Login successful
1000001Authentication 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

FieldTypeRequiredDescription
opstringYes"sub" subscribe / "unsub" unsubscribe
tpsarrayYesList of topics, each element representing a subscription item. Multiple subscriptions can be subscribed simultaneously
tps[].tstringYestopic name
tps[].chstringYesFixed value "tradingMaker"
tps[].pobjectYesadditional parameters, private message passed as empty object {}
tsint64YesRequest timestamp (milliseconds)
tidstringYesUnique 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

FieldTypeDescription
isSubResponseboolfixed to true, indicating this is a subscription response (different from push messages)
opstring"sub" or "unsub"
data.codeintResponse code
data.messagestringresponse description
tps[]stringcorresponding request parameter TPS
tidstringCorresponds to the tid in the request
tsint64server 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

codeMeaning
200Subscription Succeeded
40001Unauthenticated 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
}