本文介绍币安Binance API Websocket

General WSS information

  • The base endpoint is: wss://stream.binance.com:9443
  • Streams can be access either in a single raw stream or a combined stream
  • Raw streams are accessed at /ws/<streamName>
  • Combined streams are accessed at /stream?streams=<streamName1>/<streamName2>/<streamName3>
  • Combined stream events are wrapped as follows: {"stream":"<streamName>","data":<rawPayload>}
  • All symbols for streams are lowercase
  • A single connection to stream.binance.com is only valid for 24 hours; expect to be disconnected at the 24 hour mark

Detailed Stream information

Aggregate Trade Streams

The Aggregate Trade Streams push trade information that is aggregated for a single taker order.

Stream Name: <symbol>@aggTrade

Payload:

{
  "e": "aggTrade",  // Event type
  "E": 123456789,   // Event time
  "s": "BNBBTC",    // Symbol
  "a": 12345,       // Aggregate trade ID
  "p": "0.001",     // Price
  "q": "100",       // Quantity
  "f": 100,         // First trade ID
  "l": 105,         // Last trade ID
  "T": 123456785,   // Trade time
  "m": true,        // Is the buyer the market maker?
  "M": true         // Ignore
}

Trade Streams

The Trade Streams push raw trade information; each trade has a unique buyer and seller.

Stream Name: <symbol>@trade

Payload:

{
  "e": "trade",     // Event type
  "E": 123456789,   // Event time
  "s": "BNBBTC",    // Symbol
  "t": 12345,       // Trade ID
  "p": "0.001",     // Price
  "q": "100",       // Quantity
  "b": 88,          // Buyer order ID
  "a": 50,          // Seller order ID
  "T": 123456785,   // Trade time
  "m": true,        // Is the buyer the market maker?
  "M": true         // Ignore
}

Kline/Candlestick Streams

The Kline/Candlestick Stream push updates to the current klines/candlestick every second.

Kline/Candlestick chart intervals:

m -> minutes; h -> hours; d -> days; w -> weeks; M -> months

  • 1m
  • 3m
  • 5m
  • 15m
  • 30m
  • 1h
  • 2h
  • 4h
  • 6h
  • 8h
  • 12h
  • 1d
  • 3d
  • 1w
  • 1M

Stream Name: <symbol>@kline_<interval>

Payload:

{
  "e": "kline",     // Event type
  "E": 123456789,   // Event time
  "s": "BNBBTC",    // Symbol
  "k": {
    "t": 123400000, // Kline start time
    "T": 123460000, // Kline close time
    "s": "BNBBTC",  // Symbol
    "i": "1m",      // Interval
    "f": 100,       // First trade ID
    "L": 200,       // Last trade ID
    "o": "0.0010",  // Open price
    "c": "0.0020",  // Close price
    "h": "0.0025",  // High price
    "l": "0.0015",  // Low price
    "v": "1000",    // Base asset volume
    "n": 100,       // Number of trades
    "x": false,     // Is this kline closed?
    "q": "1.0000",  // Quote asset volume
    "V": "500",     // Taker buy base asset volume
    "Q": "0.500",   // Taker buy quote asset volume
    "B": "123456"   // Ignore
  }
}

Individual Symbol Mini Ticker Stream

24hr Mini Ticker statistics for a single symbol pushed every second.

Stream Name: <symbol>@miniTicker

Payload:

  {
    "e": "24hrMiniTicker",  // Event type
    "E": 123456789,         // Event time
    "s": "BNBBTC",          // Symbol
    "c": "0.0025",          // Current day's close price
    "o": "0.0010",          // Open price
    "h": "0.0025",          // High price
    "l": "0.0010",          // Low price
    "v": "10000",           // Total traded base asset volume
    "q": "18"               // Total traded quote asset volume
  }

All Market Mini Tickers Stream

24hr Mini Ticker statistics for all symbols that changed in an array pushed every second.

Stream Name: !miniTicker@arr

Payload:

[
  {
    // Same as \<symbol\>@miniTicker payload
  }
]

Individual Symbol Ticker Streams

24hr Ticker statistics for a single symbol pushed every second.

Stream Name: <symbol>@ticker

Payload:

{
  "e": "24hrTicker",  // Event type
  "E": 123456789,     // Event time
  "s": "BNBBTC",      // Symbol
  "p": "0.0015",      // Price change
  "P": "250.00",      // Price change percent
  "w": "0.0018",      // Weighted average price
  "x": "0.0009",      // Previous day's close price
  "c": "0.0025",      // Current day's close price
  "Q": "10",          // Close trade's quantity
  "b": "0.0024",      // Best bid price
  "B": "10",          // Best bid quantity
  "a": "0.0026",      // Best ask price
  "A": "100",         // Best ask quantity
  "o": "0.0010",      // Open price
  "h": "0.0025",      // High price
  "l": "0.0010",      // Low price
  "v": "10000",       // Total traded base asset volume
  "q": "18",          // Total traded quote asset volume
  "O": 0,             // Statistics open time
  "C": 86400000,      // Statistics close time
  "F": 0,             // First trade ID
  "L": 18150,         // Last trade Id
  "n": 18151          // Total number of trades
}

All Market Tickers Stream

24hr Ticker statistics for all symbols that changed in an array pushed every second.

Stream Name: !ticker@arr

Payload:

[
  {
    // Same as <symbol>@ticker payload
  }
]

Partial Book Depth Streams

Top <levels> bids and asks, pushed every second. Valid <levels> are 5, 10, or 20.

Stream Name: <symbol>@depth<levels>

Payload:

{
  "lastUpdateId": 160,  // Last update ID
  "bids": [             // Bids to be updated
    [
      "0.0024",         // Price level to be updated
      "10",             // Quantity
      []                // Ignore
    ]
  ],
  "asks": [             // Asks to be updated
    [
      "0.0026",         // Price level to be updated
      "100",            // Quantity
      []                // Ignore
    ]
  ]
}

Diff. Depth Stream

Order book price and quantity depth updates used to locally manage an order book pushed every second.

Stream Name: <symbol>@depth

Payload:

{
  "e": "depthUpdate", // Event type
  "E": 123456789,     // Event time
  "s": "BNBBTC",      // Symbol
  "U": 157,           // First update ID in event
  "u": 160,           // Final update ID in event
  "b": [              // Bids to be updated
    [
      "0.0024",       // Price level to be updated
      "10",
      []              // Ignore
    ]
  ],
  "a": [              // Asks to be updated
    [
      "0.0026",       // Price level to be updated
      "100",          // Quantity
      []              // Ignore
    ]
  ]
}

How to manage a local order book correctly

  1. Open a stream to wss://stream.binance.com:9443/ws/bnbbtc@depth
  2. Buffer the events you receive from the stream
  3. Get a depth snapshot from https://www.binance.com/api/v1/depth?symbol=BNBBTC&limit=1000
  4. Drop any event where u is <= lastUpdateId in the snapshot
  5. The first processed should have U <= lastUpdateId+1 AND u >= lastUpdateId+1
  6. While listening to the stream, each new event's U should be equal to the previous event's u+1
  7. The data in each event is the absolute quantity for a price level
  8. If the quantity is 0, remove the price level
  9. Receiving an event that removes a price level that is not in your local order book can happen and is normal.

币安Binance API Websocket的更多相关文章

  1. 币安Binance API

    本文介绍币安Binance API General API Information The base endpoint is: https://api.binance.com All endpoint ...

  2. 火币Huobi API Websocket

    本文介绍火币Huobi API Websocket WebSocket API简介 WebSocket协议是基于TCP的一种新的网络协议.它实现了客户端与服务器之间在单个 tcp 连接上的全双工通信, ...

  3. OKEX API(Websocket)

    本文介绍OKEX API Websocket WebSocket API for SPOT 开始使用 WebSocket是HTML5一种新的协议(Protocol).它实现了客户端与服务器全双工通信, ...

  4. ImCash:币安下架BSV之辩:规则、中立与去中心化

    一种看法是:一个引用价格数据和执行交易的加密货币交易所,其业务决策往往是在链外发生的,不受制于严格的.类似于准宪法的链上规则的约束,加密货币交易所可以拒绝任何人喜欢的价格和交易,而且这样做并不会损害底 ...

  5. python安装包API文档

    在python开发过程中,经常会使用第三方包,或者内置的包. 那么这些包,具体有哪些选项,有哪些方法,你知道吗?下面介绍一种万能方法. 使用命令:<注意,命令里python显示的API版本是根据 ...

  6. 在线聊天室的实现(1)--websocket协议和javascript版的api

    前言: 大家刚学socket编程的时候, 往往以聊天室作为学习DEMO, 实现简单且上手容易. 该Demo被不同语言实现和演绎, 网上相关资料亦不胜枚举. 以至于很多技术书籍在讲解网络相关的编程时, ...

  7. 各大知名区块链交易所链接及API文档链接

    区块链交易所链接 火币网(Huobi):https://www.huobi.br.com/zh-cn/ API文档:https://github.com/huobiapi/API_Docs/wiki ...

  8. webSocket详解

    WebSocket 实战http://www.ibm.com/developerworks/cn/java/j-lo-WebSocket/index.html 转自IBMdeveloperWorks ...

  9. WebSocket 实战

    http://www.ibm.com/developerworks/cn/java/j-lo-WebSocket/ 本文介绍了 HTML5 WebSocket 的由来,运作机制及客户端和服务端的 AP ...

随机推荐

  1. linux给当前用户添加环境变量

    比如当前用户为oracel,则添加环境变量操作为: vim  /home/oracel/.bashrc

  2. Ldap 漏洞

    0x00 Ldap安装 官网地址:https://www.userbooster.de/en/download/openldap-for-windows.aspx 在win2008上安装,一路Next ...

  3. Android开发-- 使用ADT23 的一些问题

    在使用最新版ADT 23进行android学习时发现一些问题: 1.通过设置intent的action来启动另外一个activity时,会出现No Activity found to handle I ...

  4. Nginx(十一)-- keepalived简介

    1. 什么是keepalived 基于VRRP(虚拟路由器冗余协议)来实现对web服务的高可用方案. keepalived下载地址:http://download.csdn.net/detail/u0 ...

  5. pojo与DTO的区别

    ational Mapping(对象关系映射)的缩写.通俗点讲,就是将对象与关系数据库绑定,用对象来表示关系数据.在O/R Mapping的世界里,有两个基本的也是重要的东东需要了解,即VO,PO. ...

  6. Spring transaction事务 roll back各种回滚

    Spring的AOP事务管理默认是针对unchecked exception回滚. 也就是默认对RuntimeException()异常极其子类进行事务回滚. Exception作为基类,下面还分ch ...

  7. eclipse cdt运行c程序报错“launch failed,binary not found”

    1. 安装了eclipsecdt版 2. 采用mingw 编译第一个c程序,报错“launch failed,binary not found”.检查是mingw下的bin目录在环境变量里设置错了. ...

  8. Eclipse新建动态web工程项目出现红叉解决方案

    问题描述:之前新建动态web工程一直没有问题,今天新建一个项目后项目名称上突然出现小红叉,子目录文件没有红叉. 解决过程:一开始想到的就是编译器的level设置,调整了一下,仍然没有解决. 然后在标记 ...

  9. IOS多线程之序

    版权声明:原创作品,谢绝转载!否则将追究法律责任.   我们开发的应用基本上都是多线程的,几乎没有不是多线程的应用发布在appstore.首先我们的应用启动会默认有一个主线程,你一直在里面执行很多操作 ...

  10. 剑指offer——49

    丑数 因子只含2,3,5的数称为丑数. 怎么求第K大的丑数呢.K可以为10^7 最简单的做法是,对每个数判断是否为丑数. 复杂度为O( n * log(n) ),理论上是不行的. uglys[i] 来 ...