Class: Vaultoro::TradingAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/vaultoro/trading_api/client.rb

Class Method Summary collapse

Class Method Details

.get(endpoint, params = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vaultoro/trading_api/client.rb', line 9

def self.get(endpoint, params = {})
  begin
    uri = URI.parse([Vaultoro.api_uri, "/#{Vaultoro.api_version.to_s}", endpoint].join)
    params.merge!(nonce: nonce, apikey: Vaultoro.api_key)
    uri.query = URI.encode_www_form(params)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = uri.scheme == 'https'
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    headers.merge!("X-Signature" => signature)
    request = Net::HTTP::Get.new(uri, headers)
    response = http.request(request)
  rescue StandardError => error
    puts "Request failed (#{error.message})"
  end
end

.post(endpoint, params = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vaultoro/trading_api/client.rb', line 25

def self.post(endpoint, params = {})
  begin
    uri = URI.parse([Vaultoro.api_uri, endpoint].join)
    params.merge!(nonce: nonce, apikey: Vaultoro.api_key)
    uri.query = URI.encode_www_form(params)
    # body = URI.encode_www_form(params)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = uri.scheme == 'https'
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    headers.merge!("X-Signature" => signature)
    request = Net::HTTP::Post.new(uri, headers)
    request.add_field "Content-Type", "application/x-www-form-urlencoded"
    # request.body = body
    response = http.request(request)
  rescue StandardError => error
    puts "Request failed (#{error.message})"
  end
end