watchcow 0.1.11 → 0.1.12

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: 4152adcf0ced5a26e3befac32831afde5897b5addcb9e05270e57980148448e1
4
- data.tar.gz: 7704db9e1dd1fcf40ef75ef7324375f17e75382369f0c3172bd15ce242ebf206
3
+ metadata.gz: 9278d3d386832cfad1db4406ee6c5b0343c2dd096135aaedd9a4cf98c6ff59cd
4
+ data.tar.gz: c098df95b942ed5ba925f5af509f3845378d79aca20103d6d11d7830711f3439
5
5
  SHA512:
6
- metadata.gz: bbae037e0d859d8fe567485effdfbf9e53b9408715aaa27706c250c4fb7eef8645e646ec9215636af1212b8ef01c363fb0127b9f0a6d5e659ceaf0f41b35d226
7
- data.tar.gz: 2d6ec45fc468831b5c82da5d1bb694b972ef633c2d96e7f5914bf57eea57f48bc39d0e97d8f4e542cdc71f852cf415ffe10633e902da945f6078f06621f4a523
6
+ metadata.gz: fd615fc5b8559d39e6f05d5f3f29da5742b0b6e5e25398b2446557e7e8bfc8f37708fafde6cc6ec743b885a27171eebbff077386db05ff0183dec45e8203fa89
7
+ data.tar.gz: 6d93a1703a8bc79de7e84ba126de8e39ddb435780b5a9d4f937b755dd17ed91d707de013d6ca5e1eb2d55ecb18136f02e3534b28166a6c9758b12a7d49620580
data/Gemfile.lock CHANGED
@@ -1,23 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- watchcow (0.0.1)
4
+ watchcow (0.1.11)
5
5
  httparty (~> 0.14, >= 0.14.0)
6
6
  pry-rails (~> 0.3.9)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ activesupport (6.1.3.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
11
17
  coderay (1.1.3)
18
+ concurrent-ruby (1.1.8)
12
19
  connection_pool (2.2.5)
13
20
  diff-lcs (1.4.4)
14
- httparty (0.18.1)
15
- mime-types (~> 3.0)
21
+ httparty (0.14.0)
16
22
  multi_xml (>= 0.5.2)
23
+ i18n (1.8.10)
24
+ concurrent-ruby (~> 1.0)
17
25
  method_source (1.0.0)
18
- mime-types (3.3.1)
19
- mime-types-data (~> 3.2015)
20
- mime-types-data (3.2021.0225)
26
+ minitest (5.14.3)
21
27
  multi_xml (0.6.0)
22
28
  pry (0.14.1)
23
29
  coderay (~> 1.1)
@@ -44,11 +50,17 @@ GEM
44
50
  connection_pool (~> 2.2, >= 2.2.2)
45
51
  rack (~> 2.0)
46
52
  rack-protection (>= 1.5.0)
53
+ tzinfo (2.0.4)
54
+ concurrent-ruby (~> 1.0)
55
+ zeitwerk (2.4.2)
47
56
 
48
57
  PLATFORMS
49
58
  x86_64-darwin-17
50
59
 
51
60
  DEPENDENCIES
61
+ activesupport (~> 6.1, >= 6.1.3.2)
62
+ httparty (= 0.14.0)
63
+ pry-rails
52
64
  rake (~> 13.0)
53
65
  rspec (~> 3.0)
54
66
  watchcow!
@@ -6,7 +6,22 @@ module Watchcow
6
6
  end
7
7
 
8
8
  def dm_types
9
- %w{nq cq cw nw}
9
+ data = mapping.select do |k, v|
10
+ v.in? current_types
11
+ end.keys
12
+ end
13
+
14
+ def current_types
15
+ Watchcow::ContractInfo.current_contracts
16
+ end
17
+
18
+ def mapping
19
+ {
20
+ 'cq' => 'quarter',
21
+ 'nq' => 'next_quarter',
22
+ 'nw' => 'next_week',
23
+ 'cw' => 'this_week'
24
+ }
10
25
  end
11
26
  end
12
27
  end
@@ -7,6 +7,10 @@ module Watchcow
7
7
  def call
8
8
  JSON.parse(HTTParty.get(URL))
9
9
  end
10
+
11
+ def current_contracts
12
+ call.dig('data').map{|x| x["contract_type"]}.uniq
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -5,7 +5,6 @@ module Watchcow
5
5
  URLPRO = "https://api.huobi.pro/market/depth"
6
6
 
7
7
  class << self
8
-
9
8
  # Spot market or Futures market all goes here
10
9
  def call(params:, k:)
11
10
  url = target_url(params, k)
data/lib/watchcow/rate.rb CHANGED
@@ -2,12 +2,6 @@ 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
- }
11
5
  class << self
12
6
  def call coin=nil
13
7
  results = []
@@ -26,14 +20,13 @@ module Watchcow
26
20
  rescue
27
21
  redo
28
22
  end
29
-
23
+
30
24
  dm_first_bid = dm_result.dig('tick', 'bids')[0][0].to_f
31
25
  spot_first_bid = spot_result.dig('tick', 'bids')[0][0].to_f
32
26
  margin_annual = (((dm_first_bid - spot_first_bid) / spot_first_bid) / days_remain * 365 * 100).round(6)
33
27
  margin_expect = margin_annual / 365 * days_remain
34
28
  base_gap = dm_first_bid - spot_first_bid
35
29
  gap_rate = base_gap / dm_first_bid * 100
36
- binding.pry if days_remain <= 0
37
30
  real_margin_expect = (1.0 / spot_first_bid - 1.0 / dm_first_bid) * spot_first_bid * 100
38
31
  result = {
39
32
  coin: "#{coin}_#{t}",
@@ -64,7 +57,7 @@ module Watchcow
64
57
  def days_remain_of symbol, t
65
58
  @contract_info = Watchcow::ContractInfo.call
66
59
  line = @contract_info.dig('data').select do |h|
67
- h.dig('symbol') == symbol.upcase && h.dig('contract_type') == KEYS[t]
60
+ h.dig('symbol') == symbol.upcase && h.dig('contract_type') == Watchcow::ApiSymbol.mapping[t]
68
61
  end.first
69
62
  contract_time = "#{line.dig("delivery_date").to_date.to_s} 16:00".in_time_zone('Asia/Chongqing').to_time
70
63
  ((contract_time - Time.now.to_time) / 1.hours) / 24
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Watchcow
4
- VERSION = "0.1.11"
4
+ VERSION = "0.1.12"
5
5
  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.1.11
4
+ version: 0.1.12
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-06-04 00:00:00.000000000 Z
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty