watchcow 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/watchcow.rb +0 -1
- data/lib/watchcow/client.rb +0 -83
- data/lib/watchcow/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48656fac82cae2397bc0af466760d5cbb65bbdc561c37aa2238a4b74a3b182ef
|
4
|
+
data.tar.gz: e2c550f8675ebef543e6e1a4899a25fc8154041dd4241068016af66fcb006c8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa6bf2c23486c621ef9c2926ac867ff40704c81063a316feffcb9255c50623c9647b8bd5e1238edf57b335be3fee3eb650aab8eebb0432cbdd9d6e50eae69db1
|
7
|
+
data.tar.gz: 7b68b55e20d5667e4e2ecd25f007b9462f117ec8005a12061b1f50112658b29b117b1da8170d4e1a7b7d9b376eaabd6df68dc310dc94bbdcff243b15eca3b1db
|
data/lib/watchcow.rb
CHANGED
data/lib/watchcow/client.rb
CHANGED
@@ -3,9 +3,6 @@ require 'watchcow/contract_info'
|
|
3
3
|
require 'watchcow/market_depth'
|
4
4
|
require 'active_support'
|
5
5
|
require 'watchcow/rate'
|
6
|
-
# require 'watchcow/output'
|
7
|
-
|
8
|
-
# $redis = Redis.new(url: ENV["REDIS_URL"] || "redis://localhost:6379/0")
|
9
6
|
|
10
7
|
module Watchcow
|
11
8
|
class Client
|
@@ -22,86 +19,6 @@ module Watchcow
|
|
22
19
|
nw_list: nw_list,
|
23
20
|
cw_list: cw_list
|
24
21
|
}
|
25
|
-
# mark! best_arr_cq
|
26
|
-
# # CQ
|
27
|
-
# coin = best_cq.dig(:coin)
|
28
|
-
# best_margin = "annual margin: #{best_cq.dig(:margin)}%"
|
29
|
-
# days_remained = "days remained: #{best_cq.dig(:days)}"
|
30
|
-
# expected_margin = "expected margin: #{best_cq.dig(:expected_margin)}%"
|
31
|
-
# real_margin = "landed margin: #{best_cq.dig(:real_margin_expected)}%"
|
32
|
-
# puts "---"
|
33
|
-
# puts "CQ"
|
34
|
-
# cq_string = "#{coin}, #{best_margin}, #{days_remained}, #{expected_margin}, #{real_margin}"
|
35
|
-
# puts cq_string
|
36
|
-
# # NQ
|
37
|
-
# coin = best_nq.dig(:coin)
|
38
|
-
# best_margin = "annual margin: #{best_nq.dig(:margin)}%"
|
39
|
-
# days_remained = "days remained: #{best_nq.dig(:days)}"
|
40
|
-
# expected_margin = "expected margin: #{best_nq.dig(:expected_margin)}%"
|
41
|
-
# real_margin = "landed margin: #{best_nq.dig(:real_margin_expected)}%"
|
42
|
-
# puts "NQ"
|
43
|
-
# nq_string = "#{coin}, #{best_margin}, #{days_remained}, #{expected_margin}, #{real_margin}"
|
44
|
-
# puts nq_string
|
45
|
-
# puts "---"
|
46
|
-
# Watchcow::Output.call("<p>#{cq_string}</p><p>#{nq_string}</p>")
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
def mark! coin_offer
|
51
|
-
offer_margin = coin_offer.dig(:margin)
|
52
|
-
if better_than_best? offer_margin
|
53
|
-
key = Time.now.strftime('%m-%d')
|
54
|
-
set_redis coin_offer
|
55
|
-
if worth_notification?(offer_margin)
|
56
|
-
# TODO
|
57
|
-
# Trigger SMS notification
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def set_redis coin_offer
|
63
|
-
coin_info_str = "#{coin_offer.dig(:coin)}, #{coin_offer.dig(:margin)}, #{coin_offer.dig(:days)}, record at #{Time.now.strftime('%m-%d %H:%M')}"
|
64
|
-
coin_attr = {coin: coin_offer.dig(:coin), margin: coin_offer.dig(:margin), days: coin_offer.dig(:days), record_at: Time.now.strftime('%Y-%m-%d %H:%M')}
|
65
|
-
best_margin_of_day = $redis.get('margin_of_day')
|
66
|
-
if best_margin.blank? || two_hous_past?
|
67
|
-
$redis.set('offer', coin_info_str)
|
68
|
-
$redis.set('coin', coin_attr.to_json)
|
69
|
-
end
|
70
|
-
if best_margin_of_day.blank? || coin_offer.dig(:margin).to_f - best_margin_of_day.to_f > 1
|
71
|
-
$redis.set('margin_of_day', coin_offer.dig(:margin))
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def best_margin
|
76
|
-
key = $redis.get('margin_of_day')
|
77
|
-
if key.blank?
|
78
|
-
nil
|
79
|
-
else
|
80
|
-
key.to_f
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def better_than_best? offer_margin
|
85
|
-
return true if best_margin.blank?
|
86
|
-
return true if best_margin > 30 && offer_margin > best_margin
|
87
|
-
end
|
88
|
-
|
89
|
-
def worth_notification? offer_margin
|
90
|
-
return true if best_margin > 30 && (offer_margin - best_margin) > 2
|
91
|
-
end
|
92
|
-
|
93
|
-
def two_hous_past?
|
94
|
-
(Time.now - last_time_records).ceil / 3600 >= 2
|
95
|
-
end
|
96
|
-
|
97
|
-
def last_time_records
|
98
|
-
key = $redis.get('coin')
|
99
|
-
if key.blank?
|
100
|
-
puts "redis 'coin' nothing returns"
|
101
|
-
return nil
|
102
|
-
else
|
103
|
-
JSON.parse(key).dig('record_at').to_datetime
|
104
|
-
end
|
105
22
|
end
|
106
23
|
end
|
107
24
|
end
|
data/lib/watchcow/version.rb
CHANGED