用户API-WebSocket接口

WebSocketAPI

BITHI为用户提供了一个简单的而又强大的API,旨在帮助用户快速高效的将BITHI交易功能整合到自己应用当中。
如果在使用过程中有任何问题,请联系我们客服 ,我们将为您做出最权威的解答。

WebSocket服务地址

WebSocket服务连接地址:wss://kline.bithi.com/websocket

使用说明

以下API都可以在一个WebSocket 连接进行处理, 通过订阅报文中的action参数来订阅服务器数据。k线、盘口、交易记录数据三类数据服务器首先会返回一次全量数据,之后有新数据时会主动推送。
订阅报文基础格式:

{"dataType":"1_ENTRUST_ADD_EOS_QTUM", "dataSize":1, "action":"ADD"}
dataType: 请求的数据类型, 下面各个章节会详细说明。
dataSize: 请求的数据数量,决定首次全量数据的数量,不传或者为 0 则返回一条数据。
action: 请求的动作类型,ADD:增加数据订阅,DEL:移除数据订阅。 

报文格式比较简单直观,可以先用在线websocket工具简单测试下或者到官网有k线的页面打开开发者模式查看数据后再进行开发。

1行情API

获取最新行情数据

1.1K线

size最多为500条,支持的时间周期有 1M, 5M, 15M, 30M, 1H, 1D
示例

request
{"dataType":"90_KLINE_1M_BTC_KRW","dataSize":1000,"action":"ADD"} 
首次全量数据response
[["K","90","btc_krw","1530588720","9.1829","9.2747","9.1398","9.2190","66.68","0.39","1.00","1M","false","617.67"],
["K","90","btc_krw","1530588660","9.3281","9.4647","9.2334","9.2454","137.81","-0.83","1.00","1M","false","1317.67"]]
增量数据response
["K","90","btc_krw","1530588660","9.3230","9.4647","9.2334","9.2454","137.81","-0.83","1.00","1M","false","1317.67"]

request dataType格式为 市场id_KLINE_时间周期_市场卖方货币_市场卖方货币 全量数据是增量数据的列表形式,字段说明:[数据类型, 市场ID, 市场名字, 时间戳, 开盘价, 最高价, 最低价, 收盘价, 成交量, 涨跌幅度, 美元汇率, K线周期, 是否经过转换(字段未启用),成交额(单位是买方币种)]

1.2盘口(市场深度)

买盘卖盘各自最多50条,后续版本全量数据可能会发多次,接收到全量数据后清空替换掉所有盘口。
示例

request
{"dataType":"90_ENTRUST_ADD_BTC_KRW","dataSize":50,"action":"ADD"}
全量数据response
[["AE","90","BTC_KRW","1530588744",
{"asks":[["9.5247","8.3054"],["9.5243","1.2751"],["9.2451","7.3003"]]},
{"bids":[["9.2277","0.7185"],["9.2274","1.0099"],["9.2267","10.6798"]]}]]  
增量数据response
["E","90","1530596231","BTC_KRW","ASK","9.3146","25.1791"]  

request dataType格式为 市场id_ENTRUST_ADD_市场卖方货币_市场卖方货币
全量数据字段说明:[数据类型, 市场ID, 市场名字, 时间戳, asks:(卖盘)[[价格, 量]], bids:(买盘)[[价格, 量]]]
增量数据字段说明:[数据类型, 市场ID, 时间戳, 市场名字, 买卖类型(asks卖bids买), 价格, 量]
每个增量数据表示的是单个档位要数据,当量为0时说明这个档位已经被全部交易完毕,需要移除。

1.3交易记录

全量数据买最多50条。
示例

request
{"dataType":"90_TRADE_BTC_KRW","dataSize":20,"action":"ADD"}  
全量数据response
[["T","90","1530588744","BTC_KRW","ask","9.2190","9.5193"],
["T","90","1530588741","BTC_KRW","ask","9.1909","7.8205"],
["T","90","1530588698","BTC_KRW","ask","9.2608","3.0521"]] 
后续增量数据response
["T","90","1530596909","BTC_KRW","ask","9.2256","15.2634"]  

request dataType格式为 市场id_TRADE_市场卖方货币_市场卖方货币
全量数据是增量数据的列表形式,字段说明:[数据类型, 市场ID, 时间戳, 市场名字, 买卖类型(ask卖bid买), 价格, 量]

1.4获取全部市场24H行情数据

没有全量数据和增量数据的分别,只有一种格式。
示例

request
{"dataType":"ALL_TRADE_STATISTIC_24H","dataSize":1,"action":"ADD"}  
response
{"trade_statistic":
[[99,"9.39","9.82","1","153734.8286","830.3","[[1, 9.39], [2, 9.37], [3, 9.24], [4, 9.39]]","9.27","9.39","21469873.408"],
[90,"9.5","6652698.301","1.02","169532.11","814.53","[[1, 9.486], [2, 9.658], [3, 9.212], [4, 9.25]]","9.4","9.227","21469873.408"]]}

request dataType固定为 ALL_TRADE_STATISTIC_24H
字段说明:
{"trade_statistic":[[ 市场ID, 最新成交价, 最高价,最低价, 24小时成交量,24小时涨跌幅, 最近6H收盘价列表,买一价,卖一价,24小时成交额(单位是买方币种)],....]}。
最近6H收盘价列表数据说明:[[序号, 收盘价], [序号, 收盘价], [序号, 收盘价]]

1.5获取单个市场24H行情数据

没有全量数据和增量数据的分别,只有一种格式。
示例

request
{"dataType":"90_TRADE_STATISTIC_24H","dataSize":1,"action":"ADD"}  
response
{"trade_statistic":
[[90,"9.5","6652698.301","1.02","169532.11","814.53","[[1, 9.486], [2, 9.658], [3, 9.212], [4, 9.25]]","9.4","9.227","21469873.408"]]}

request dataType格式为 市场id_TRADE_STATISTIC
字段说明:
返回的数据格式和1.4获取全部市场24H行情数据一致,只是列表中只包含有单个市场的数据。

2错误码

失败时返回报文如下,其中dataType对应订阅数据报文的dataType参数

{
    "msg":"data not exist",
    "code":"5016",
    "dataType":"5_KLINE_1M_BTC_USDT"
}

错误码列表:

错误码 说明 英文说明
5016 数据不存在 data not exist
会话

{{selectedConversation.conversationName}}

정보발송
{{curr.unreadCount}}

{{curr.conversationName}}

정보발송

{{item.senderInfo.nickname}}