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
|
# File 'lib/vaultoro/basic_api/latest_trades.rb', line 8
def fetch
@errors.clear
@errors << ":since or :count argument is required" unless @since || @count
@errors << ":count argument must be between 1-250" unless @count && @count >= 1 && @count <= 250
return false if @errors.any?
params = {}
params.merge!(since: @since) if @since
params.merge!(count: @count) if @count
response = Client.get("/latesttrades", params)
code = response.code rescue ""
case code
when '200'
hash = JSON.parse(response.body)
@status = 'SUCCESS'
hash.each do |trade|
@list << Trade.new(
transaction_id: trade['tid'],
price: trade['price'].to_f,
amount: trade['amount'].to_f,
time: DateTime.strptime(trade['date'], '%Y-%m-%dT%H:%M:%S.%L%z').to_time.utc
)
end
return true
else
set_errors(response)
return false
end
end
|