The interface supports two connection methods: token connection and apikey connection.
Regardless of the connection and subscription method, the returned data message body is the same.
1. Token Connection
Overview:
Carry the token in the request header to establish a connection with the backend. After the connection is established, send a message to subscribe. Only after a successful subscription can you receive pushed messages.
Overview:
Carry the api-key in the request header to establish a connection with the backend. After the connection is established, send a message to subscribe. Only after a successful subscription can you receive pushed messages.
After a successful connection, the backend returns: connect success
After a successful subscription, the backend returns: sub success
The actual message body is GZIP-compressed binary data, which needs to be parsed before it can be displayed properly. You can implement the parsing tool in your own language.
Here is an online reference tool: https://www.bejson.com/encrypt/gzip/#google_vignette
For example, the received binary Base64 data:
After parsing:
Message Field Descriptions
3.1 When Position or Account Changes
3.2 When User Holds a Position
3.3 When the System Closes
A fixed message will be pushed:
3.4 Normal Order
3.5 Trigger Order Return Data
4. Heartbeat
Ping every 30 seconds. If the server does not receive a ping for more than 40 seconds, it will actively disconnect.
{
"channel": "ACCOUNT_UPDATE", // channel: different event types, ACCOUNT_UPDATE is pushed when position or account changes
"uid": 1001, // Contract user ID
"t": "1564745798938", // Timestamp
"d": { // Data
"et": "CREATE", // UPDATE, DELETE, DEFAULT
// CREATE: Add a new position, p is not empty, and all position data is returned
// DELETE: Delete a position, p is not empty, and only the position id is returned
// UPDATE: Update a position, p is not empty, and only the changed fields are returned
// DEFAULT: Position unchanged, only account info changed, p is empty
"a": [ // Account list
{
"c": "USDT", // Currency name
"an": "122624.12345678", // Account balance
"la": "100.12345678", // Frozen account balance
"pn": "50.12345678" // Isolated margin account balance
},
{
"c": "BTC", // Currency
"an": "122624.12345678", // Account balance
"la": "100.12345678", // Frozen account balance
"pn": "50.12345678" // Isolated margin account balance
}
],
"p": { // Position info
"id": 90762, // Position ID
"cid": 127, // Contract ID
"pt": 1, // Position type: 1 Cross, 2 Isolated
"cn": "S-BTC-USDT", // Contract name
"con": "BTCUSDT-EXUSD", // Contract alias
"l": 20, // Leverage
"pv": 12, // Position volume
"op": 98533.6, // Average open price
"rp": 68000.3, // Estimated liquidation price
"hm": 98.22008325596366, // Isolated margin held
"ra": 2, // Realized PnL
"s": "BUY", // Position direction
"mr": 0.0847015132701974, // Margin rate
"oa": 0.0847015132701974, // Opening margin
"ccv": 2 // Closable volume
}
}
}
{
"channel": "ADL_PRICE", // When the user holds a position, ADL_PRICE message is pushed every second
"uid": 1001, // Contract user ID
"l": [
{
"id": 7001, // Position ID
"al": 1, // ADL level
"rp": 68000.3, // Estimated liquidation price
"ha": 98.22008325596366, // Margin
"mr": 0.0847015132701974, // Margin rate
"bo": 79000, // Best bid price
"so": 78000, // Best ask price
"lt": 78500, // Last traded price
"tp": 78000 // Mark price
},
{
"id": 7002, // Position ID
"al": 1, // ADL level
"rp": 68000.3, // Estimated liquidation price
"ha": 98.22008325596366, // Margin
"mr": 0.0847015132701974, // Margin rate
"bo": 79000, // Best bid price
"so": 78000, // Best ask price
"lt": 78500, // Last traded price
"tp": 78000 // Mark price
}
]
}