WebSocket
BaseUrl: wss://openapi.digifinex.com/swap_ws/v2/
Public channel
- Time
- Ping
- Ticker
- AllTicker
- Depth
- Trades
- CurrentCandle
- IndexPrice
- MarkPrice
- MarkCandle
- PriceRange
- FundRate
- SettlePrice
Private channel
Connection
- A single connection is only valid for 24 hours; expect to be disconnected at the 24 hour mark
- The connection will break automatically if the subscription is not established or data has not been pushed for more than 60 seconds, to keep the connection stable, you should set a timer less than 60 second and send a
ping
request when the timer triggered(see Ping). - A single connection can not subscribe over 30 public channels, if you need subscribe more than 30 public channels, you need to build more connection.
- All response use
zlib deflate
to compress data.
deflate example
<script src="https://cdn.bootcss.com/pako/1.0.6/pako.min.js"></script>
<script src="https://static.runoob.com/assets/jquery/2.0.3/jquery.min.js"></script>
<script>
websocket = function () {
var ws = new WebSocket("wss://openapi.digifinex.com/swap_ws/v2/");
ws.onopen = function() {
console.log("connect success");
ws.send('{"id":1, "event":"server.ping"}');
}
ws.onmessage = function(e) {
var blob = e.data;
var reader = new FileReader();
reader.readAsBinaryString(blob);
reader.onload = function (evt) {
var data = pako.inflate(evt.target.result, { to: 'string' })
console.log("receive binaray message: " + data);
}
}
};
websocket();
</script>
ErrorCode
code | message | description |
---|---|---|
1 | success | request success |
2 | ParamInvalid | param invalid |
3 | AuthFail | auth fail |
4 | NeedAuth | need auth |
5 | RepeatSubscribe | repeat subscribe |
6 | SubscribeFail | subscribe fail |
7 | UnsubscribeFailed | unsubscribe fail |
8 | ApiNotActive | api not active |
9 | RepeatAuth | repeat auth |
Public Channel
Time
event:server.time
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | server.time |
id | yes | number | auto-increment request id |
request example
{
"event":"server.time",
"id":1
}
response param
Parameters | Type | Description |
---|---|---|
event | string | server.time |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
data | string | milliseconds since UNIX epoch |
response example
{
"event":"server.time",
"id":1,
"code":1,
"msg":"success",
"data":1662109531891
}
Ping
event:server.ping
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | server.ping |
id | yes | number | auto-increment request id |
request example
{
"event":"server.ping",
"id":1
}
response param
Parameters | Type | Description |
---|---|---|
event | string | server.ping |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
data | string | pong if success |
response example
{
"event":"server.ping",
"id":1,
"code":1,
"msg":"success",
"data":"pong"
}
Ticker
Subscribe
event:ticker.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | ticker.subscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"ticker.subscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"ticker.subscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | ticker.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"ticker.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:ticker.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | ticker.unsubscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"ticker.unsubscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"ticker.unsubscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | ticker.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"ticker.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | ticker.unsubscribe |
- data | object | response data |
instrument_id | string | instrument id |
best_bid | string | best bid price |
best_bid_size | string | best bid volume |
best_ask | string | best ask price |
best_ask_size | string | best ask volume |
high_24h | string | highest trade price since 24 hours ago |
open_24h | string | 24 hours ago trade price |
low_24h | string | lowest trade price since 24 hours ago |
last | string | last trade price |
last_qty | string | last trade volume |
volume_24h | string | total trade volume since 24 hours ago |
volume_token_24h | string | total trade token since 24 hours ago |
open_interest | string | ignore |
timestamp | number | milliseconds since UNIX epoch |
push example
{
"event":"ticker.update",
"data":{
"instrument_id":"ETHUSDTPERP",
"best_bid":"1588.41",
"best_bid_size":"938",
"best_ask":"1588.50",
"best_ask_size":"220",
"high_24h":"1611.49",
"open_24h":"1563.83",
"low_24h":"1513.14",
"last":"1588.35",
"last_qty":"130",
"volume_24h":"81330353",
"volume_token_24h":"813303.53",
"open_interest":"-",
"timestamp":1662116941153
}
}
All Ticker
Subscribe
event:all_ticker.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | all_ticker.subscribe |
id | yes | number | auto-increment request id |
request example
{
"event":"all_ticker.subscribe",
"id":1
}
response param
Parameters | Type | Description |
---|---|---|
event | string | all_ticker.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"all_ticker.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:all_ticker.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | all_ticker.unsubscribe |
id | yes | number | auto-increment request id |
request example
{
"event":"all_ticker.unsubscribe",
"id":1
}
response param
Parameters | Type | Description |
---|---|---|
event | string | all_ticker.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"all_ticker.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | ticker.unsubscribe |
- data | object | response data |
instrument_id | string | instrument id |
best_bid | string | best bid price |
best_bid_size | string | best bid volume |
best_ask | string | best ask price |
best_ask_size | string | best ask volume |
high_24h | string | highest trade price since 24 hours ago |
open_24h | string | 24 hours ago trade price |
low_24h | string | lowest trade price since 24 hours ago |
last | string | last trade price |
last_qty | string | last trade volume |
volume_24h | string | total trade volume since 24 hours ago |
volume_token_24h | string | total trade token since 24 hours ago |
open_interest | string | ignore |
timestamp | number | milliseconds since UNIX epoch |
push example
[
{
"instrument_id":"ETHUSDTPERP",
"best_bid":"1572.12",
"best_bid_size":"947",
"best_ask":"1572.21",
"best_ask_size":"972",
"high_24h":"1647.36",
"open_24h":"1577.20",
"low_24h":"1546.10",
"last":"1572.19",
"last_qty":"51",
"volume_24h":"87716861",
"volume_token_24h":"877168.61",
"open_interest":"-",
"timestamp":1662169486547
}
]
Depth
Subscribe
event:depth.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | depth.subscribe |
id | yes | number | auto-increment request id |
level | yes | number | depth level, valid level: 10 20 100 |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"depth.subscribe",
"id":1,
"instrument_id":"ETHUSDTPERP",
"level": 10
}
or
{
"event":"depth.subscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"],
"level": 10
}
response param
Parameters | Type | Description |
---|---|---|
event | string | depth.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"depth.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:depth.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | depth.unsubscribe |
id | yes | number | auto-increment request id |
level | yes | number | depth level, valid level: 10 20 100 |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"depth.unsubscribe",
"id":1,
"instrument_id":"ETHUSDTPERP",
"level": 10
}
or
{
"event":"depth.unsubscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"],
"level": 10
}
response param
Parameters | Type | Description |
---|---|---|
event | string | depth.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"depth.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | ticker.unsubscribe |
- data | object | response data |
instrument_id | string | instrument id |
level | number | push depth level |
timestamp | number | milliseconds since UNIX epoch |
- - asks | object | asks book |
0 | string | price |
1 | number | amount |
- - bids | object | bids book |
0 | string | price |
1 | number | amount |
push example
{
"event":"depth.update",
"data":{
"instrument_id":"BTCUSDTPERP",
"level":10,
"timestamp":1662173255498,
"asks":[
["19962.75",0],
["19964.25",561]
],
"bids":[
["19928.54",1001]
]
}
}
Trades
Subscribe
event:trades.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | trades.subscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"trades.subscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"trades.subscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | trades.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"trades.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:trades.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | trades.unsubscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"trades.unsubscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"trades.unsubscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | trades.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"trades.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | trades.update |
- data | object | response data |
instrument_id | string | instrument id |
trade_id | string | trade id |
direction | string | order direction 1:Open Long 2:Open Short 3:Close Long 4:Close Short |
volume | string | trade volume |
price | string | trade price |
trade_time | number | milliseconds since UNIX epoch |
response example
{
"event":"trades.update",
"data":[
{
"instrument_id":"ETHUSDTPERP",
"trade_id":"1565899918726402049",
"trade_time":1662174608295,
"volume":"5417",
"price":"1557.81",
"direction":"4"
},
{
"instrument_id":"ETHUSDTPERP",
"trade_id":"1565899917015126017",
"trade_time":1662174607887,
"volume":"111",
"price":"1557.80",
"direction":"3"
}
]
}
Cur Candle
Subscribe
event:cur_candle.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | cur_candle.subscribe |
id | yes | number | auto-increment request id |
granularity | yes | string | candle granularity: 1m 5m 15m 30m 1h 4h 12h 1d 1w |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"cur_candle.subscribe",
"id":1,
"granularity": "1m",
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"cur_candle.subscribe",
"id":1,
"granularity": "1m",
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | cur_candle.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"cur_candle.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:cur_candle.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | cur_candle.unsubscribe |
id | yes | number | auto-increment request id |
granularity | yes | string | candle granularity: 1m 5m 15m 30m 1h 4h 12h 1d 1w |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"cur_candle.unsubscribe",
"id":1,
"granularity": "1m",
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"cur_candle.unsubscribe",
"id":1,
"granularity": "1m",
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | cur_candle.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"cur_candle.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | cur_candle.update |
- data | object | response data |
instrument_id | string | instrument id |
granularity | string | candle granularity: 1m 5m 15m 30m 1h 4h 12h 1d 1w |
- - candle | object | candle detail |
0 | number | milliseconds since UNIX epoch (candle start) |
1 | string | open price |
2 | string | highest price |
3 | string | lowest price |
4 | string | close price |
5 | string | trade volume |
6 | string | token trade num |
push example
{
"event":"cur_candle.update",
"data":{
"instrument_id":"ETHUSDTPERP",
"granularity":"1m",
"candle":[1662338160000,"1573.31","1574.18","1573.13","1574.18","10529","105.29"]
}
}
Index Price
Subscribe
event:index_price.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | index_price.subscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"index_price.subscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"index_price.subscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | index_price.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"index_price.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:index_price.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | index_price.unsubscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"index_price.unsubscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"index_price.unsubscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | index_price.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"index_price.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | index_price.update |
- data | object | response data |
instrument_id | string | instrument id |
index_price | string | instrument index price |
timestamp | number | milliseconds since UNIX epoch |
push example
{
"event":"index_price.update",
"data":{
"instrument_id":"ETHUSDTPERP",
"index_price":"1573.26",
"timestamp":1662338890989
}
}
Mark Price
Subscribe
event:mark_price.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | mark_price.subscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"mark_price.subscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"mark_price.subscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | mark_price.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"mark_price.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:mark_price.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | mark_price.unsubscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"mark_price.unsubscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"mark_price.unsubscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | mark_price.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"mark_price.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | mark_price.update |
- data | object | response data |
instrument_id | string | instrument id |
index_price | string | instrument index price |
timestamp | number | milliseconds since UNIX epoch |
push example
{
"event":"mark_price.update",
"data":{
"instrument_id":"ETHUSDTPERP",
"mark_price":"1574.30",
"timestamp":1662339184099
}
}
Mark Candle
Subscribe
event:mark_candle.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | mark_candle.subscribe |
id | yes | number | auto-increment request id |
granularity | yes | string | candle granularity: 1m 5m 15m 30m 1h 4h 12h 1d 1w |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"mark_candle.subscribe",
"id":1,
"granularity": "1m",
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"mark_candle.subscribe",
"id":1,
"granularity": "1m",
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | mark_candle.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"mark_candle.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:mark_candle.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | mark_candle.unsubscribe |
id | yes | number | auto-increment request id |
granularity | yes | string | candle granularity: 1m 5m 15m 30m 1h 4h 12h 1d 1w |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"mark_candle.unsubscribe",
"id":1,
"granularity": "1m",
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"mark_candle.unsubscribe",
"id":1,
"granularity": "1m",
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | mark_candle.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"mark_candle.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | cur_candle.update |
- data | object | response data |
instrument_id | string | instrument id |
granularity | string | candle granularity: 1m 5m 15m 30m 1h 4h 12h 1d 1w |
- - mark_candle | object | candle detail |
0 | number | milliseconds since UNIX epoch (candle start) |
1 | string | open price |
2 | string | highest price |
3 | string | lowest price |
4 | string | close price |
5 | string | trade volume |
6 | string | token trade num |
push example
{
"event":"mark_candle.update",
"data":{
"instrument_id":"ETHUSDTPERP",
"granularity":"1m",
"mark_candle":[1662338160000,"1573.31","1574.18","1573.13","1574.18"]
}
}
Price Range
Subscribe
event:price_range.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | price_range.subscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"price_range.subscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"price_range.subscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | price_range.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"price_range.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:price_range.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | price_range.unsubscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"price_range.unsubscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"price_range.unsubscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | price_range.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"price_range.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | price_range.update |
- data | object | response data |
instrument_id | string | instrument id |
highest | string | max buy price |
lowest | string | min sell price |
timestamp | number | milliseconds since UNIX epoch |
push example
{
"event":"price_range.update",
"data":{
"instrument_id":"ETHUSDTPERP",
"highest":"1738.58",
"lowest":"1422.43",
"timestamp":1662339996916
}
}
Fund Rate
Subscribe
event:fund_rate.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | fund_rate.subscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"fund_rate.subscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"fund_rate.subscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | fund_rate.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"fund_rate.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:fund_rate.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | fund_rate.unsubscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"fund_rate.unsubscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"fund_rate.unsubscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | fund_rate.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"fund_rate.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | fund_rate.update |
- data | object | response data |
instrument_id | string | instrument id |
funding_rate | string | current funding rate |
funding_time | number | settlement time,milliseconds since UNIX epoch |
next_funding_rate | string | forecasted funding rate for the next period |
next_funding_time | number | funding time for the next period, milliseconds since UNIX epoch |
push example
{
"event":"fund_rate.update",
"data":{
"instrument_id":"ETHUSDTPERP",
"funding_rate":"-0.00007",
"funding_time":1662364800000,
"next_funding_rate":"-0.00010155724195205366",
"next_funding_time":1662393600000
}
}
Settle price
Subscribe
event:estimated_settle_price.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | estimated_settle_price.subscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"estimated_settle_price.subscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"estimated_settle_price.subscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | estimated_settle_price.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"estimated_settle_price.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:estimated_settle_price.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | estimated_settle_price.unsubscribe |
id | yes | number | auto-increment request id |
instrument_id | options | string | instrument_id |
instrument_ids | options | array | array of instrument_id. instrument_id and instrument_ids must not be both empty |
request example
{
"event":"estimated_settle_price.unsubscribe",
"id":1,
"instrument_id":"ETHUSDTPERP"
}
or
{
"event":"estimated_settle_price.unsubscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
response param
Parameters | Type | Description |
---|---|---|
event | string | estimated_settle_price.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"estimated_settle_price.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | estimated_settle_price.update |
- data | object | response data |
instrument_id | string | instrument id |
estimated_settle_price | string | current funding rate |
timestamp | number | milliseconds since UNIX epoch |
push example
{
"event":"estimated_settle_price.update",
"data":{
"instrument_id":"BTC2-MOVE-20220909",
"estimated_settle_price":"175.3345",
"timestamp":1662341408594
}
}
Private Channel
Auth
event:server.auth
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | server.auth |
id | yes | number | auto-increment request id |
apikey | yes | string | apikey you got |
timestamp | yes | number | milliseconds since UNIX epoch |
signature | yes | string | base64 encrypted after sha256 encrypted timestamp by api secret |
sign example
timestamp = new Date().getTime();
signature = CryptoJS.enc.Base64.Stringify(CryptoJS.HmacSHA256(timestamp.toString(), secret))
request example
{
"event":"server.auth",
"id":1,
"apikey":"dce030fc256f39",
"timestamp": 1662346006093,
"signature":"RYJ9f9tXUnR454vNaOcEis+ZGWL3FzOseRtLpM6wPyg="
}
response param
Parameters | Type | Description |
---|---|---|
event | string | server.auth |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"server.auth",
"id":1,
"code":1,
"msg":"success"
}
Account
Subscribe
event:account.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | account.subscribe |
id | yes | number | auto-increment request id |
currency | no | string | currency |
currency_list | no | array | array of currency |
instrument_type | no | number | instrument_type: 0-All, 1-Simulate, 2-Real default 0 |
contract_type | no | number | contract_type: -1-All, 0-Swap, 1-Move default 0 |
request example
{
"event":"account.subscribe",
"id":1,
"currency":"USDT"
}
or
{
"event":"account.subscribe",
"id":1,
"instrument_type": 1
}
or
{
"event":"account.subscribe",
"id":1,
"currency_list":["USDT","ETH"]
}
or
{
"event":"account.subscribe",
"id":1,
"contract_type": 0
}
or
{
"event":"account.subscribe",
"id":1
}
response param
Parameters | Type | Description |
---|---|---|
event | string | account.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"account.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:account.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | account.unsubscribe |
id | yes | number | auto-increment request id |
currency | no | string | currency |
currency_list | no | array | array of currency |
instrument_type | no | number | instrument_type: 0-All, 1-Simulate, 2-Real default 0 |
contract_type | no | number | contract_type: -1-All, 0-Swap, 1-Move default 0 |
request example
{
"event":"account.unsubscribe",
"id":1,
"currency":"USDT"
}
or
{
"event":"account.unsubscribe",
"id":1,
"currency_list":["USDT","ETH"]
}
or
{
"event":"account.unsubscribe",
"id":1,
"instrument_type": 1
}
or
{
"event":"account.unsubscribe",
"id":1,
"contract_type": 0
}
or
{
"event":"account.unsubscribe",
"id":1
}
response param
Parameters | Type | Description |
---|---|---|
event | string | account.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"account.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | account.update |
- data | object | response data |
equity | string | account equity(include unrealized profit and loss) |
currency | string | currency |
margin | string | margin occupied by position |
cross_maintain_margin | string | maintain margin of cross account |
cross_force_close_fee | string | force close fee of cross account |
cross_margin | string | cross margin occupied by position |
isolate_margin | string | isolate margin occupied by position |
isolate_balance | string | total isolate balance |
frozen_margin | string | margin occupied by open orders |
frozen_money | string | fee occupied by open orders |
frozen_transfer | string | amount occupied by transfer risk control |
margin_ratio | string | margin ratio |
realized_pnl | string | realized profit and loss |
avail_balance | string | available balance |
unrealized_pnl | string | unrealized profit and loss(cross+isolate) |
isolate_unrealized_pnl | string | isolate unrealized profit and loss |
time_stamp | number | milliseconds since UNIX epoch |
push example
{
"event":"account.update",
"data":[
{
"equity":"1298.925394604643674",
"currency":"BTC",
"margin":"0",
"cross_maintain_margin":"0",
"cross_force_close_fee":"0",
"cross_margin": "0",
"isolate_margin": "0",
"isolate_balance": "0",
"frozen_margin":"0",
"frozen_money":"0",
"frozen_transfer":"0",
"margin_ratio":"10000.0000000000000000",
"realized_pnl":"0.0514979656207763",
"avail_balance":"1298.925394604643674",
"unrealized_pnl":"0",
"isolate_unrealized_pnl":"0",
"time_stamp":1662346135090
},
{
"equity":"0.0099961852826424",
"currency":"ETH",
"margin":"0",
"cross_maintain_margin":"0",
"cross_force_close_fee":"0",
"cross_margin": "0",
"isolate_margin": "0",
"isolate_balance": "0",
"frozen_margin":"0",
"frozen_money":"0",
"frozen_transfer":"0",
"margin_ratio":"10000.0000000000000000",
"realized_pnl":"0",
"avail_balance":"0.0099961852826424",
"unrealized_pnl":"0",
"isolate_unrealized_pnl":"0",
"time_stamp":1662346135090
},
{
"equity":"10000003771.0212405313799258",
"currency":"USDT",
"margin":"38.21658",
"cross_maintain_margin":"38.21658",
"cross_force_close_fee":"10.125",
"cross_margin": "38.21658",
"isolate_margin": "0",
"isolate_balance": "0",
"frozen_margin":"9.1908",
"frozen_money":"0.00951048",
"frozen_transfer":"0",
"margin_ratio":"2093570.2271399295",
"realized_pnl":"-176.795509999999996",
"avail_balance":"9999999899.8372250513799258",
"unrealized_pnl":"3823.767125",
"isolate_unrealized_pnl":"0",
"time_stamp":1662346135090
}
]
}
Position
Subscribe
event:position.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | position.subscribe |
id | yes | number | auto-increment request id |
instrument_id | no | string | instrument_id |
instrument_ids | no | array | array of instrument_id |
instrument_type | no | number | instrument_type: 0-All, 1-Simulate, 2-Real default 0 |
contract_type | no | number | contract_type: -1-All, 0-Swap, 1-Move default 0 |
request example
{
"event":"position.subscribe",
"id":1,
"instrument_id":"BTCUSDTPERP"
}
or
{
"event":"position.subscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
or
{
"event":"position.subscribe",
"id":1,
"instrument_type": 1
}
or
{
"event":"position.subscribe",
"id":1,
"contract_type": 0
}
or
{
"event":"position.subscribe",
"id":1
}
response param
Parameters | Type | Description |
---|---|---|
event | string | position.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"position.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:position.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | position.unsubscribe |
id | yes | number | auto-increment request id |
instrument_id | no | string | instrument_id |
instrument_ids | no | array | array of instrument_id |
instrument_type | no | number | instrument_type: 0-All, 1-Simulate, 2-Real default 0 |
contract_type | no | number | contract_type: -1-All, 0-Swap, 1-Move default 0 |
request example
{
"event":"position.unsubscribe",
"id":1,
"instrument_id":"BTCUSDTPERP"
}
or
{
"event":"position.unsubscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
or
{
"event":"position.unsubscribe",
"id":1,
"instrument_type": 1
}
or
{
"event":"position.unsubscribe",
"id":1,
"contract_type": 0
}
or
{
"event":"position.unsubscribe",
"id":1
}
response param
Parameters | Type | Description |
---|---|---|
event | string | position.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"position.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | position.update |
- data | object | response data |
instrument_id | string | instrument id |
margin_mode | string | margin mode, crossed or isolated |
posi_balance | string | valid only isolated margin mode |
avail_position | string | position that can be closed |
avg_cost | string | average open price |
last | string | instrument latest trade price |
mark_price | string | instrument mark price |
leverage | string | leverage |
liquidation_price | string | estimated liquidation price |
maint_margin_ratio | string | maintenance margin ratio |
margin | string | use margin of current position |
maintain_margin | string | maintenance margin requirement |
force_close_fee | string | force close fee requirement |
position | string | total position |
realized_pnl | string | realized profit and loss |
unrealized_pnl | string | unrealized profit and loss |
unrealized_pnl_rate | string | unrealized profit and loss rate |
side | string | position side: long | short |
open_outstanding | string | close order not finish size |
add_margin_max | number | auto add margin count limit. -1: no limit, 0: forbidden, 1: at most one times, 2: at most two times, 3: at most three times |
add_margin_count | number | auto add margin count |
risk_score | string | risk score to be ADL (0-1) |
margin_ratio | string | margin ratio |
timestamp | number | milliseconds since UNIX epoch |
push example
{
"event":"position.update",
"data":[
{
"instrument_id":"BCHUSDTPERP",
"margin_mode":"crossed",
"posi_balance": "0",
"avail_position":"22",
"avg_cost":"133.2235",
"last":"2093474.889566104",
"mark_price":"2093474.88",
"leverage":"20",
"liquidation_price":"4522842166.604714",
"maint_margin_ratio":"0.005",
"margin":"14.654585",
"maintain_margin":"14.654585",
"force_close_fee":"1.345",
"position":"22",
"realized_pnl":"66038.60989713322",
"unrealized_pnl":"11.49169999999998",
"unrealized_pnl_rate":"0.7841709608289815",
"side":"short",
"open_outstanding":"0",
"add_margin_max": 0,
"add_margin_count": 0,
"risk_score":"0.8",
"margin_ratio":"0",
"timestamp":1662349557399
},
{
"instrument_id":"BTCUSDTPERP",
"margin_mode":"crossed",
"posi_balance": "0",
"avail_position":"18",
"avg_cost":"13600.1055555555556",
"last":"2093474.889566104",
"mark_price":"2093474.88",
"leverage":"20",
"liquidation_price":"-561195557768.7087",
"maint_margin_ratio":"0.01",
"margin":"12.240095",
"maintain_margin":"6.240095",
"force_close_fee":"1.345",
"position":"18",
"realized_pnl":"-15193964.386545531",
"unrealized_pnl":"3755.1941",
"unrealized_pnl_rate":"306.79452242813477",
"side":"long",
"open_outstanding":"0",
"add_margin_max": 0,
"add_margin_count": 0,
"risk_score":"0.3166666666666667",
"margin_ratio":"0",
"timestamp":1662349557399
},
{
"instrument_id":"ETHUSDTPERP",
"margin_mode":"crossed",
"posi_balance": "0",
"avail_position":"10",
"avg_cost":"1546.38",
"last":"2093474.889566104",
"mark_price":"2093474.88",
"leverage":"20",
"liquidation_price":"-101015238820.95909",
"maint_margin_ratio":"0.01",
"margin":"7.7319",
"maintain_margin":"3.240095",
"force_close_fee":"1.345",
"position":"10",
"realized_pnl":"-30292.73799999998",
"unrealized_pnl":"3.0988499999999988",
"unrealized_pnl_rate":"0.40078764598610933",
"side":"long",
"open_outstanding":"0",
"add_margin_max": 0,
"add_margin_count": 0,
"risk_score":"0.1666666666666667",
"margin_ratio":"0",
"timestamp":1662349557399
}
]
}
Order
Subscribe
event:order.subscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | order.subscribe |
id | yes | number | auto-increment request id |
instrument_id | no | string | instrument_id |
instrument_ids | no | array | array of instrument_id |
instrument_type | no | number | instrument_type: 0-All, 1-Simulate, 2-Real default 0 |
contract_type | no | number | contract_type: -1-All, 0-Swap, 1-Move default 0 |
request example
{
"event":"order.subscribe",
"id":1,
"instrument_id":"BTCUSDTPERP"
}
or
{
"event":"order.subscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
or
{
"event":"order.subscribe",
"id":1,
"instrument_type": 1
}
or
{
"event":"order.subscribe",
"id":1,
"contract_type": 0
}
or
{
"event":"order.subscribe",
"id":1
}
response param
Parameters | Type | Description |
---|---|---|
event | string | order.subscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"order.subscribe",
"id":1,
"code":1,
"msg":"success"
}
UnSubscribe
event:order.unsubscribe
request param
Parameters | Required | Type | Description |
---|---|---|---|
event | yes | string | order.unsubscribe |
id | yes | number | auto-increment request id |
instrument_id | no | string | instrument_id |
instrument_ids | no | array | array of instrument_id |
instrument_type | no | number | instrument_type: 0-All, 1-Simulate, 2-Real default 0 |
contract_type | no | number | contract_type: -1-All, 0-Swap, 1-Move default 0 |
request example
{
"event":"order.unsubscribe",
"id":1,
"instrument_id":"BTCUSDTPERP"
}
or
{
"event":"order.unsubscribe",
"id":1,
"instrument_ids":["BTCUSDTPERP","ETHUSDTPERP"]
}
or
{
"event":"order.unsubscribe",
"id":1,
"instrument_type": 1
}
or
{
"event":"order.unsubscribe",
"id":1,
"contract_type": 0
}
or
{
"event":"order.unsubscribe",
"id":1
}
response param
Parameters | Type | Description |
---|---|---|
event | string | order.unsubscribe |
id | number | auto-increment request id |
code | number | see ErrorCode |
msg | string | error msg |
response example
{
"event":"order.unsubscribe",
"id":1,
"code":1,
"msg":"success"
}
Push
push param
Parameters | Type | Description |
---|---|---|
event | string | order.update |
- data | object | response data |
order_id | string | order id |
margin_mode | string | margin mode, crossed or isolated |
instrument_id | string | instrument id |
contract_val | string | contract value of single size |
type | number | type: 1 open long 2 open short 3 close long 4 close short |
order_type | number | order type: 0: limit_price 1: IOC_opponent 2: IOC_Optimal_5 3: IOC_Optimal_10 13: IOC_Optimal_20 4: IOC_custom_price 6: GTC_opponent 7: GTC_Optimal_5 8: GTC_Optimal_10 14: GTC_Optimal_20 10: FOK_opponent 11: FOK_Optimal_5 12: FOK_Optimal_10 15: FOK_Optimal_20 9: FOK_custom_price |
price | string | order price |
size | string | order size |
filled_qty | string | filled quantity |
price_avg | string | average trade price |
fee | string | trade fee |
state | number | order status: -10: add fail, -1: canceled, 0: open, 1: part filled, 2: filled |
leverage | string | leverage |
turnover | string | filled trade value |
close_profit | string | order close profit |
has_stop | number | has stop: 0 no 1 yes |
insert_time | number | order create time, milliseconds since UNIX epoch |
time_stamp | number | order last update time, milliseconds since UNIX epoch |
push example
{
"event":"order.update",
"data":[
{
"order_id":"1565280144598241280",
"margin_mode": "crossed",
"instrument_id":"BTCUSDTPERP",
"contract_val":"0.001",
"type":1,
"order_type":0,
"price":"1998",
"size":"100",
"filled_qty":"8",
"price_avg":"1998",
"fee":"0.00047952",
"state":1,
"leverage":"20",
"turnover":"15.984",
"close_profit": "1.3762",
"has_stop":0,
"insert_time":1662026842634,
"time_stamp":1662068860901
}
]
}