币安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 ...
随机推荐
- LR 测试http协议xml格式数据接口
Action() { lr_start_transaction("T1"); web_custom_request("xxxxHTTPRequest", &qu ...
- 【Ceisum】Max转GLTF
参考资料:https://blog.csdn.net/u011394175/article/details/78919281 1.在3DsMax中加入COLLADA插件:COLLADA-MAX-PC_ ...
- ArcGIS应用
1.ArcGIS Server发布资源报错:网络资源问题 有可能是跟网络相关的服务没有开启,开启相关服务器后有可能可以解决此问题. 还有可能通过此法解决:开始--控制面板--网络和共享中心--高级共享 ...
- 【PHP代码审计】 那些年我们一起挖掘SQL注入 - 1.什么都没过滤的入门情况
0x01 背景 首先恭喜Seay法师的力作<代码审计:企业级web代码安全架构>,读了两天后深有感触.想了想自己也做审计有2年了,决定写个PHP代码审计实例教程的系列,希望能够帮助到新人更 ...
- Python系统编程笔记
01. 进程与程序 编写完毕的代码,在没有运行的时候,称之为程序 正在运行着的代码,就称为进程 进程是系统分配资源的最小单位. 进程资源包括: 中间变量 代码 计数器 02. 通过os.fork()函 ...
- .vimrc设置说明
在终端下使用vim进行编辑时,默认情况下, 编辑的界面上是没有显示行号.语法高亮度显示.智能缩进等功能的. 为了更好的在vim下进行工作,需要手动设置一个配置文件:.vimrc. 在启动vim时,当前 ...
- no matching function for call to ‘std::basic_string<char>::assign(std::string&, int)
使用string中的assign赋值函数报错,代码为: text0.assign(line,i+); 其中text0与line都为string类型 最后发现assign函数的原型为 string &a ...
- 基于WordNet的英文同义词、近义词相似度评估及代码实现
源码地址:https://github.com/XBWer/WordSimilarity 1.确定要解决的问题及意义 在基于代码片段的分类过程中,由于程序员对数据变量名的选取可能具有一定的规范性,在某 ...
- SharpGL学习笔记(六) 裁剪变换
在OpenGL中,除了视景体定义的6个裁剪平面(上下左右前后)外, 用户还可以定义一个或者多个附加的裁剪平面,以去掉场景中无关的目标. 附加平面裁剪函数原型如下: ClipPlane(OpenGL.G ...
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验十九:SDRAM模块② — 多字读写
实验十九:SDRAM模块② — 多字读写 表示19.1 Mode Register的内容. Mode Register A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A ...