Class: Vaultoro::BasicAPI::BidAsk

Inherits:
Vaultoro::Base show all
Defined in:
lib/vaultoro/basic_api/bid_ask.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
# File 'lib/vaultoro/basic_api/bid_ask.rb', line 6

def fetch
  @errors.clear

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

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

    hash['bids'].each do |bid|
      @list << PriceVolume.new(type: 'bid', price: bid[0].to_f, volume: bid[1].to_f)
    end

    hash['asks'].each do |ask|
      @list << PriceVolume.new(type: 'ask', price: bid[0].to_f, volume: bid[1].to_f)
    end

    unless @status == 'SUCCESS'
      set_errors(response)
      return false
    end

    return true
  else
    set_errors(response)
    return false
  end
end