module Binance::Spot::Market

This module includes all spot public endpoints, including:

@see binance-docs.github.io/apidocs/spot/en/#market-data-endpoints

Public Instance Methods

agg_trades(symbol:, **kwargs) click to toggle source

Compressed/Aggregate Trades List

Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.

GET /api/v3/aggTrades

@param symbol [String] the symbol @param kwargs [Hash] @option kwargs [Integer] :startTime Timestamp in ms to get aggregate trades from INCLUSIVE. @option kwargs [Integer] :endTime Timestamp in ms to get aggregate trades until INCLUSIVE. @option kwargs [Integer] :fromId Trade id to fetch from. Default gets most recent trades. @option kwargs [Integer] :limit Default 500; max 1000. @see binance-docs.github.io/apidocs/spot/en/#compressed-aggregate-trades-list

# File lib/binance/spot/market.rb, line 121
def agg_trades(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.public_request(
    path: '/api/v3/aggTrades',
    params: kwargs.merge(symbol: symbol)
  )
end
avg_price(symbol:) click to toggle source

Current Average Price

Current average price for a symbol.

GET /api/v3/avgPrice

@param symbol [String] the symbol @see binance-docs.github.io/apidocs/spot/en/#current-average-price

# File lib/binance/spot/market.rb, line 165
def avg_price(symbol:)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.public_request(
    path: '/api/v3/avgPrice',
    params: { symbol: symbol }
  )
end
book_ticker(symbol: nil) click to toggle source

Symbol Order Book Ticker

Best price/qty on the order book for a symbol or symbols.

GET /api/v3/ticker/bookTicker

@param symbol [String] the symbol @see binance-docs.github.io/apidocs/spot/en/#symbol-order-book-ticker

# File lib/binance/spot/market.rb, line 212
def book_ticker(symbol: nil)
  @session.public_request(
    path: '/api/v3/ticker/bookTicker',
    params: { symbol: symbol }
  )
end
depth(symbol:, **kwargs) click to toggle source

Order Book

GET /api/v3/depth

@param symbol [String] the symbol @param kwargs [Hash] @option kwargs [Integer] :limit Default 100; max 1000. Valid limits:[5, 10, 20, 50, 100, 500, 1000, 5000] @see binance-docs.github.io/apidocs/spot/en/#order-book

# File lib/binance/spot/market.rb, line 62
def depth(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.public_request(
    path: '/api/v3/depth',
    params: kwargs.merge(symbol: symbol)
  )
end
exchange_info(symbol: nil, symbols: nil) click to toggle source

Exchange Information

GET /api/v3/exchangeInfo

@option kwargs [string] :symbol @option kwargs [string] :symbols @see binance-docs.github.io/apidocs/spot/en/#exchange-information

# File lib/binance/spot/market.rb, line 39
def exchange_info(symbol: nil, symbols: nil)
  if symbols.is_a?(Array)
    symbols = symbols.map { |v| "%22#{v}%22" }.join(',')
    symbols = "%5B#{symbols}%5D"
  end
  @session.public_request(
    path: '/api/v3/exchangeInfo',
    params:
      {
        symbol: symbol,
        symbols: symbols
      }
  )
end
historical_trades(symbol:, **kwargs) click to toggle source

Old Trade Lookup

X-MBX-APIKEY required

GET /api/v3/historicalTrades

@param symbol [String] the symbol @param kwargs [Hash] @option kwargs [Integer] :limit Default 500; max 1000. @option kwargs [Integer] :fromId Trade id to fetch from. Default gets most recent trades. @see binance-docs.github.io/apidocs/spot/en/#old-trade-lookup-market_data

# File lib/binance/spot/market.rb, line 99
def historical_trades(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.public_request(
    path: '/api/v3/historicalTrades',
    params: kwargs.merge(symbol: symbol)
  )
end
klines(symbol:, interval:, **kwargs) click to toggle source

Kline/Candlestick Data

Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.

GET /api/v3/klines

@param symbol [String] the symbol @param interval [String] interval @param kwargs [Hash] @option kwargs [Integer] :startTime Timestamp in ms to get aggregate trades from INCLUSIVE. @option kwargs [Integer] :endTime Timestamp in ms to get aggregate trades until INCLUSIVE. @option kwargs [Integer] :limit Default 500; max 1000. @see binance-docs.github.io/apidocs/spot/en/#kline-candlestick-data

# File lib/binance/spot/market.rb, line 144
def klines(symbol:, interval:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)
  Binance::Utils::Validation.require_param('interval', interval)

  @session.public_request(
    path: '/api/v3/klines',
    params: kwargs.merge(
      symbol: symbol,
      interval: interval
    )
  )
end
ping() click to toggle source

Test Connectivity

GET /api/v3/ping

@see binance-docs.github.io/apidocs/spot/en/#test-connectivity

# File lib/binance/spot/market.rb, line 19
def ping
  @session.public_request(path: '/api/v3/ping')
end
ticker_24hr(symbol: nil) click to toggle source

24hr Ticker Price Change Statistics

24 hour rolling window price change statistics. Careful when accessing this with no symbol.

GET /api/v3/ticker/24hr

@param symbol [String] the symbol @see binance-docs.github.io/apidocs/spot/en/#24hr-ticker-price-change-statistics

# File lib/binance/spot/market.rb, line 182
def ticker_24hr(symbol: nil)
  @session.public_request(
    path: '/api/v3/ticker/24hr',
    params: { symbol: symbol }
  )
end
ticker_price(symbol: nil) click to toggle source

Symbol Price Ticker

Latest price for a symbol or symbols.

GET /api/v3/ticker/price

@param symbol [String] the symbol @see binance-docs.github.io/apidocs/spot/en/#symbol-price-ticker

# File lib/binance/spot/market.rb, line 197
def ticker_price(symbol: nil)
  @session.public_request(
    path: '/api/v3/ticker/price',
    params: { symbol: symbol }
  )
end
time() click to toggle source

Check Server Time

GET /api/v3/time

@see binance-docs.github.io/apidocs/spot/en/#check-server-time

# File lib/binance/spot/market.rb, line 28
def time
  @session.public_request(path: '/api/v3/time')
end
trades(symbol:, **kwargs) click to toggle source

Recent Trades List

GET /api/v3/trades

@param symbol [String] the symbol @param kwargs [Hash] @option kwargs [Integer] :limit Default 500; max 1000. @see binance-docs.github.io/apidocs/spot/en/#recent-trades-list

# File lib/binance/spot/market.rb, line 79
def trades(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.public_request(
    path: '/api/v3/trades',
    params: kwargs.merge(symbol: symbol)
  )
end