WebSocket
Z
作者:Zedcex Support
一周前更新

WebSocket

一般的

Websocket 是一种新的 HTML5 协议。 它实现了客户端和服务器之间的全双工数据传输,允许数据在两个方向上有效地传输。 只需一次握手,客户端和服务器之间的连接就建立起来。 然后服务器将能够根据预设的规则将数据推送到客户端。 其优点包括:

客户端和服务器之间传输数据的WebSocket请求头大约只有2个字节

客户端或服务器都可以发起数据传输

由于不需要重复创建和删除TCP连接,因此节省了带宽和服务器资源

我们强烈建议开发者使用WebSocket API来检索市场数据和订单深度。

WS信息

网址:wss://wspool.hiotc.pro/kline-api/ws​

返回的数据除心跳数据外都会进行二进制压缩(用户需要通过Gzip算法解压)

命令格式

事件

渠道

描述

sub

market_$symbol_depth_step0

Subscribe depth

unsub

market_$symbol_depth_step0

Unsubscribe depth

sub

market_$symbol_trade_ticker

Subscribe to real-time trade

unsub

market_$symbol_trade_ticker

Unsubscribe real-time trade

sub

market_$symbol_ticker

Subscribe to 24h market data

unsub

market_$symbol_ticker

Unsubscribe 24h market data

sub

market_$symbol_kline_1min

Subscribe to 1min k-line information

req

market_$symbol_kline_1month

Request 1 month historical bar record

Heartbeat

Every once in a while, the server will send a PING message. The client needs to reply to the PONG message, otherwise the server will close the connection.

  • ping

1

{

2

"ping": 1535975085052

3

}

Copied!

  • pong

1

{

2

"pong": 1535975085052

3

}

Copied!

Subscription Full Depth

  • Subscription message structure

1

{

2

"event":"sub",

3

"params":{

4

"channel":"market_$symbol_depth_step0", // $symbol E.g. btcusdt

5

"cb_id":"1" // Business ID is not required

6

}

7

}

Copied!

  • Payload

1

{

2

"channel":"market_btcusdt_depth_step0",

3

"ts":1506584998239,

4

"tick":{ //A maximum of 30 orders are returned

5

"asks":[ //asks

6

[10000.19,0.93],

7

[10001.21,0.2],

8

[10002.22,0.34]

9

],

10

"buys":[ //buy

11

[9999.53,0.93],

12

[9998.2,0.2],

13

[9997.19,0.21]

14

]

15

}

16

}

Copied!

Subscription Real Time Trade

  • Subscription message structure

1

{

2

"event":"sub",

3

"params":{

4

"channel":"market_$symbol_trade_ticker", // $symbol E.g. btcusdt

5

"cb_id":"1" // Business ID is not required

6

}

7

}

Copied!

  • Payload

1

{

2

"channel":"market_$symbol_trade_ticker",

3

"ts":1506584998239,//request time

4

"tick":{

5

"data":[

6

{

7

"side":"buy",//buy,sell

8

"price":32.233,

9

"vol":232,

10

"amount":323,

11

"ds":'2017-09-10 23:12:21'

12

}

13

]

14

}

15

}

Copied!

Subscription Kline Market

  • Subscription message structure

1

{

2

"event":"sub",

3

"params":{

4

"channel":"market_$symbol_kline_[1min/5min/15min/30min/60min/1day/1week/1month]", // $symbol E.g. btcusdt

5

"cb_id":"1" // Business ID is not required

6

}

7

}

Copied!

  • Payload

1

{

2

"channel":"market_$symbol_kline_1min", //1min is for 1 minute

3

"ts":1506584998239,//request time

4

"tick":{

5

"id":1506602880,//kline start time

6

"vol":1212.12211,

7

"open":2233.22,//open price

8

"close":1221.11,//close price

9

"high":22322.22,//high price

10

"low":2321.22//low price

11

}

12

}

Copied!

Subscription Market Tickers

  • Subscription message structure

1

{

2

"event":"sub",

3

"params":{

4

"channel":"market_$symbol_ticker", // $symbol E.g. btcusdt

5

"cb_id":"1" // Business ID is not required

6

}

7

}

Copied!

  • Payload

1

{

2

"channel":"market_$symbol_ticker",

3

"ts":1506584998239,//request time

4

"tick":{

5

"amount":123.1221,

6

"vol":1212.12211,

7

"open":2233.22,//open price

8

"close":1221.11,//close price

9

"high":22322.22,//high price

10

"low":2321.22,//low price

11

"rose":-0.2922,//increase

12

}

13

}

Copied!

Request Kline History Data

  • Subscription message structure

1

{

2

"event":"req",

3

"params":{

4

"channel":"market_$symbol_kline_[1min/5min/15min/30min/60min/1day/1week/1month]",

5

"cb_id":"1",

6

"endIdx":"1506602880", //Return pageSize data before endIdx Not required

7

"pageSize":100 // Not required

8

}

9

}

Copied!

  • Payload

1

{

2

"event_rep":"rep","channel":"market_$symbol_kline_5min",

3

"ts":1506584998239,//request time

4

"data":[ //up to 300

5

{

6

"id":1506602880,//kline start time

7

"amount":123.1221,

8

"vol":1212.12211,

9

"open":2233.22,//open price

10

"close":1221.11,//close price

11

"high":22322.22,//high price

12

"low":2321.22//low price

13

},

14

{

15

"id":1506602880,//kline start time

16

"amount":123.1221,

17

"vol":1212.12211,

18

"open":2233.22,//open price

19

"close":1221.11,//close price

20

"high":22322.22,//high price

21

"low":2321.22//low price

22

}

23

]

24

}

Copied!

Request History Trade

  • Subscription message structure

1

{

2

"event":"req",

3

"params":{

4

"channel":"market_$symbol_trade_ticker", // $symbol E.g. btcusdt

5

"cb_id":"1" // Business ID is not required

6

}

7

}

Copied!

  • Payload

1

{

2

"event_rep":"rep","channel":"market_$symbol_trade_ticker",

3

"ts":1506584998239,"status":"ok",

4

"data":[

5

{

6

"side":"buy",//buy,sell

7

"price":32.233,//trade price

8

"vol":232,//trade vol

9

"amount":323//trade amount

10

},

11

{

12

"side":"buy",//buy,sell

13

"price":32.233,//trade price

14

"vol":232,//trade vol

15

"amount":323//trade amount

16

}

17

]

18

}

这是否解答了您的问题?