Module: Binance::Client::REST::Public_API

Defined in:
lib/binance/client/rest/public_api.rb

Overview

Public: A Module containing all of the Public API endpoints

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Internal: Create Lambda that returns a new Faraday client instance and add it to the REST class instance variable @api. This is called while a new instance of the REST class is created.

base - The base class that is being extended into.



15
16
17
18
19
20
21
22
23
# File 'lib/binance/client/rest/public_api.rb', line 15

def self.extended(base)
  REST.api[:public] = lambda do
    Faraday.new(url: "#{BASE_URL}/api") do |conn|
      conn.request :json
      conn.response :json, content_type: /\bjson$/
      conn.adapter base.adapter
    end
  end
end

Instance Method Details

#agg_trades(options) ⇒ Object

Public: Retrieve aggregate trade data for the specified symbol

options - The Hash which hosts various REST query params.

:symbol     - The String of which trading pair to retrieve.
:fromId     - The String of which trade ID to fetch from (optional).
:startTime  - The Timestamp of when to get trades from in
              milliseconds (optional).
:endTime    - The Timestamp of when to get trades until in
              milliseconds (optional).
:limit      - The Number of how many trades to request (optional).

Returns a Hash with the request response



100
101
102
# File 'lib/binance/client/rest/public_api.rb', line 100

def agg_trades(options)
  request :public, :get, 'aggTrades', options
end

#all_book_tickersObject

Public: Retrieve all book ticker data for all symbols

Returns a Hash with the request response



161
162
163
# File 'lib/binance/client/rest/public_api.rb', line 161

def all_book_tickers
  request :public, :get, 'bookTicker'
end

#all_pricesObject

Public: Retrieve all price ticker data

Returns a Hash with the request response



144
145
146
# File 'lib/binance/client/rest/public_api.rb', line 144

def all_prices
  request :public, :get, 'price'
end

#book_ticker(options) ⇒ Object

Public: Retrieve best price per quantity on the order book

options - The Hash which hosts various REST query params.

:symbol - The String of which trading pair to retrieve (optional).

Returns a Hash with the request response



154
155
156
# File 'lib/binance/client/rest/public_api.rb', line 154

def book_ticker(options)
  request :public, :get, 'bookTicker', options
end

#depth(options) ⇒ Object

Public: Retrieve depth information for the specified symbol

options - The Hash which hosts various REST query params.

:symbol - The String of which trading pair to retrieve.
:limit  - The Number of how many updates to request (optional).

Returns a Hash with the request response



61
62
63
# File 'lib/binance/client/rest/public_api.rb', line 61

def depth(options)
  request :public, :get, 'depth', options
end

#exchange_infoObject

Public: Retrieve current exchange trading rules and symbol information

Returns a Hash with the request response



42
43
44
# File 'lib/binance/client/rest/public_api.rb', line 42

def exchange_info
  request :public, :get, 'exchangeInfo'
end

#historical_trades(options) ⇒ Object

Public: Retrieve old trade data for the specified symbol

options - The Hash which hosts various REST query params.

:symbol - The String of which trading pair to retrieve.
:limit  - The Number of how many trades to request (optional).
:fromId - The String of which trade ID to fetch from (optional).

Returns a Hash with the request response



84
85
86
# File 'lib/binance/client/rest/public_api.rb', line 84

def historical_trades(options)
  request :user_data, :get, 'historicalTrades', options
end

#klines(options) ⇒ Object

Public: Retrieve kline data for the specified symbol

options - The Hash which hosts various REST query params.

:symbol     - The String of which trading pair to retrieve.
:interval   - The String of which interval to retrieve (optional).
:fromId     - The String of which trade ID to fetch from (optional).
:startTime  - The Timestamp of when to get trades from in
              milliseconds (optional).
:endTime    - The Timestamp of when to get trades until in
              milliseconds (optional).
:limit      - The Number of how many trades to request (optional).

Returns a Hash with the request response



117
118
119
# File 'lib/binance/client/rest/public_api.rb', line 117

def klines(options)
  request :public, :get, 'klines', options
end

#pingObject

Public: Ping the server to test connectivity

Returns a Hash with the request response



28
29
30
# File 'lib/binance/client/rest/public_api.rb', line 28

def ping
  request :public, :get, 'ping'
end

#price(options) ⇒ Object

Public: Retrieve price ticker data for the specified symbol

options - The Hash which hosts various REST query params.

:symbol - The String of which trading pair to retrieve (optional).

Returns a Hash with the request response



137
138
139
# File 'lib/binance/client/rest/public_api.rb', line 137

def price(options)
  request :public, :get, 'price', options
end

#productsObject

Public: Retrieve current exchange asset information. This is an undocumented endpoint.

Returns a Hash with the request response



50
51
52
# File 'lib/binance/client/rest/public_api.rb', line 50

def products
  request :public, :get, 'products'
end

#timeObject

Public: Retrieve the server time in milliseconds

Returns a Hash with the request response



35
36
37
# File 'lib/binance/client/rest/public_api.rb', line 35

def time
  request :public, :get, 'time'
end

#trades(options) ⇒ Object

Public: Retrieve recent trades for the specified symbol

options - The Hash which hosts various REST query params.

:symbol - The String of which trading pair to retrieve.
:limit  - The Number of how many trades to request (optional).

Returns a Hash with the request response



72
73
74
# File 'lib/binance/client/rest/public_api.rb', line 72

def trades(options)
  request :public, :get, 'trades', options
end

#twenty_four_hour(options) ⇒ Object

Public: Retrieve 24 hour ticker price data

options - The Hash which hosts various REST query params.

:symbol - The String of which trading pair to retrieve (optional).

Returns a Hash with the request response



127
128
129
# File 'lib/binance/client/rest/public_api.rb', line 127

def twenty_four_hour(options)
  request :public, :get, '24hr', options
end