class Binance::Client::REST
Constants
- BASE_URL
- ENDPOINTS
- METHODS
- SignRequestMiddleware
Sign the query string using HMAC(sha-256) and appends to query string
- TimestampRequestMiddleware
Generate a timestamp in milliseconds and append to query string
Public Class Methods
add_query_param(query, key, value)
click to toggle source
# File lib/binance/client/rest.rb, line 34 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
new(api_key: '', secret_key: '', adapter: Faraday.default_adapter)
click to toggle source
# File lib/binance/client/rest.rb, line 14 def initialize(api_key: '', secret_key: '', adapter: Faraday.default_adapter) @clients = {} @clients[:public] = public_client adapter @clients[:verified] = verified_client api_key, adapter @clients[:signed] = signed_client api_key, secret_key, adapter @clients[:withdraw] = withdraw_client api_key, secret_key, adapter @clients[:public_withdraw] = public_withdraw_client adapter end
Public Instance Methods
camelize(str)
click to toggle source
# File lib/binance/client/rest.rb, line 40 def camelize(str) str.split('_') .map.with_index { |word, i| i.zero? ? word : word.capitalize }.join end
public_client(adapter)
click to toggle source
# File lib/binance/client/rest/clients.rb, line 6 def public_client(adapter) Faraday.new(url: "#{BASE_URL}/api") do |conn| conn.request :json conn.response :json, content_type: /\bjson$/ conn.adapter adapter end end
public_withdraw_client(adapter)
click to toggle source
# File lib/binance/client/rest/clients.rb, line 33 def public_withdraw_client(adapter) Faraday.new(url: "#{BASE_URL}/wapi") do |conn| conn.request :json conn.response :json, content_type: /\bjson$/ conn.adapter adapter end end
signed_client(api_key, secret_key, adapter)
click to toggle source
# File lib/binance/client/rest/clients.rb, line 22 def signed_client(api_key, secret_key, adapter) Faraday.new(url: "#{BASE_URL}/api") do |conn| conn.request :json conn.response :json, content_type: /\bjson$/ conn.headers['X-MBX-APIKEY'] = api_key conn.use TimestampRequestMiddleware conn.use SignRequestMiddleware, secret_key conn.adapter adapter end end
verified_client(api_key, adapter)
click to toggle source
# File lib/binance/client/rest/clients.rb, line 14 def verified_client(api_key, adapter) Faraday.new(url: "#{BASE_URL}/api") do |conn| conn.response :json, content_type: /\bjson$/ conn.headers['X-MBX-APIKEY'] = api_key conn.adapter adapter end end
withdraw_client(api_key, secret_key, adapter)
click to toggle source
# File lib/binance/client/rest/clients.rb, line 41 def withdraw_client(api_key, secret_key, adapter) Faraday.new(url: "#{BASE_URL}/wapi") do |conn| conn.request :url_encoded conn.response :json, content_type: /\bjson$/ conn.headers['X-MBX-APIKEY'] = api_key conn.use TimestampRequestMiddleware conn.use SignRequestMiddleware, secret_key conn.adapter adapter end end