Class: Binance::Spot::WebSocket
- Inherits:
-
WebSocketBase
- Object
- WebSocketBase
- Binance::Spot::WebSocket
- Defined in:
- lib/binance/spot/websocket.rb
Overview
Spot Websocket
Constant Summary collapse
- BASE_URL =
'wss://stream.binance.com:9443'
Instance Method Summary collapse
-
#agg_trade(symbol:, callbacks:) ⇒ Object
Aggregate Trade Streams The Aggregate Trade Streams push trade information that is aggregated for a single taker order.
-
#book_ticker(callbacks:, symbol: nil) ⇒ Object
Individual Symbol Book Ticker Streams or All Book Tickers Stream Pushes any update to the best bid or ask’s price or quantity in real-time for a specified symbol.
-
#diff_book_depth(symbol:, speed:, callbacks:) ⇒ Object
Diff.
-
#initialize(options = {}) ⇒ WebSocket
constructor
A new instance of WebSocket.
-
#kline(symbol:, interval:, callbacks:) ⇒ Object
Kline/Candlestick Streams The Kline/Candlestick Stream push updates to the current klines/candlestick every second.
-
#mini_ticker(callbacks:, symbol: nil) ⇒ Object
Individual Symbol Mini Ticker Stream or All Market Mini Tickers Stream 24hr rolling window mini-ticker statistics.
-
#partial_book_depth(symbol:, levels:, speed:, callbacks:) ⇒ Object
Partial Book Depth Streams Top bids and asks, Valid are 5, 10, or 20.
-
#subscribe(stream:, callbacks:) ⇒ Object
(also: #user_data)
Subscribe to a stream manually subscribe(stream: “btcusdt@miniTicker”) or subscribe(stream: [“btcusdt@miniTicker”, “ethusdt@miniTicker”]).
-
#symbol_ticker(callbacks:, symbol: nil) ⇒ Object
Individual Symbol Ticker Streams or All Market Tickers Stream 24hr rollwing window ticker statistics for a single symbol.
-
#trade(symbol:, callbacks:) ⇒ Object
Trade Streams The Trade Streams push raw trade information; each trade has a unique buyer and seller.
Methods inherited from WebSocketBase
#create_connection, #subscribe_to
Constructor Details
Instance Method Details
#agg_trade(symbol:, callbacks:) ⇒ Object
Aggregate Trade Streams The Aggregate Trade Streams push trade information that is aggregated for a single taker order. Stream Name: <symbol>@aggTrade Update Speed: Real-time
24 25 26 27 |
# File 'lib/binance/spot/websocket.rb', line 24 def agg_trade(symbol:, callbacks:) url = "#{@base_url}/ws/#{symbol.downcase}@aggTrade" create_connection(url, callbacks) end |
#book_ticker(callbacks:, symbol: nil) ⇒ Object
Individual Symbol Book Ticker Streams or All Book Tickers Stream Pushes any update to the best bid or ask’s price or quantity in real-time for a specified symbol. Stream Name: <symbol>@bookTicker or !bookTicker Update Speed: Real-time
93 94 95 96 97 98 99 100 |
# File 'lib/binance/spot/websocket.rb', line 93 def book_ticker(callbacks:, symbol: nil) url = if symbol.nil? "#{@base_url}/ws/!bookTicker" else "#{@base_url}/ws/#{symbol.downcase}@bookTicker" end create_connection(url, callbacks) end |
#diff_book_depth(symbol:, speed:, callbacks:) ⇒ Object
Diff. Depth Stream Top bids and asks, Valid are 5, 10, or 20. Stream Name: <symbol>@depth<levels> OR <symbol>@depth<levels>@100ms. Update Speed: 1000ms or 100ms
124 125 126 127 |
# File 'lib/binance/spot/websocket.rb', line 124 def diff_book_depth(symbol:, speed:, callbacks:) url = "#{@base_url}/ws/#{symbol.downcase}@depth@#{speed}" create_connection(url, callbacks) end |
#kline(symbol:, interval:, callbacks:) ⇒ Object
Kline/Candlestick Streams The Kline/Candlestick Stream push updates to the current klines/candlestick every second. Stream Name: <symbol>@kline_<interval> Update Speed: 2000ms
49 50 51 52 |
# File 'lib/binance/spot/websocket.rb', line 49 def kline(symbol:, interval:, callbacks:) url = "#{@base_url}/ws/#{symbol.downcase}@kline_#{interval}" create_connection(url, callbacks) end |
#mini_ticker(callbacks:, symbol: nil) ⇒ Object
Individual Symbol Mini Ticker Stream or All Market Mini Tickers Stream 24hr rolling window mini-ticker statistics. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs. Stream Name: <symbol>@miniTicker or !miniTicker@arr Update Speed: 1000ms
61 62 63 64 65 66 67 68 |
# File 'lib/binance/spot/websocket.rb', line 61 def mini_ticker(callbacks:, symbol: nil) url = if symbol.nil? "#{@base_url}/ws/!miniTicker@arr" else "#{@base_url}/ws/#{symbol.downcase}@miniTicker" end create_connection(url, callbacks) end |
#partial_book_depth(symbol:, levels:, speed:, callbacks:) ⇒ Object
Partial Book Depth Streams Top bids and asks, Valid are 5, 10, or 20. Stream Name: <symbol>@depth<levels> OR <symbol>@depth<levels>@100ms. Update Speed: 1000ms or 100ms
111 112 113 114 |
# File 'lib/binance/spot/websocket.rb', line 111 def partial_book_depth(symbol:, levels:, speed:, callbacks:) url = "#{@base_url}/ws/#{symbol.downcase}@depth#{levels}@#{speed}" create_connection(url, callbacks) end |
#subscribe(stream:, callbacks:) ⇒ Object Also known as: user_data
Subscribe to a stream manually subscribe(stream: “btcusdt@miniTicker”) or subscribe(stream: [“btcusdt@miniTicker”, “ethusdt@miniTicker”])
134 135 136 137 138 139 140 141 142 |
# File 'lib/binance/spot/websocket.rb', line 134 def subscribe(stream:, callbacks:) url = if stream.is_a?(Array) "#{@base_url}/stream?streams=#{stream.join('/')}" else "#{@base_url}/ws/#{stream}" end subscribe_to(url, callbacks) end |
#symbol_ticker(callbacks:, symbol: nil) ⇒ Object
Individual Symbol Ticker Streams or All Market Tickers Stream 24hr rollwing window ticker statistics for a single symbol. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs. Stream Name: <symbol>@ticker or !ticker@arr Update Speed: 1000ms
77 78 79 80 81 82 83 84 |
# File 'lib/binance/spot/websocket.rb', line 77 def symbol_ticker(callbacks:, symbol: nil) url = if symbol.nil? "#{@base_url}/ws/!ticker@arr" else "#{@base_url}/ws/#{symbol.downcase}@ticker" end create_connection(url, callbacks) end |
#trade(symbol:, callbacks:) ⇒ Object
Trade Streams The Trade Streams push raw trade information; each trade has a unique buyer and seller. Stream Name: <symbol>@trade Update Speed: Real-time
36 37 38 39 |
# File 'lib/binance/spot/websocket.rb', line 36 def trade(symbol:, callbacks:) url = "#{@base_url}/ws/#{symbol.downcase}@trade" create_connection(url, callbacks) end |