class Bittrex::Request

Constants

BASE_URL

Attributes

api_key[R]
api_secret[R]

Public Class Methods

new(api_key, api_secret) click to toggle source
# File lib/request.rb, line 6
def initialize(api_key, api_secret)
  @api_key = api_key
  @api_secret = api_secret
end

Public Instance Methods

get(path, params = '') click to toggle source
# File lib/request.rb, line 11
def get(path, params = '')
  begin
    nonce = Time.now.to_i
    final_url = "#{BASE_URL}#{path}?apikey=#{api_key}&nonce=#{nonce}&"+params
    hmac_sign = generate_sign(final_url)

    response = HTTParty.get(final_url, headers: { apisign: hmac_sign })
    handle_response response.body
  rescue Exception => e
    nil
  end
end

Private Instance Methods

generate_sign(url) click to toggle source
# File lib/request.rb, line 26
def generate_sign(url)
  OpenSSL::HMAC.hexdigest('sha512', api_secret, url)
end
handle_response(response) click to toggle source
# File lib/request.rb, line 30
def handle_response(response)
  json = JSON.parse(response)
  if json['success']
    json['result']
  else
    puts "Request failed: #{json}"
    json['message']
  end
end