Class: VaultOfSatoshi::API::Public

Inherits:
Base
  • Object
show all
Defined in:
lib/vault_of_satoshi/api/public.rb

Constant Summary

Constants inherited from Base

Base::ALL_CURRENCIES, Base::CRYPTO_CURRENCIES, Base::FIAT_CURRENCIES

Instance Method Summary collapse

Methods inherited from Base

#inspect

Constructor Details

#initializePublic

Returns a new instance of Public.



5
6
# File 'lib/vault_of_satoshi/api/public.rb', line 5

def initialize
end

Instance Method Details

#orderbook(params = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vault_of_satoshi/api/public.rb', line 25

def orderbook(params = {})
  params.slice!(:order_currency, :payment_currency, :group_orders, :round, :count)
  params[:group_orders] = [1, "1", true, nil].include?(params[:group_orders]) ? 1 : 0
  endpoint = "/public/orderbook"

  response = self.class.get(endpoint, query: params).parsed_response
  raise VaultOfSatoshi::API::Error.new(response["message"]) if response["status"] == "error"

  response["data"]["bids"].map! do |bid_object|
    parse_data(bid_object, currency_objects: [:price, :quantity])
  end
  response["data"]["asks"].map! do |ask_object|
    parse_data(ask_object, currency_objects: [:price, :quantity])
  end
  parse_data(response["data"], timestamps: :timestamp)
end

#ticker(params = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vault_of_satoshi/api/public.rb', line 8

def ticker(params = {})
  params.slice!(:order_currency, :payment_currency)
  endpoint = "/public/ticker"

  response = self.class.get(endpoint, query: params).parsed_response
  raise VaultOfSatoshi::API::Error.new(response["message"]) if response["status"] == "error"

  parse_options = {
    timestamps: :date,
    currency_objects: [
      :opening_price, :closing_price, :min_price, :max_price,
      :average_price, :units_traded, :volume_1day, :volume_7day
    ]
  }
  parse_data(response["data"], parse_options)
end