watchcow 0.0.1 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 190013ace8f0a7d0ef2025cb766d42a9fdb60594d530e4cd977bf828c0f0af29
4
- data.tar.gz: 71ca5b0d7f88bd1ef3062e7025ecff773ef52c6bf235016ebf00e1c169bec70a
3
+ metadata.gz: 48656fac82cae2397bc0af466760d5cbb65bbdc561c37aa2238a4b74a3b182ef
4
+ data.tar.gz: e2c550f8675ebef543e6e1a4899a25fc8154041dd4241068016af66fcb006c8b
5
5
  SHA512:
6
- metadata.gz: df69250920b9ac2858655cc00778881b711bd768faf9ac32cee5a7aa0286b1351e38faf499064525f08ab97615ca36b62f5f0cf2c724a05c8376b213b0258239
7
- data.tar.gz: 13c323b3124bc39e6151c7062862c1a34fbd29413b109df07d3865646352f85d091f8a0d9f60b10a9f763e1e3b3307afb5a98935b6729ff8d0971b0e2271de20
6
+ metadata.gz: fa6bf2c23486c621ef9c2926ac867ff40704c81063a316feffcb9255c50623c9647b8bd5e1238edf57b335be3fee3eb650aab8eebb0432cbdd9d6e50eae69db1
7
+ data.tar.gz: 7b68b55e20d5667e4e2ecd25f007b9462f117ec8005a12061b1f50112658b29b117b1da8170d4e1a7b7d9b376eaabd6df68dc310dc94bbdcff243b15eca3b1db
data/Gemfile CHANGED
@@ -8,3 +8,9 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
+
12
+ gem "httparty", '0.14.0'
13
+ # gem 'redis', '~> 3.3.5'
14
+ # gem 'sidekiq', '5.2.9'
15
+ gem 'pry-rails'
16
+ gem 'activesupport', '~> 6.1', '>= 6.1.3.2'
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ watchcow (0.0.1)
5
+ httparty (~> 0.14, >= 0.14.0)
6
+ pry-rails (~> 0.3.9)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.3)
12
+ connection_pool (2.2.5)
13
+ diff-lcs (1.4.4)
14
+ httparty (0.18.1)
15
+ mime-types (~> 3.0)
16
+ multi_xml (>= 0.5.2)
17
+ method_source (1.0.0)
18
+ mime-types (3.3.1)
19
+ mime-types-data (~> 3.2015)
20
+ mime-types-data (3.2021.0225)
21
+ multi_xml (0.6.0)
22
+ pry (0.14.1)
23
+ coderay (~> 1.1)
24
+ method_source (~> 1.0)
25
+ pry-rails (0.3.9)
26
+ pry (>= 0.10.4)
27
+ rack (2.2.3)
28
+ rack-protection (2.0.4)
29
+ rack
30
+ rake (13.0.3)
31
+ rspec (3.10.0)
32
+ rspec-core (~> 3.10.0)
33
+ rspec-expectations (~> 3.10.0)
34
+ rspec-mocks (~> 3.10.0)
35
+ rspec-core (3.10.1)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-expectations (3.10.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-mocks (3.10.2)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-support (3.10.2)
44
+ connection_pool (~> 2.2, >= 2.2.2)
45
+ rack (~> 2.0)
46
+ rack-protection (>= 1.5.0)
47
+
48
+ PLATFORMS
49
+ x86_64-darwin-17
50
+
51
+ DEPENDENCIES
52
+ rake (~> 13.0)
53
+ rspec (~> 3.0)
54
+ watchcow!
55
+
56
+ BUNDLED WITH
57
+ 2.2.6
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'
@@ -6,7 +6,7 @@ module Watchcow
6
6
  end
7
7
 
8
8
  def dm_types
9
- %w{nq cq}
9
+ %w{nq cq cw nw}
10
10
  end
11
11
  end
12
12
  end
@@ -4,95 +4,21 @@ require 'watchcow/market_depth'
4
4
  require 'active_support'
5
5
  require 'watchcow/rate'
6
6
 
7
- $redis = Redis.new(url: ENV["REDIS_URL"] || "redis://localhost:6379/0")
8
-
9
7
  module Watchcow
10
8
  class Client
11
9
  class << self
12
10
  def call
13
- while true
14
- results = Watchcow::Rate.call
15
- best_cq = results[:cq_best]
16
- best_nq = results[:nq_best]
17
- mark! best_cq
18
- # CQ
19
- coin = best_cq.dig(:coin)
20
- best_margin = "annual margin: #{best_cq.dig(:margin)}%"
21
- days_remained = "days remained: #{best_cq.dig(:days)}"
22
- expected_margin = "expected margin: #{best_cq.dig(:expected_margin)}%"
23
- real_margin = "landed margin: #{best_cq.dig(:real_margin_expected)}%"
24
- puts "---"
25
- puts "Best current quarter"
26
- puts "#{coin}, #{best_margin}, #{days_remained}, #{expected_margin}, #{real_margin}"
27
- # NQ
28
- coin = best_nq.dig(:coin)
29
- best_margin = "annual margin: #{best_nq.dig(:margin)}%"
30
- days_remained = "days remained: #{best_nq.dig(:days)}"
31
- expected_margin = "expected margin: #{best_nq.dig(:expected_margin)}%"
32
- real_margin = "landed margin: #{best_nq.dig(:real_margin_expected)}%"
33
- puts "Best next quarter"
34
- puts "#{coin}, #{best_margin}, #{days_remained}, #{expected_margin}, #{real_margin}"
35
- puts "---"
36
- sleep(30)
37
- end
38
- end
39
-
40
- private
41
- def mark! coin_offer
42
- offer_margin = coin_offer.dig(:margin)
43
- if better_than_best? offer_margin
44
- key = Time.now.strftime('%m-%d')
45
- set_redis coin_offer
46
- if worth_notification?(offer_margin)
47
- # TODO
48
- # Trigger SMS notification
49
- end
50
- end
51
- end
52
-
53
- def set_redis coin_offer
54
- coin_info_str = "#{coin_offer.dig(:coin)}, #{coin_offer.dig(:margin)}, #{coin_offer.dig(:days)}, record at #{Time.now.strftime('%m-%d %H:%M')}"
55
- 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')}
56
- best_margin_of_day = $redis.get('margin_of_day')
57
- if best_margin.blank? || two_hous_past?
58
- $redis.set('offer', coin_info_str)
59
- $redis.set('coin', coin_attr.to_json)
60
- end
61
- if best_margin_of_day.blank? || coin_offer.dig(:margin).to_f - best_margin_of_day.to_f > 1
62
- $redis.set('margin_of_day', coin_offer.dig(:margin))
63
- end
64
- end
65
-
66
- def best_margin
67
- key = $redis.get('margin_of_day')
68
- if key.blank?
69
- nil
70
- else
71
- key.to_f
72
- end
73
- end
74
-
75
- def better_than_best? offer_margin
76
- return true if best_margin.blank?
77
- return true if best_margin > 30 && offer_margin > best_margin
78
- end
79
-
80
- def worth_notification? offer_margin
81
- return true if best_margin > 30 && (offer_margin - best_margin) > 2
82
- end
83
-
84
- def two_hous_past?
85
- (Time.now - last_time_records).ceil / 3600 >= 2
86
- end
87
-
88
- def last_time_records
89
- key = $redis.get('coin')
90
- if key.blank?
91
- puts "redis 'coin' nothing returns"
92
- return nil
93
- else
94
- JSON.parse(key).dig('record_at').to_datetime
95
- end
11
+ results = Watchcow::Rate.call
12
+ cq_list = results[:cq_list]
13
+ nq_list = results[:nq_list]
14
+ nw_list = results[:nw_list]
15
+ cw_list = results[:cw_list]
16
+ {
17
+ cq_list: cq_list,
18
+ nq_list: nq_list,
19
+ nw_list: nw_list,
20
+ cw_list: cw_list
21
+ }
96
22
  end
97
23
  end
98
24
  end
@@ -0,0 +1,10 @@
1
+ # module Watchcow
2
+ # class Output
3
+ # class << self
4
+ # def call text
5
+ # path = File.expand_path('~/', __FILE__)
6
+ # File.open("#{path}/info.html", 'w+'){|f| f.write(text)}
7
+ # end
8
+ # end
9
+ # end
10
+ # end
data/lib/watchcow/rate.rb CHANGED
@@ -2,6 +2,12 @@ require 'active_support/core_ext'
2
2
 
3
3
  module Watchcow
4
4
  class Rate
5
+ KEYS = {
6
+ 'cq' => 'quarter',
7
+ 'nq' => 'next_quarter',
8
+ 'nw' => 'next_week',
9
+ 'cw' => 'this_week'
10
+ }
5
11
  class << self
6
12
  def call
7
13
  results = []
@@ -9,7 +15,6 @@ module Watchcow
9
15
  Watchcow::ApiSymbol.dm_types.each do |t|
10
16
  dm_symbol = {symbol: "#{coin}_#{t}"}
11
17
  spot_symbol = {symbol: "#{coin}usdt"}
12
-
13
18
  begin
14
19
  dm_result = Watchcow::MarketDepth.call(params: dm_symbol, k: :future)
15
20
  # puts dm_symbol.dig(:symbol)
@@ -22,7 +27,6 @@ module Watchcow
22
27
  days_remain = self.days_remain_of(coin, t)
23
28
  dm_first_bid = dm_result.dig('tick', 'bids')[0][0].to_f
24
29
  spot_first_bid = spot_result.dig('tick', 'bids')[0][0].to_f
25
-
26
30
  margin_annual = (((dm_first_bid - spot_first_bid) / spot_first_bid) / days_remain * 365 * 100).round(6)
27
31
  margin_expect = margin_annual / 365 * days_remain
28
32
 
@@ -40,17 +44,22 @@ module Watchcow
40
44
  end
41
45
  results_cq = results.select{|x| x[:coin].include?('cq')}
42
46
  results_nq = results.select{|x| x[:coin].include?('nq')}
47
+ results_cw = results.select{|x| x[:coin].include?('cw')}
48
+ results_nw = results.select{|x| x[:coin].include?('nw')}
43
49
  {
44
- cq_best: results_cq.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]}.first,
45
- nq_best: results_nq.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]}.first,
50
+ cq_list: results_cq.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]},
51
+ nq_list: results_nq.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]},
52
+ cw_list: results_cw.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]},
53
+ nw_list: results_nw.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]}
46
54
  }
47
55
  end
48
56
 
49
57
  def days_remain_of symbol, t
50
58
  @contract_info ||= Watchcow::ContractInfo.call
51
59
  line = @contract_info.dig('data').select do |h|
52
- mark = t == 'cq' ? 'quarter' : 'next_quarter'
53
- h.dig('symbol') == symbol.upcase && h.dig('contract_type') == mark
60
+ # mark = t == 'cq' ? 'quarter' : 'next_quarter'
61
+ # h.dig('symbol') == symbol.upcase && h.dig('contract_type') == mark
62
+ h.dig('symbol') == symbol.upcase && h.dig('contract_type') == KEYS[t]
54
63
  end.first
55
64
  (line.dig("delivery_date").to_s.to_date - Time.now.to_date).to_i
56
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Watchcow
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.7"
5
5
  end
Binary file
Binary file
Binary file
Binary file
data/watchcow.gemspec CHANGED
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
29
29
  # spec.add_dependency "example-gem", "~> 1.0"
30
30
 
31
31
  spec.add_dependency "httparty", '~> 0.14', ">= 0.14.0"
32
- spec.add_dependency "redis", '~> 3.3', ">= 3.3.5"
33
- spec.add_dependency "sidekiq", '~> 5.2', ">= 5.2.9"
32
+ # spec.add_dependency "redis", '~> 3.3', ">= 3.3.5"
33
+ # spec.add_dependency "sidekiq", '~> 5.2', ">= 5.2.9"
34
34
  spec.add_dependency "pry-rails", "~> 0.3.9"
35
35
 
36
36
  # For more information and examples about making a new gem, checkout our
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watchcow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - DrinE Liu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date:
11
+ date: 2021-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -30,46 +30,6 @@ dependencies:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0.14'
33
- - !ruby/object:Gem::Dependency
34
- name: redis
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '3.3'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 3.3.5
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '3.3'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 3.3.5
53
- - !ruby/object:Gem::Dependency
54
- name: sidekiq
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '5.2'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 5.2.9
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '5.2'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 5.2.9
73
33
  - !ruby/object:Gem::Dependency
74
34
  name: pry-rails
75
35
  requirement: !ruby/object:Gem::Requirement
@@ -96,20 +56,24 @@ files:
96
56
  - ".rspec"
97
57
  - CODE_OF_CONDUCT.md
98
58
  - Gemfile
59
+ - Gemfile.lock
99
60
  - LICENSE.txt
100
61
  - README.md
101
62
  - Rakefile
102
63
  - bin/console
103
64
  - bin/setup
104
- - lib/notification_worker.rb
105
65
  - lib/watchcow.rb
106
66
  - lib/watchcow/api_symbol.rb
107
67
  - lib/watchcow/client.rb
108
68
  - lib/watchcow/contract_info.rb
109
69
  - lib/watchcow/market_depth.rb
70
+ - lib/watchcow/output.rb
110
71
  - lib/watchcow/rate.rb
111
72
  - lib/watchcow/version.rb
112
- - watchcow-0.0.1.gem
73
+ - watchcow-0.0.2.gem
74
+ - watchcow-0.0.3.gem
75
+ - watchcow-0.0.4.gem
76
+ - watchcow-0.0.5.gem
113
77
  - watchcow.gemspec
114
78
  homepage: https://rubygems.org/gems
115
79
  licenses:
@@ -1,11 +0,0 @@
1
- require 'sidekiq'
2
- require 'watchcow'
3
-
4
- class NotificationWorker
5
-
6
- include Sidekiq::Worker
7
-
8
- def perform
9
- Watchcow::Client.call
10
- end
11
- end
data/watchcow-0.0.1.gem DELETED
Binary file