-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.rb
59 lines (48 loc) · 1.71 KB
/
check.rb
1
2
3
4
5
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'mexbt'
require 'active_support/core_ext/numeric/time'
class Check
include Mexbt
p "Hello"
p "How has the BTCMXN price changed over the last hour? - press 1"
p "How has the BTCMXN price changed over the last day? - press 2"
p "How has the BTCMXN price changed over the last week?? - press 3"
p "Quit? - press q"
prompt = "> "
while input = gets.chomp # loop while getting user input
case input
when "1"
puts "last hour variation - between " + (Time.now - 1.hour).to_s + " to " + (Time.now).to_s
trades = Mexbt.trades_by_date(from: (Time.now - 1.hour).to_i, to: Time.now.to_time.to_i)
if (trades[:trades].size >= 2)
variance = trades.first.px - trades.last.px
puts variance.to_s + "%"
else
puts "0%"
end
when "2"
puts "last day variation - between " + (Time.now - 1.day).to_s + " to " + (Time.now).to_s
trades = Mexbt.trades_by_date(from: (Time.now - 1.day).to_i, to: Time.now.to_time.to_i)
if (trades[:trades].size >= 2)
variance = trades.first.px - trades.last.px
puts variance.to_s + "%"
else
puts "0%"
end
when "3"
puts "last week variation - between " + (Time.now - 1.week).to_s + " to " + (Time.now).to_s
trades = Mexbt.trades_by_date(from: (Time.now - 1.week).to_i, to: Time.now.to_time.to_i)
if (trades[:trades].size >= 2)
variance = trades.first.px - trades.last.px
puts variance.to_s + "%"
else
puts "0%"
end
when "quit"
puts "Quiting"
break # and again
else
puts "Please type either 1,2,3 or quit"
end
print prompt # print the prompt, so the user knows to re-enter input
end
end