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.
-
#avg_price(symbol:, callbacks:) ⇒ Object
Average Price Average price streams push changes in the average price over a fixed time interval.
-
#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 for UTC 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.
-
#rolling_window_ticker(symbol:, windowSize:, callbacks:) ⇒ Object
Individual Symbol Rolling Window Statistics Streams Rolling window ticker statistics for a single symbol, computed over multiple windows.
-
#rolling_window_ticker_all_symbols(windowSize:, callbacks:) ⇒ Object
All Market Rolling Window Statistics Streams Rolling window ticker statistics for all market symbols, computed over multiple windows.
-
#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:
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 |
#avg_price(symbol:, callbacks:) ⇒ Object
Average Price
Average price streams push changes in the average price over a fixed time interval.
Stream Name:
109 110 111 112 |
# File 'lib/binance/spot/websocket.rb', line 109 def avg_price(symbol:, callbacks:) url = "#{@base_url}/ws/#{symbol.downcase}@avgPrice" 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:
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:
136 137 138 139 |
# File 'lib/binance/spot/websocket.rb', line 136 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 for UTC
The Kline/Candlestick Stream push updates to the current klines/candlestick every second.
Stream Name:
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:
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:
123 124 125 126 |
# File 'lib/binance/spot/websocket.rb', line 123 def partial_book_depth(symbol:, levels:, speed:, callbacks:) url = "#{@base_url}/ws/#{symbol.downcase}@depth#{levels}@#{speed}" create_connection(url, callbacks) end |
#rolling_window_ticker(symbol:, windowSize:, callbacks:) ⇒ Object
Individual Symbol Rolling Window Statistics Streams
Rolling window ticker statistics for a single symbol, computed over multiple windows.
Stream Name:
148 149 150 151 |
# File 'lib/binance/spot/websocket.rb', line 148 def rolling_window_ticker(symbol:, windowSize:, callbacks:) url = "#{@base_url}/ws/#{symbol.downcase}@ticker_#{windowSize}" create_connection(url, callbacks) end |
#rolling_window_ticker_all_symbols(windowSize:, callbacks:) ⇒ Object
All Market Rolling Window Statistics Streams
Rolling window ticker statistics for all market symbols, computed over multiple windows. Note that only tickers that have changed will be present in the array.
Stream Name: !ticker_
160 161 162 163 |
# File 'lib/binance/spot/websocket.rb', line 160 def rolling_window_ticker_all_symbols(windowSize:, callbacks:) url = "#{@base_url}/ws/!ticker_#{windowSize}@arr" 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"])
170 171 172 173 174 175 176 177 178 |
# File 'lib/binance/spot/websocket.rb', line 170 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:
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:
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 |