watchcow 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e874e0e43b791b20d5b540718554168ef71f8f1f8658224f79669cfe444ef82
4
- data.tar.gz: 9c24f027f2970847773fabd678150ac2cb12e6f53ad459eae5f468af309a62e1
3
+ metadata.gz: 48656fac82cae2397bc0af466760d5cbb65bbdc561c37aa2238a4b74a3b182ef
4
+ data.tar.gz: e2c550f8675ebef543e6e1a4899a25fc8154041dd4241068016af66fcb006c8b
5
5
  SHA512:
6
- metadata.gz: 7860babf90df45f49b68488c4c8e0799673a6dbcc4aa38f7066061acc6aa54945dd264d88acea43a6d0570e38bd3813d2efe9e7dd60fe9ed45479e94a49b3d23
7
- data.tar.gz: fcc55289c8ec8098ee58d200c412828b6b2727af779b158d186e535cd66f1ffe3271cfffb9075cadad26be3f18835de07fa0edd2090b6a297106c8d300c62ae3
6
+ metadata.gz: fa6bf2c23486c621ef9c2926ac867ff40704c81063a316feffcb9255c50623c9647b8bd5e1238edf57b335be3fee3eb650aab8eebb0432cbdd9d6e50eae69db1
7
+ data.tar.gz: 7b68b55e20d5667e4e2ecd25f007b9462f117ec8005a12061b1f50112658b29b117b1da8170d4e1a7b7d9b376eaabd6df68dc310dc94bbdcff243b15eca3b1db
data/lib/watchcow.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  require 'json'
3
- require "redis"
4
3
  require 'httparty'
5
4
  require "pry"
6
5
  require 'watchcow/client'
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Watchcow
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.7"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watchcow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - DrinE Liu