WebSocket API Reference
阿新 • • 發佈:2018-05-01
open ted req con tab 範圍 訂閱 方式 IT
訂閱 KLine 數據 market.$symbol.kline.$period
成功建立和 WebSocket API 的連接之後,向 Server 發送如下格式的數據來訂閱數據:
{ "sub": "market.$symbol.kline.$period", "id": "id generate by client" }
參數名稱 | 是否必須 | 類型 | 描述 | 默認值 | 取值範圍 |
---|---|---|---|---|---|
symbol | true | string | 交易對 | ethbtc, ltcbtc, etcbtc, bchbtc...... | |
period | true | string | K線周期 | 1min, 5min, 15min, 30min, 60min, 1day, 1mon, 1week, 1year |
正確訂閱的例子
正確訂閱
{ "sub": "market.btcusdt.kline.1min", "id": "id1" }
訂閱成功返回數據的例子
{ "id": "id1", "status": "ok", "subbed": "market.btcusdt.kline.1min", "ts": 1489474081631 }
之後每當 KLine 有更新時,client 會收到數據,例子
{ "ch": "market.btcusdt.kline.1min", "ts": 1489474082831, "tick": {"id": 1489464480, "amount": 0.0, "count": 0, "open": 7962.62, "close": 7962.62, "low": 7962.62, "high": 7962.62, "vol": 0.0 } }
tick 說明
"tick": { "id": K線id, "amount": 成交量, "count": 成交筆數, "open": 開盤價, "close": 收盤價,當K線為最晚的一根時,是最新成交價 "low": 最低價,"high": 最高價, "vol": 成交額, 即 sum(每一筆成交價 * 該筆的成交量) }
錯誤訂閱的例子
錯誤訂閱(錯誤的 symbol)
{ "sub": "market.invalidsymbol.kline.1min", "id": "id2" }
訂閱失敗返回數據的例子
{ "id": "id2", "status": "error", "err-code": "bad-request", "err-msg": "invalid topic market.invalidsymbol.kline.1min", "ts": 1494301904959 }
錯誤訂閱(錯誤的 topic)
{ "sub": "market.btcusdt.kline.3min", "id": "id3" }
訂閱失敗返回數據的例子
{ "id": "id3", "status": "error", "err-code": "bad-request", "err-msg": "invalid topic market.btcusdt.kline.3min", "ts": 1494310283622 }
請求 KLine 數據 market.$symbol.kline.$period
{ "req": "market.$symbol.kline.$period", "id": "id generated by client", "from": "optional, type: long, 2017-07-28T00:00:00+08:00 至 2050-01-01T00:00:00+08:00 之間的時間點,單位:秒", "to": "optional, type: long, 2017-07-28T00:00:00+08:00 至 2050-01-01T00:00:00+08:00 之間的時間點,單位:秒,必須比 from 大" }
參數名稱 | 是否必須 | 類型 | 描述 | 默認值 | 取值範圍 |
---|---|---|---|---|---|
symbol | true | string | 交易對 | btcusdt, ethusdt, ltcusdt, etcusdt, bchusdt, ethbtc, ltcbtc, etcbtc, bchbtc... | |
period | true | string | K線周期 | 1min, 5min, 15min, 30min, 60min, 1day, 1mon, 1week, 1year |
[t1,t5]設有 t1 ~ t5 的K線.
- from: t1, to: t5, return [t1, t5].
- from: t5, to: t1, which t5 > t1, return [].
- from: t5, return [t5].
- from: t3, return [t3, t5].
- to: t5, return [t1, t5].
- from: t which t3 < t <t4, return [t4, t5].
- to: t which t3 < t <t4, return [t1, t3].
- from: t1 and to: t2, should satisfy 1501171200 < t1 < t2 < 2524579200.
一次最多300條
請求 KLine 數據的例子
{ "req": "market.btcusdt.kline.1min", "id": "id10" }
返回數據的例子
{ "rep": "market.btcusdt.kline.1min", "status": "ok", "id": "id10", "tick": [ { "amount": 17.4805, "count": 27, "id": 1494478080, "open": 10050.00, "close": 10058.00, "low": 10050.00, "high": 10058.00, "vol": 175798.757708 }, { "amount": 15.7389, "count": 28, "id": 1494478140, "open": 10058.00, "close": 10060.00, "low": 10056.00, "high": 10065.00, "vol": 158331.348600 }, // more KLine data here ] }
訂閱 Market Depth 數據 market.$symbol.depth.$type
成功建立和 WebSocket API 的連接之後,向 Server 發送如下格式的數據來訂閱數據:
{ "sub": "market.$symbol.depth.$type", "id": "id generated by client" }
參數名稱 | 是否必須 | 類型 | 描述 | 默認值 | 取值範圍 |
---|---|---|---|---|---|
symbol | true | string | 交易對 | btcusdt, ethusdt, ltcusdt, etcusdt, bchusdt, ethbtc, ltcbtc, etcbtc, bchbtc... | |
type | true | string | Depth 類型 | step0, step1, step2, step3, step4, step5(合並深度0-5);step0時,不合並深度 |
- 用戶選擇“合並深度”時,一定報價精度內的市場掛單將予以合並顯示。合並深度僅改變顯示方式,不改變實際成交價格。
正確訂閱例子
{ "sub": "market.btcusdt.depth.step0", "id": "id1" }
訂閱成功返回數據的例子
{ "id": "id1", "status": "ok", "subbed": "market.btcusdt.depth.step0", "ts": 1489474081631 }
之後每當 depth 有更新時,client 會收到數據,例子
{ "ch": "market.btcusdt.depth.step0", "ts": 1489474082831, "tick": { "bids": [ [9999.3900,0.0098], // [price, amount] [9992.5947,0.0560], // more Market Depth data here ] "asks": [ [10010.9800,0.0099] [10011.3900,2.0000] //more data here ] } }
tick 說明
"tick": { "bids": [ [買1價,買1量] [買2價,買2量] //more data here ] "asks": [ [賣1價,賣1量] [賣2價,賣2量] //more data here ] }
請求 Market Depth 數據 market.$symbol.depth.$type
{ "req": "market.$symbol.depth.$type", "id": "id generated by client" }
請求 Market Depth 數據的例子
{ "req": "market.btcusdt.depth.step0", "id": "id10" }
返回數據的例子:
{ "rep": "market.btcusdt.depth.step0", "status": "ok", "id": "id10", "tick": { "bids": [ [9999.3900,0.0098], // [price, amount] [9992.5947,0.0560], // more Market Depth data here ] "asks": [ [10010.9800,0.0099] [10011.3900,2.0000] //more data here ] } }
訂閱 Trade Detail 數據 market.$symbol.trade.detail
{ "sub": "market.$symbol.trade.detail", "id": "id generated by client" }
參數名稱 | 是否必須 | 類型 | 描述 | 默認值 | 取值範圍 |
---|---|---|---|---|---|
symbol | true | string | 交易對 | btcusdt, ethusdt, ltcusdt, etcusdt, bchusdt, ethbtc, ltcbtc, etcbtc, bchbtc... |
正確訂閱例子:
{ "sub": "market.btcusdt.trade.detail", "id": "id1" }
訂閱成功返回數據的例子:
{ "id": "id1", "status": "ok", "subbed": "market.btcusdt.trade.detail", "ts": 1489474081631 }
之後每當 Trade Detail 有更新時,client 會收到數據,例子:
{ "ch": "market.btcusdt.trade.detail", "ts": 1489474082831, "data": [ { "id": 601595424, "price": 10195.64, "time": 1494495766, "amount": 0.2943, "direction": "buy", "tradeId": 601595424, "ts": 1494495766000 }, { "id": 601595423, "price": 10195.64, "time": 1494495711, "amount": 0.2430, "direction": "buy", "tradeId": 601595423, "ts": 1494495711000 }, // more Trade Detail data here ] } }
data 說明:
"data": [ { "id": 消息ID, "price": 成交價, "time": 成交時間, "amount": 成交量, "direction": 成交方向, "tradeId": 成交ID, "ts": 時間戳 } ]
請求 Trade Detail 數據 market.$symbol.trade.detail
{ "req": "market.$symbol.trade.detail", "id": "id generated by client" }
- 僅能獲取最近 300 個 Trade Detail 數據
請求 Trade Detail 數據的例子
{ "req": "market.btcusdt.trade.detail", "id": "id11" }
返回數據的例子:
{ "rep": "market.btcusdt.trade.detail", "status": "ok", "id": "id11", "data": [ { "id": 601595424, "price": 10195.64, "time": 1494495766, "amount": 0.2943, "direction": "buy", "tradeId": 601595424, "ts": 1494495766000 }, { "id": 601595423, "price": 10195.64, "time": 1494495711, "amount": 0.2430, "direction": "buy", "tradeId": 601595423, "ts": 1494495711000 }, // more Trade Detail data here ] }
請求 Market Detail 數據 market.$symbol.detail
{ "req": "market.$symbol.detail", "id": "id generated by client" }
- 僅返回當前 Market Detail
請求 Market Detail 數據的例子
{ "req": "market.btcusdt.detail", "id": "id12" }
返回數據的例子:
{ "rep": "market.btcusdt.detail", "status": "ok", "id": "id12", "tick": { "amount": 12224.2922, "open": 9790.52, "close": 10195.00, "high": 10300.00, "ts": 1494496390000, "id": 1494496390, "count": 15195, "low": 9657.00, "vol": 121906001.754751 } }
WebSocket API Reference