订阅 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
}
}

火币网API文档——WebSocket API Reference的更多相关文章

  1. 火币网API文档——WebSocket API简介

    WebSocket API简介 WebSocket协议是基于TCP的一种新的网络协议.它实现了客户端与服务器之间在单个 tcp 连接上的全双工通信,由服务器主动发送信息给客户端,减少了频繁的身份验证等 ...

  2. 火币网API文档——WebSocket API错误码

    错误信息返回格式 { "id": "id generate by client", "status": "error", ...

  3. 火币网API文档——Websocket 请求与订阅示例

    1. 访问地址 Pro 站行情请求地址为:wss://api.huobipro.com/ws HADAX 站行情请求地址为:wss://api.hadax.com/ws 2. 数据压缩 WebSock ...

  4. 火币网API文档——REST API 签名认证

    安全认证 目前关于apikey申请和修改,请在“账户 - API管理”页面进行相关操作.其中AccessKey为API 访问密钥,SecretKey为用户对请求进行签名的密钥(仅申请时可见).Pro站 ...

  5. 火币网API文档——REST API 错误码

    错误码 行情 API 错误码 错误码 描述 bad-request 错误请求 invalid-parameter 参数错 invalid-command 指令错 code 的具体解释, 参考对应的er ...

  6. SpringBoot系列: 使用 Swagger 生成 API 文档

    SpringBoot非常适合开发 Restful API程序, 我们都知道为API文档非常重要, 但要维护好难度也很大, 原因有: 1. API文档如何能被方便地找到? 以文件的形式编写API文档都有 ...

  7. springboot + swagger2 生成api文档

    直接贴代码: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-sw ...

  8. 什么是API文档?--斯科特·马文

    有时候,软件开发人员想要的是自己的软件被其他应用软件所应用,而不是让人来操作.API使各种应用软件互相通信成为了可能. 从事API文档写作15年,我亲眼见证了API产品的崛起.各个公司开始搭建平台,希 ...

  9. 以api文档为中心--前后端分开发离新思维

    api文档编写好像很简单,其实不是.一个良好的api文档,需要就有以下内容:接口详细描述,接口参数详细描述,接口返回结果详细描述,容易理解的范例.这些内容其实是不少的,编写过程中还非常单调乏味.再加上 ...

随机推荐

  1. [Python] 06 - Modules --> Packages

    故事背景 一.阶级关系 1. Programs are composed of modules.2. Modules contain statements.3. Statements contain ...

  2. git 删除仓库的文件

    git移除远程仓库某个文件夹 1.比如src/product/ 文件夹 git rm -r --cached "src/product" //执行命令. 2.提交到本地 git c ...

  3. (ecj)Eclipse的Java编译器分析之一——ecj介绍

    Java是一个开放的平台,对于除发布编译器/解释器/基础类库之外,该语言的负责机构更多的是制定一系列标准,任何符合标准的厂商产品均可用于市场投放.甚至包括其编译器及解释器. (比如Hibernate提 ...

  4. io流和序列化

    1.使用File操作文件 public class IoTest { public static void main(String[] args) throws IOException { /* 01 ...

  5. linux 部分系统命令

    在网上看到一些系统命令,贴一记 # uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # ...

  6. mapper.xml

    #{}如果是字符串就不用加引号,否则报错,${}也一样,不是占位符需要加

  7. Adobe Photoshop CS6简单的破解

    由于网站的页面布局和素材准备等等需要用到Photoshop,所以下载了个 Photoshop CS6,写这份破解文档的大佬感觉写的很复杂,看了让人头疼,乱搞中突然发现一个方法可以很快的进行破解操作,我 ...

  8. C#网页采集数据的几种方式(WebClient、WebBrowser和HttpWebRequest/HttpWebResponse)

    一.通过WebClient获取网页内容 这是一种很简单的获取方式,当然,其它的获取方法也很简单.在这里首先要说明的是,如果为了实际项目的效率考虑,需要考虑在函数中分配一个内存区域.大概写法如下 //M ...

  9. 转发一篇好文:36氪翻译自medium的文章: 读书没有 KPI:为什么坚持“一年读 100 本书”没用?

    你只是为了达成所谓的数量目标而读书. 编者按:读书本是一项安静.缓慢的活动,但随着现代社会节奏的加快,信息技术的广泛普及,读书这一行为模式也开始发生了变化.越来越多的人开始碎片化阅读,并且越来越多的文 ...

  10. Codeforces 1032 - A/B/C/D/E - (Undone)

    链接:http://codeforces.com/contest/1032/ 是真的真的真的忍不住想吐槽这题意是真的真的真的读不懂…… A - Kitchen Utensils - [简单数学题] 题 ...