watchcow 0.0.3 → 0.0.8

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: cda7d68cc1cb1ba53871ca1e4b2f1cdb3884daff8abfa148363395b44a18213d
4
- data.tar.gz: 975be9a7765e07031eb6ca6d6acb7a287c53bbf22793c7b41fae0f1ed3c0e5a0
3
+ metadata.gz: f68067affe43ba8f13442ef5d8d26bf2b5a4baf441baeabea15ca35caee8abcc
4
+ data.tar.gz: 724b3b7c74be7ec4f3a760372b264f66fc23e6c1c9784d206c20a1fcaccdbf4f
5
5
  SHA512:
6
- metadata.gz: 920372c2c7e02c94e15018a7b71baf1a607b81c249ad4ae79bd4fd77f9e470d4262ec0861f701922cf2d1ba62fd00e220503323e508ef62b6f867be43dbb3416
7
- data.tar.gz: 3a9b4a02242835cd1afc3e9cf0c216c28bde4ba066a3434e32d352d69937a0b04815ef7cc4ee5bd8b601bb6fb39b88bbd399e87a3ec5f3215575dbc241107d5d
6
+ metadata.gz: 3c680b39a2544d5416edcde25deab194654b1cfe8d8ba2f7431712139032c9e4dd1c3ea2cbde691a72df0c1329d5dafcdca9baaaec61ce4e182cfce617c5e9d1
7
+ data.tar.gz: e0bf02ae041a6f187b37436525249ed7e786c0defa92e7de959d035cc9009176d4a4c99ef3144298880b3d15ab0dfcb9af30f6f63db103966d0d5f3d1a1cc55b
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 = "#{coin}, #{best_margin}, #{days_remained}, #{expected_margin}, #{real_margin}"
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 = "#{coin}, #{best_margin}, #{days_remained}, #{expected_margin}, #{real_margin}"
37
- puts nq_string
38
- puts "---"
39
- Watchcow::Output.call("<p>#{cq_string}</p><p>#{nq_string}</p>")
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
 
@@ -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.3"
4
+ VERSION = "0.0.8"
5
5
  end
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.3
4
+ version: 0.0.8
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,9 @@ 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
115
77
  - watchcow.gemspec
116
78
  homepage: https://rubygems.org/gems
117
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