Module: Binance::Spot::Market
- Included in:
- Binance::Spot
- Defined in:
- lib/binance/spot/market.rb
Overview
This module includes all spot public endpoints, including:
-
server time
-
kline
-
ticker
-
trades
-
orderbook
-
etc
Instance Method Summary collapse
-
#agg_trades(symbol:, **kwargs) ⇒ Object
Compressed/Aggregate Trades List.
-
#avg_price(symbol:) ⇒ Object
Current Average Price.
-
#book_ticker(symbol: nil) ⇒ Object
Symbol Order Book Ticker.
-
#depth(symbol:, **kwargs) ⇒ Object
Order Book.
-
#exchange_info(symbol: nil, symbols: nil, permissions: nil) ⇒ Object
Exchange Information.
-
#historical_trades(symbol:, **kwargs) ⇒ Object
Old Trade Lookup.
-
#klines(symbol:, interval:, **kwargs) ⇒ Object
Kline/Candlestick Data.
-
#ping ⇒ Object
Test Connectivity.
-
#ticker(symbol: nil, symbols: nil, windowSize: '1d') ⇒ Object
Symbol Order Book Ticker.
-
#ticker_24hr(symbol: nil) ⇒ Object
24hr Ticker Price Change Statistics.
-
#ticker_price(symbol: nil) ⇒ Object
Symbol Price Ticker.
-
#ticker_trading_day(symbol: nil, symbols: nil, **kwargs) ⇒ Object
Trading Day Ticker.
-
#time ⇒ Object
Check Server Time.
-
#trades(symbol:, **kwargs) ⇒ Object
Recent Trades List.
-
#ui_klines(symbol:, interval:, **kwargs) ⇒ Object
UIKlines.
Instance Method Details
#agg_trades(symbol:, **kwargs) ⇒ Object
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
124 125 126 127 128 129 130 131 |
# File 'lib/binance/spot/market.rb', line 124 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:) ⇒ Object
Current Average Price
Current average price for a symbol.
GET /api/v3/avgPrice
196 197 198 199 200 201 202 203 |
# File 'lib/binance/spot/market.rb', line 196 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) ⇒ Object
Symbol Order Book Ticker
Best price/qty on the order book for a symbol or symbols.
GET /api/v3/ticker/bookTicker
272 273 274 275 276 277 |
# File 'lib/binance/spot/market.rb', line 272 def book_ticker(symbol: nil) @session.public_request( path: '/api/v3/ticker/bookTicker', params: { symbol: symbol } ) end |
#depth(symbol:, **kwargs) ⇒ Object
Order Book
GET /api/v3/depth
65 66 67 68 69 70 71 72 |
# File 'lib/binance/spot/market.rb', line 65 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, permissions: nil) ⇒ Object
Exchange Information
GET /api/v3/exchangeInfo
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/binance/spot/market.rb', line 42 def exchange_info(symbol: nil, symbols: nil, permissions: nil) if symbols.is_a?(Array) symbols = symbols.map { |v| "%22#{v}%22" }.join(',') symbols = "%5B#{symbols}%5D" end if .is_a?(Array) = .map { |v| "%22#{v}%22" }.join(',') = "%5B#{}%5D" end @session.public_request( path: '/api/v3/exchangeInfo', params: { symbol: symbol, symbols: symbols, permissions: } ) end |
#historical_trades(symbol:, **kwargs) ⇒ Object
Old Trade Lookup
X-MBX-APIKEY required
GET /api/v3/historicalTrades
102 103 104 105 106 107 108 109 |
# File 'lib/binance/spot/market.rb', line 102 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) ⇒ Object
Kline/Candlestick Data
Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
GET /api/v3/klines
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/binance/spot/market.rb', line 148 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 ⇒ Object
Test Connectivity
GET /api/v3/ping
19 20 21 |
# File 'lib/binance/spot/market.rb', line 19 def ping @session.public_request(path: '/api/v3/ping') end |
#ticker(symbol: nil, symbols: nil, windowSize: '1d') ⇒ Object
Symbol Order Book Ticker
Best price/qty on the order book for a symbol or symbols.
GET /api/v3/ticker/bookTicker
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/binance/spot/market.rb', line 287 def ticker(symbol: nil, symbols: nil, windowSize: '1d') raise Binance::DuplicatedParametersError.new('symbol', 'symbols') unless symbols.nil? || symbol.nil? params = { symbol: symbol.upcase } if symbol if symbols symbols = symbols.map { |s| "\"#{s}\"" }.join(',') params = { symbols: "\[#{symbols}\]".upcase } end params[:windowSize] = windowSize @session.public_request( path: '/api/v3/ticker', params: params ) end |
#ticker_24hr(symbol: nil) ⇒ Object
24hr Ticker Price Change Statistics
24 hour rolling window price change statistics. Careful when accessing this with no symbol.
GET /api/v3/ticker/24hr
213 214 215 216 217 218 |
# File 'lib/binance/spot/market.rb', line 213 def ticker_24hr(symbol: nil) @session.public_request( path: '/api/v3/ticker/24hr', params: { symbol: symbol } ) end |
#ticker_price(symbol: nil) ⇒ Object
Symbol Price Ticker
Latest price for a symbol or symbols.
GET /api/v3/ticker/price
257 258 259 260 261 262 |
# File 'lib/binance/spot/market.rb', line 257 def ticker_price(symbol: nil) @session.public_request( path: '/api/v3/ticker/price', params: { symbol: symbol } ) end |
#ticker_trading_day(symbol: nil, symbols: nil, **kwargs) ⇒ Object
Trading Day Ticker
Price change statistics for a trading day.
GET /api/v3/ticker/tradingDay
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/binance/spot/market.rb', line 232 def ticker_trading_day(symbol: nil, symbols: nil, **kwargs) raise Binance::DuplicatedParametersError.new('symbol', 'symbols') unless symbols.nil? || symbol.nil? if symbols symbols = symbols.map { |s| "\"#{s}\"" }.join(',') symbols = { symbols: "\[#{symbols}\]".upcase } end @session.public_request( path: '/api/v3/ticker/tradingDay', params: kwargs.merge( symbol: symbol, symbols: symbols ) ) end |
#time ⇒ Object
Check Server Time
GET /api/v3/time
28 29 30 |
# File 'lib/binance/spot/market.rb', line 28 def time @session.public_request(path: '/api/v3/time') end |
#trades(symbol:, **kwargs) ⇒ Object
Recent Trades List
GET /api/v3/trades
82 83 84 85 86 87 88 89 |
# File 'lib/binance/spot/market.rb', line 82 def trades(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @session.public_request( path: '/api/v3/trades', params: kwargs.merge(symbol: symbol) ) end |
#ui_klines(symbol:, interval:, **kwargs) ⇒ Object
UIKlines
uiKlines return modified kline data, optimized for presentation of candlestick charts
GET /api/v3/uiKlines
175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/binance/spot/market.rb', line 175 def ui_klines(symbol:, interval:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) Binance::Utils::Validation.require_param('interval', interval) @session.public_request( path: '/api/v3/uiKlines', params: kwargs.merge( symbol: symbol, interval: interval ) ) end |