订阅 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. 设计模式-结构型模式, mvc 模型视图控制器模式(8)

    MVC 模式代表 Model-View-Controller(模型-视图-控制器) 模式.这种模式用于应用程序的分层开发. Model(模型) - 模型代表一个存取数据的对象或 JAVA POJO.它 ...

  2. 相比Redis,Memcached真的过时了吗?

    下面内容来自Redis作者在stackoverflow上的一个回答,对应的问题是<Is memcached a dinosaur in comparison to Redis?>(相比Re ...

  3. oracle学习笔记1(环境搭建)

    学习的开始先剧透一下,本人有点笨,本来想用oracle vbox,装个red hat+oracle,但是虚拟机一直报错,0x00000000内存不能written.所以便想到其他的办法,刚好接触了go ...

  4. react列表数据显示

    react的列表数据一般是用map循环显示的. 使用map注意:map的回调函数为箭头函数时,后面如果加大括号(箭头函数常规编写),必须要有return才可以,如果箭头函数后面没有大括号(箭头函数简写 ...

  5. java.util.HashMap的简单介绍

    1. java.util.HashMap的底层实现是数组+链表. 2. 简介put(key, value)方法的执行过程: 1)通过key值,使用散列算法计算出来一个hash值,用来确定该元素需要存储 ...

  6. 7.13python多进程

    所以引入了     多进程*(异步) 处理效率高 #!/usr/bin/env python #!--*--coding:utf-8 --*-- #!@Time :2018/7/13 19:26 #! ...

  7. ls --help 常用命令

    $ ls --help Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory ...

  8. 170825、SolrCloud 分布式集群部署步骤

    安装软件包准备 apache-tomcat-7.0.54 jdk1.7 solr-4.8.1 zookeeper-3.4.5 注:以上软件都是基于 Linux 环境的 64位 软件,以上软件请到各自的 ...

  9. Python2安装igraph

    前言 igraph是一个进行图计算和社交网络分析的软件包,支持python语言,打算学习igraph,然后应用在自己的项目中. 系统环境 64位win10系统,同时安装了python3.6和pytho ...

  10. 关于form表单排版的技巧

    //此处说明一个对于排版表单的方法将form表单嵌套在table里,因为table是格式化的,所以就不用再手动排版了源码如下 <from action="" method=& ...