WebSocketAPI
xt为用户提供了一个简单的而又强大的API,旨在帮助用户快速高效的将xt交易功能整合到自己应用当中。
WebSocket服务地址
xt WebSocket服务连接地址:wss://ws.xt.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
获取xt最新行情数据
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.182984","9.274772","9.139348","9.219058","66.68","0.39","1.00","1M","false"],
["K","90","btc_krw","1530588660","9.323081","9.464753","9.233462","9.245472","137.81","-0.83","1.00","1M","false"]]
增量数据response
["K","90","btc_krw","1530588660","9.323081","9.464753","9.233462","9.245472","137.81","-0.83","1.00","1M","false"]
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.52474412","8.30549744"],["9.52439338","1.27516183"],["9.24510427","7.30032233"]]},
{"bids":[["9.22777334","0.7185328"],["9.22746464","1.00998182"],["9.22673134","10.67980016"]]}]]
增量数据response
["E","90","1530596231","BTC_KRW","ASK","9.31466872","25.17915754"]
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.21905755","9.51934036"],
["T","90","1530588741","BTC_KRW","ask","9.1909928","7.82056220"],
["T","90","1530588698","BTC_KRW","ask","9.26087653","3.05215100"]]
后续增量数据response
["T","90","1530596909","BTC_KRW","ask","9.22561602","15.26344425"]
request dataType格式为 市场id_TRADE_市场卖方货币_市场卖方货币
全量数据是增量数据的列表形式,字段说明:[数据类型, 市场ID, 币种信息, 时间戳, 买卖类型(asks卖bids买), 价格, 量]
市场行情包括6小时收盘价
没有全量数据和增量数据的分别,只有一种格式。
示例
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"],
[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"]]}
request dataType固定为 ALL_TRADE_STATISTIC_24H
字段说明:
{"trade_statistic":[[ 市场ID, 最新成交价, 最高价,最低价, 24小时成交量,24小时涨跌幅, 最近6H收盘价列表,买一价,卖一价],....]}。
最近6H收盘价列表数据说明:[[序号, 收盘价], [序号, 收盘价], [序号, 收盘价]]