watchcow 0.0.4 → 0.0.5

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: 05b9a33fd36329da19cd035e61cedb67d0a8c9a63ce9a8e998a30bdcea23c9c9
4
- data.tar.gz: 516806f9ca4e6126af51d61b4a840e9dfebe8db6b1e0a44cd6aec0c05730ed3f
3
+ metadata.gz: 3f445e4343b05fe230682a4f2c841acbea5be420df877eed931e949a3e9e51e1
4
+ data.tar.gz: f7b0ff6d26285b0310c8c47dfda9f7532906b9f6e2fdebeff5c979ec278ea774
5
5
  SHA512:
6
- metadata.gz: 57a3f624f1a633f42800cb2213250263e90fe3baf8f8a6a44cd1dd3da0969e78af2d7caa6248fbb543ec898baa4b4c5e22dfc0fcd27f002af51525a379e6b919
7
- data.tar.gz: 56955671e47731937449fb358616c0742ffae81ca3b6b81ee468731be7a02194290973a35e44de818834a556b051e0b58263a41b79420ae619fe98820c5c57c0
6
+ metadata.gz: 29b6d8fd8ef18b7da1a398a660e606a5028bc8d2a013f93b41bec9d94e3862a87debb67cc74ec379fcfce93bb6ca9e3273aa93bb2cc0251b63687c051bdae4d7
7
+ data.tar.gz: 0204b63fbd2e472ba1cd57dfc4be63ccbca6bc4b07939b52b2b8c08f4e40376a644f53253b08e4031fc091e0add53fe09bcfa68c911e545f9b69a7daf0b8e575
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'
@@ -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,42 +3,47 @@ require 'watchcow/contract_info'
3
3
  require 'watchcow/market_depth'
4
4
  require 'active_support'
5
5
  require 'watchcow/rate'
6
- require 'watchcow/output'
6
+ # require 'watchcow/output'
7
7
 
8
- $redis = Redis.new(url: ENV["REDIS_URL"] || "redis://localhost:6379/0")
8
+ # $redis = Redis.new(url: ENV["REDIS_URL"] || "redis://localhost:6379/0")
9
9
 
10
10
  module Watchcow
11
11
  class Client
12
12
  class << self
13
13
  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
14
+ results = Watchcow::Rate.call
15
+ cq_list = results[:cq_list]
16
+ nq_list = results[:nq_list]
17
+ nw_list = results[:nw_list]
18
+ cw_list = results[:cw_list]
19
+ {
20
+ cq_list: cq_list,
21
+ nq_list: nq_list,
22
+ nw_list: nw_list,
23
+ cw_list: cw_list
24
+ }
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>")
42
47
  end
43
48
 
44
49
  private
@@ -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
 
@@ -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.4"
4
+ VERSION = "0.0.5"
5
5
  end
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.4
4
+ version: 0.0.5
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,8 @@ 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
115
76
  - watchcow.gemspec
116
77
  homepage: https://rubygems.org/gems
117
78
  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