watchcow 0.0.4 → 0.0.9

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: 05b9a33fd36329da19cd035e61cedb67d0a8c9a63ce9a8e998a30bdcea23c9c9
4
- data.tar.gz: 516806f9ca4e6126af51d61b4a840e9dfebe8db6b1e0a44cd6aec0c05730ed3f
3
+ metadata.gz: 6080cdde2570128036d8101431ed88182bea35c5020553350846b5967bc36333
4
+ data.tar.gz: e391557868cc31f20e3c0e5861320bdb9cd1820fe088a53b74e3ad326248aa4c
5
5
  SHA512:
6
- metadata.gz: 57a3f624f1a633f42800cb2213250263e90fe3baf8f8a6a44cd1dd3da0969e78af2d7caa6248fbb543ec898baa4b4c5e22dfc0fcd27f002af51525a379e6b919
7
- data.tar.gz: 56955671e47731937449fb358616c0742ffae81ca3b6b81ee468731be7a02194290973a35e44de818834a556b051e0b58263a41b79420ae619fe98820c5c57c0
6
+ metadata.gz: 613bb077941b9e46c84fd3eb54a67a2931419f4322235df80d24ef618ba9cc1d29ccbac1648ac6b96831476f2ed25e0cc48674a7c1c06fac1516d6ad43ab9da7
7
+ data.tar.gz: 9782590eafd22f4c783a405bb1389fdd88b2c1f5492f1159dda56bff5fe4fa9c2986f957a9620dc598a117a562b805525b24f3cdd6dcb0d2d0db03c6d43dd8fd
data/Gemfile CHANGED
@@ -10,7 +10,7 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "httparty", '0.14.0'
13
- gem 'redis', '~> 3.3.5'
14
- gem 'sidekiq', '5.2.9'
13
+ # gem 'redis', '~> 3.3.5'
14
+ # gem 'sidekiq', '5.2.9'
15
15
  gem 'pry-rails'
16
16
  gem 'activesupport', '~> 6.1', '>= 6.1.3.2'
data/Gemfile.lock CHANGED
@@ -4,8 +4,6 @@ PATH
4
4
  watchcow (0.0.1)
5
5
  httparty (~> 0.14, >= 0.14.0)
6
6
  pry-rails (~> 0.3.9)
7
- redis (~> 3.3, >= 3.3.5)
8
- sidekiq (~> 5.2, >= 5.2.9)
9
7
 
10
8
  GEM
11
9
  remote: https://rubygems.org/
@@ -30,7 +28,6 @@ GEM
30
28
  rack-protection (2.0.4)
31
29
  rack
32
30
  rake (13.0.3)
33
- redis (3.3.5)
34
31
  rspec (3.10.0)
35
32
  rspec-core (~> 3.10.0)
36
33
  rspec-expectations (~> 3.10.0)
@@ -44,11 +41,9 @@ GEM
44
41
  diff-lcs (>= 1.2.0, < 2.0)
45
42
  rspec-support (~> 3.10.0)
46
43
  rspec-support (3.10.2)
47
- sidekiq (5.2.9)
48
44
  connection_pool (~> 2.2, >= 2.2.2)
49
45
  rack (~> 2.0)
50
46
  rack-protection (>= 1.5.0)
51
- redis (>= 3.3.5, < 4.2)
52
47
 
53
48
  PLATFORMS
54
49
  x86_64-darwin-17
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
@@ -3,100 +3,23 @@ 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
12
9
  class << self
13
10
  def call
14
- while true
15
- results = Watchcow::Rate.call
16
- best_cq = results[:cq_best]
17
- best_nq = results[:nq_best]
18
- mark! best_cq
19
- # CQ
20
- coin = best_cq.dig(:coin)
21
- best_margin = "annual margin: #{best_cq.dig(:margin)}%"
22
- days_remained = "days remained: #{best_cq.dig(:days)}"
23
- expected_margin = "expected margin: #{best_cq.dig(:expected_margin)}%"
24
- real_margin = "landed margin: #{best_cq.dig(:real_margin_expected)}%"
25
- puts "---"
26
- puts "CQ"
27
- cq_string = "<p style='font-size: 46px;'>#{coin}</p><p style='font-size: 46px;'>#{best_margin}</p><p style='font-size: 46px;'>#{days_remained}</p><p style='font-size: 46px;'>#{expected_margin}</p><p style='font-size: 46px;'>#{real_margin}</p>"
28
- puts cq_string
29
- # NQ
30
- coin = best_nq.dig(:coin)
31
- best_margin = "annual margin: #{best_nq.dig(:margin)}%"
32
- days_remained = "days remained: #{best_nq.dig(:days)}"
33
- expected_margin = "expected margin: #{best_nq.dig(:expected_margin)}%"
34
- real_margin = "landed margin: #{best_nq.dig(:real_margin_expected)}%"
35
- puts "NQ"
36
- nq_string = "<p style='font-size: 46px;'>#{coin}</p><p style='font-size: 46px;'>#{best_margin}</p><p style='font-size: 46px;'>#{days_remained}</p><p style='font-size: 46px;'>#{expected_margin}</p><p style='font-size: 46px;'>#{real_margin}</p>"
37
- puts nq_string
38
- puts "---"
39
- Watchcow::Output.call("#{cq_string}---<br>---#{nq_string}")
40
- sleep(30)
41
- end
42
- end
43
-
44
- private
45
- def mark! coin_offer
46
- offer_margin = coin_offer.dig(:margin)
47
- if better_than_best? offer_margin
48
- key = Time.now.strftime('%m-%d')
49
- set_redis coin_offer
50
- if worth_notification?(offer_margin)
51
- # TODO
52
- # Trigger SMS notification
53
- end
54
- end
55
- end
56
-
57
- def set_redis coin_offer
58
- coin_info_str = "#{coin_offer.dig(:coin)}, #{coin_offer.dig(:margin)}, #{coin_offer.dig(:days)}, record at #{Time.now.strftime('%m-%d %H:%M')}"
59
- 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')}
60
- best_margin_of_day = $redis.get('margin_of_day')
61
- if best_margin.blank? || two_hous_past?
62
- $redis.set('offer', coin_info_str)
63
- $redis.set('coin', coin_attr.to_json)
64
- end
65
- if best_margin_of_day.blank? || coin_offer.dig(:margin).to_f - best_margin_of_day.to_f > 1
66
- $redis.set('margin_of_day', coin_offer.dig(:margin))
67
- end
68
- end
69
-
70
- def best_margin
71
- key = $redis.get('margin_of_day')
72
- if key.blank?
73
- nil
74
- else
75
- key.to_f
76
- end
77
- end
78
-
79
- def better_than_best? offer_margin
80
- return true if best_margin.blank?
81
- return true if best_margin > 30 && offer_margin > best_margin
82
- end
83
-
84
- def worth_notification? offer_margin
85
- return true if best_margin > 30 && (offer_margin - best_margin) > 2
86
- end
87
-
88
- def two_hous_past?
89
- (Time.now - last_time_records).ceil / 3600 >= 2
90
- end
91
-
92
- def last_time_records
93
- key = $redis.get('coin')
94
- if key.blank?
95
- puts "redis 'coin' nothing returns"
96
- return nil
97
- else
98
- JSON.parse(key).dig('record_at').to_datetime
99
- 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
+ results = {
17
+ cq_list: cq_list,
18
+ nq_list: nq_list,
19
+ nw_list: nw_list,
20
+ cw_list: cw_list
21
+ }
22
+ results.to_json
100
23
  end
101
24
  end
102
25
  end
@@ -1,10 +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
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
 
@@ -34,23 +38,30 @@ module Watchcow
34
38
  days: days_remain,
35
39
  expected_margin: margin_expect,
36
40
  real_margin_expected: real_margin_expect
41
+ dm_first_bid: dm_first_bid,
42
+ spot_first_bid: spot_first_bid
37
43
  }
38
44
  results.push(result)
39
45
  end
40
46
  end
41
47
  results_cq = results.select{|x| x[:coin].include?('cq')}
42
48
  results_nq = results.select{|x| x[:coin].include?('nq')}
49
+ results_cw = results.select{|x| x[:coin].include?('cw')}
50
+ results_nw = results.select{|x| x[:coin].include?('nw')}
43
51
  {
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,
52
+ cq_list: results_cq.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]},
53
+ nq_list: results_nq.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]},
54
+ cw_list: results_cw.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]},
55
+ nw_list: results_nw.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]}
46
56
  }
47
57
  end
48
58
 
49
59
  def days_remain_of symbol, t
50
60
  @contract_info ||= Watchcow::ContractInfo.call
51
61
  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
62
+ # mark = t == 'cq' ? 'quarter' : 'next_quarter'
63
+ # h.dig('symbol') == symbol.upcase && h.dig('contract_type') == mark
64
+ h.dig('symbol') == symbol.upcase && h.dig('contract_type') == KEYS[t]
54
65
  end.first
55
66
  (line.dig("delivery_date").to_s.to_date - Time.now.to_date).to_i
56
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Watchcow
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.9"
5
5
  end
Binary file
Binary file
Binary file
Binary file
Binary file
data/watchcow.gemspec CHANGED
@@ -29,10 +29,10 @@ 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
37
37
  # guide at: https://bundler.io/guides/creating_gem.html
38
38
  end
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.4
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - DrinE Liu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-14 00:00:00.000000000 Z
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
@@ -102,7 +62,6 @@ files:
102
62
  - Rakefile
103
63
  - bin/console
104
64
  - bin/setup
105
- - lib/notification_worker.rb
106
65
  - lib/watchcow.rb
107
66
  - lib/watchcow/api_symbol.rb
108
67
  - lib/watchcow/client.rb
@@ -112,6 +71,11 @@ files:
112
71
  - lib/watchcow/rate.rb
113
72
  - lib/watchcow/version.rb
114
73
  - watchcow-0.0.2.gem
74
+ - watchcow-0.0.3.gem
75
+ - watchcow-0.0.4.gem
76
+ - watchcow-0.0.5.gem
77
+ - watchcow-0.0.6.gem
78
+ - watchcow-0.0.7.gem
115
79
  - watchcow.gemspec
116
80
  homepage: https://rubygems.org/gems
117
81
  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