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.
-
#time ⇒ Object
Check Server Time.
-
#trades(symbol:, **kwargs) ⇒ Object
Recent Trades List.
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
122 123 124 125 126 127 128 129 |
# File 'lib/binance/spot/market.rb', line 122 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
166 167 168 169 170 171 172 173 |
# File 'lib/binance/spot/market.rb', line 166 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
213 214 215 216 217 218 |
# File 'lib/binance/spot/market.rb', line 213 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
63 64 65 66 67 68 69 70 |
# File 'lib/binance/spot/market.rb', line 63 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/binance/spot/market.rb', line 40 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
100 101 102 103 104 105 106 107 |
# File 'lib/binance/spot/market.rb', line 100 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
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/binance/spot/market.rb', line 145 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
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/binance/spot/market.rb', line 228 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
183 184 185 186 187 188 |
# File 'lib/binance/spot/market.rb', line 183 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
198 199 200 201 202 203 |
# File 'lib/binance/spot/market.rb', line 198 def ticker_price(symbol: nil) @session.public_request( path: '/api/v3/ticker/price', params: { symbol: symbol } ) 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
80 81 82 83 84 85 86 87 |
# File 'lib/binance/spot/market.rb', line 80 def trades(symbol:, **kwargs) Binance::Utils::Validation.require_param('symbol', symbol) @session.public_request( path: '/api/v3/trades', params: kwargs.merge(symbol: symbol) ) end |