Class: Binance::Client::REST
- Inherits:
-
Object
- Object
- Binance::Client::REST
- Defined in:
- lib/binance/client/rest.rb,
lib/binance/client/rest/public_api.rb,
lib/binance/client/rest/account_api.rb,
lib/binance/client/rest/withdraw_api.rb,
lib/binance/client/rest/api_endpoints.rb,
lib/binance/client/rest/sign_request_middleware.rb,
lib/binance/client/rest/timestamp_request_middleware.rb
Overview
Provides low level methods for Binance APIs via their REST interface
Defined Under Namespace
Modules: Account_API, Public_API, Withdraw_API Classes: SignRequestMiddleware, TimestampRequestMiddleware
Constant Summary collapse
- BASE_URL =
'https://www.binance.com'.freeze
- API_ENDPOINTS =
{ # Public API Endpoints 'ping' => 'v1/ping', 'time' => 'v1/time', 'exchangeInfo' => 'v1/exchangeInfo', 'products' => '/exchange/public/products', 'depth' => 'v1/depth', 'trades' => 'v1/trades', 'historicalTrades' => 'v1/historicalTrades', 'aggTrades' => 'v1/aggTrades', 'klines' => 'v1/klines', '24hr' => 'v1/ticker/24hr', 'price' => 'v3/ticker/price', 'bookTicker' => 'v3/ticker/bookTicker', # Account API Endpoints 'order' => 'v3/order', 'order/test' => 'v3/order/test', 'openOrders' => 'v3/openOrders', 'allOrders' => 'v3/allOrders', 'account' => 'v3/account', 'myTrades' => 'v3/myTrades', # Withdraw API Endpoints 'withdraw' => 'v3/withdraw.html', 'depositHistory' => 'v3/depositHistory.html', 'withdrawHistory' => 'v3/withdrawHistory.html', 'depositAddress' => 'v3/depositAddress.html' }.freeze
Class Attribute Summary collapse
-
.api ⇒ Object
Returns the value of attribute api.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(api_key: '', secret_key: '') ⇒ REST
constructor
A new instance of REST.
- #request(api, method, endpoint, options = {}) ⇒ Object
Constructor Details
#initialize(api_key: '', secret_key: '') ⇒ REST
Returns a new instance of REST.
23 24 25 26 27 28 29 30 |
# File 'lib/binance/client/rest.rb', line 23 def initialize(api_key: '', secret_key: '') @api_key = api_key @secret_key = secret_key extend Public_API extend Account_API extend Withdraw_API end |
Class Attribute Details
.api ⇒ Object
Returns the value of attribute api.
18 19 20 |
# File 'lib/binance/client/rest.rb', line 18 def api @api end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
21 22 23 |
# File 'lib/binance/client/rest.rb', line 21 def api_key @api_key end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
21 22 23 |
# File 'lib/binance/client/rest.rb', line 21 def secret_key @secret_key end |
Class Method Details
.add_query_param(query, key, value) ⇒ Object
42 43 44 45 46 |
# File 'lib/binance/client/rest.rb', line 42 def self.add_query_param(query, key, value) query = query.to_s query << '&' unless query.empty? query << "#{Faraday::Utils.escape key}=#{Faraday::Utils.escape value}" end |
Instance Method Details
#request(api, method, endpoint, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/binance/client/rest.rb', line 32 def request(api, method, endpoint, = {}) conn = REST.api[api].call response = conn.send(method) do |req| req.url API_ENDPOINTS[endpoint] req.params.merge! end response.body end |