class Binance::Spot::WebSocket

Spot Websocket

Constants

BASE_URL

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/binance/spot/websocket.rb, line 11
def initialize(options = {})
  @base_url = options[:base_url] || BASE_URL
  options[:base_url] = @base_url
  super(options)
end

Public Instance Methods

agg_trade(symbol:, callbacks:) click to toggle source

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

@param symbol [String] @see binance-docs.github.io/apidocs/spot/en/#aggregate-trade-streams

# 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) click to toggle source

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

@option symbol [String] @see binance-docs.github.io/apidocs/spot/en/#individual-symbol-book-ticker-streams

# 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:) click to toggle source

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

@param symbol [String] @param speed [String] 1000ms or 100ms @see binance-docs.github.io/apidocs/spot/en/#diff-depth-stream

# 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:) click to toggle source

Kline/Candlestick Streams The Kline/Candlestick Stream push updates to the current klines/candlestick every second. Stream Name: <symbol>@kline_<interval> Update Speed: 2000ms

@param symbol [String] @param interval [String] 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M @see binance-docs.github.io/apidocs/spot/en/#kline-candlestick-streams

# 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) click to toggle source

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

@option symbol [String] @see binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream

# 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:) click to toggle source

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

@param symbol [String] @param levels [Integer] 5, 10, or 20. @param speed [String] 1000ms or 100ms @see binance-docs.github.io/apidocs/spot/en/#partial-book-depth-streams

# 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:) click to toggle source

Subscribe to a stream manually subscribe(stream: “btcusdt@miniTicker”) or subscribe(stream: [“btcusdt@miniTicker”, “ethusdt@miniTicker”])

@param stream [String|Array]

# 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
Also aliased as: user_data
symbol_ticker(callbacks:, symbol: nil) click to toggle source

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

@option symbol [String] @see binance-docs.github.io/apidocs/spot/en/#individual-symbol-ticker-streams

# 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:) click to toggle source

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

@param symbol [String] @see binance-docs.github.io/apidocs/spot/en/#trade-streams

# File lib/binance/spot/websocket.rb, line 36
def trade(symbol:, callbacks:)
  url = "#{@base_url}/ws/#{symbol.downcase}@trade"
  create_connection(url, callbacks)
end
user_data(stream:, callbacks:)
Alias for: subscribe