币安Binance API Websocket
本文介绍币安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
- Open a stream to wss://stream.binance.com:9443/ws/bnbbtc@depth
 - Buffer the events you receive from the stream
 - Get a depth snapshot from https://www.binance.com/api/v1/depth?symbol=BNBBTC&limit=1000
 - Drop any event where 
uis <=lastUpdateIdin the snapshot - The first processed should have 
U<=lastUpdateId+1 ANDu>=lastUpdateId+1 - While listening to the stream, each new event's 
Ushould be equal to the previous event'su+1 - The data in each event is the absolute quantity for a price level
 - If the quantity is 0, remove the price level
 - Receiving an event that removes a price level that is not in your local order book can happen and is normal.
 
币安Binance API Websocket的更多相关文章
- 币安Binance API
		
本文介绍币安Binance API General API Information The base endpoint is: https://api.binance.com All endpoint ...
 - 火币Huobi API Websocket
		
本文介绍火币Huobi API Websocket WebSocket API简介 WebSocket协议是基于TCP的一种新的网络协议.它实现了客户端与服务器之间在单个 tcp 连接上的全双工通信, ...
 - OKEX API(Websocket)
		
本文介绍OKEX API Websocket WebSocket API for SPOT 开始使用 WebSocket是HTML5一种新的协议(Protocol).它实现了客户端与服务器全双工通信, ...
 - ImCash:币安下架BSV之辩:规则、中立与去中心化
		
一种看法是:一个引用价格数据和执行交易的加密货币交易所,其业务决策往往是在链外发生的,不受制于严格的.类似于准宪法的链上规则的约束,加密货币交易所可以拒绝任何人喜欢的价格和交易,而且这样做并不会损害底 ...
 - python安装包API文档
		
在python开发过程中,经常会使用第三方包,或者内置的包. 那么这些包,具体有哪些选项,有哪些方法,你知道吗?下面介绍一种万能方法. 使用命令:<注意,命令里python显示的API版本是根据 ...
 - 在线聊天室的实现(1)--websocket协议和javascript版的api
		
前言: 大家刚学socket编程的时候, 往往以聊天室作为学习DEMO, 实现简单且上手容易. 该Demo被不同语言实现和演绎, 网上相关资料亦不胜枚举. 以至于很多技术书籍在讲解网络相关的编程时, ...
 - 各大知名区块链交易所链接及API文档链接
		
区块链交易所链接 火币网(Huobi):https://www.huobi.br.com/zh-cn/ API文档:https://github.com/huobiapi/API_Docs/wiki ...
 - webSocket详解
		
WebSocket 实战http://www.ibm.com/developerworks/cn/java/j-lo-WebSocket/index.html 转自IBMdeveloperWorks ...
 - WebSocket 实战
		
http://www.ibm.com/developerworks/cn/java/j-lo-WebSocket/ 本文介绍了 HTML5 WebSocket 的由来,运作机制及客户端和服务端的 AP ...
 
随机推荐
- iOS 图片加载速度极限优化—FastImageCache解析
			
FastImageCache是Path团队开发的一个开源库,用于提升图片的加载和渲染速度,让基于图片的列表滑动起来更顺畅,来看看它是怎么做的.优化点iOS从磁盘加载一张图片,使用UIImageVIew ...
 - osgearth2.8关于RectangleNodeEditor编辑点不可见的问题
			
static_cast<SphereDragger*>(_llDragger)->setColor(osg::Vec4(0,0,1,0)); Alpha写成了0 应该写成 stati ...
 - 普通for循环和增强for循环的区别
			
1.普通for循环:自行维护循环次数,循环体自行维护获取元素的方法: int[] array = new int[]{1,2,3,4,5}; //int[] array ={1,2,3,4,5} ; ...
 - 【Java并发编程五】信号量
			
一.概述 技术信号量用来控制能够同时访问某特定资源的活动的数量,或者同时执行某一给定操作的数据.计数信号量可以用来实现资源池或者给一个容器限定边界. 信号量维护了一个许可集,许可的初始量通过构造函数传 ...
 - nginx+php-fpm 报“File not found.”
			
找网上找了很多帖子,大都是说nginx中的$document_root$换成绝对路径,但是依然不能解决问题 后再把php-fpm配置文件中的 [www]下边的 usr = apache group = ...
 - EXCEL数据匹配:The 'Microsoft.Jet.Oledb.4.0' provider is not registered on the local machin
			
百度的处理结果: 作者:LisenYang http://blog.csdn.net/lisenyang/article/details/52106492 这篇博文里面说的,默认设置修改[启动32应用 ...
 - Linux设备驱动剖析之SPI(二)
			
957至962行,一个SPI控制器用一个master来描述.这里使用SPI核心的spi_alloc_master函数请求分配master.它在drivers/spi/spi.c文件中定义: struc ...
 - 删除sql注入
			
), );--过滤字符串 字符串及之后的数据将被替换为空 set @FilterStr='</title><style>.alx2{'; set @curTable='user ...
 - 【vue基础学习】vue.js开发环境搭建
			
1.安装node.js(http://www.runoob.com/nodejs/nodejs-install-setup.html) 2.基于node.js,利用淘宝npm镜像安装相关依赖 在cmd ...
 - 【WEB前端开发最佳实践系列】CSS篇
			
一.有效组织CSS代码 规划组织CSS代码:组织CSS代码文件,所有的CSS都可以分为2类,通用类和业务类.代码的组织应该把通用类和业务类的代码放在不同的目录中. 模块内部的另一样式规则:样式声明的顺 ...