Class: Vaultoro::BasicAPI::OrderBook

Inherits:
Vaultoro::Base show all
Defined in:
lib/vaultoro/basic_api/order_book.rb

Instance Method Summary collapse

Methods inherited from Vaultoro::Base

#inspect

Instance Method Details

#fetchObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vaultoro/basic_api/order_book.rb', line 6

def fetch
  @errors.clear

  response = Client.get('/orderbook', {})
  code = response.code rescue ""

  case code
  when '200'
    hash = JSON.parse(response.body)
    @status = hash['status'].upcase

    if @status == 'SUCCESS'
      hash['data'].each do |orders|
        orders['b'] do |buy|
          @list << Order.new(
            gold_amount: buy['Gold_Amount'].to_f,
            gold_price: buy['Gold_Price'].to_f
          )
        end

        orders['s'] do |sell|
          @list << Order.new(
            gold_amount: buy['Gold_Amount'].to_f,
            gold_price: buy['Gold_Price'].to_f
          )
        end
      end
    else
      set_errors(response)
      return false
    end

    return true
  else
    set_errors(response)
    return false
  end
end