class Bitfinex::Client
Public Class Methods
new(args = {})
click to toggle source
# File lib/bitfinex/client.rb, line 9 def initialize(args = {}) @api_endpoint = args[:url] ? "#{args[:url]}/v2/" : "https://api.bitfinex.com/v2/" @api_key = args[:api_key] @api_secret = args[:api_secret] end
Private Instance Methods
build_payload(url, params = {}, nonce)
click to toggle source
# File lib/bitfinex/client.rb, line 38 def build_payload(url, params = {}, nonce) payload = {} payload["nonce"] = nonce payload["request"] = url payload.merge!(params) if params Base64.strict_encode64(payload.to_json) end
request(url, options = {})
click to toggle source
# File lib/bitfinex/client.rb, line 17 def request(url, options = {}) body = options || {} nonce = ((Time.now.to_f * 1000).floor * 1000).to_s payload = "/api/v2/#{url}#{nonce}#{body.to_json}" sign = OpenSSL::HMAC.hexdigest("sha384", @api_secret, payload) headers = { 'Content-Type': "application/json", 'Accept': "application/json", 'bfx-nonce': nonce, 'bfx-signature': sign, 'bfx-apikey': @api_key, } response = HTTParty.post( "#{@api_endpoint}#{url}", :body => body.to_json, :headers => headers, ) end
v1_request(url, options = {})
click to toggle source
# File lib/bitfinex/client.rb, line 46 def v1_request(url, options = {}) nonce = ((Time.now.to_f * 1000).floor * 1000).to_s url = "/v1/#{url}" payload = build_payload(url, options, nonce) headers = { "X-BFX-APIKEY" => @api_key, "X-BFX-PAYLOAD" => payload, "X-BFX-SIGNATURE" => OpenSSL::HMAC.hexdigest("sha384", @api_secret, payload), } response = HTTParty.post( "https://api.bitfinex.com#{url}", :headers => headers, ).body end