watchcow 0.1.4 → 0.1.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: b9be8072f67eb62cbc4b7cf1ba09f62d336121edd4190cf0cf8c90c5a72bda52
4
- data.tar.gz: ff1d7c9ec0a90d00f591a097240192b2b971e6dbece3e8fea816a313f15551ae
3
+ metadata.gz: 99751f179eb4c15e3b19d81e778b8fb6c3c99e5582fb51ce0130aaa8ab436b8d
4
+ data.tar.gz: d78b9d8c59613ca84e186c5a2ff783fb68817fb32ec0aa2ff727a88b213f346a
5
5
  SHA512:
6
- metadata.gz: 2f16346c204fe851b6d09c42c69e6fe38fb4a98bf29f2ba877650d17f72f6f477dbdd0d8732715b3a9d8488a44cc14a4e5cc353c88fd36a874641375391dcd8c
7
- data.tar.gz: 8fd9836528fc159891f4889b964b5a5bfb3eeca1ed490fc62c5f2d9b0ce04fa6d928bb0a47ceda1745f2b6e580bd4aacf937a619650e37d5134534c2abf2e9e9
6
+ metadata.gz: 75ef29d231100e343af3879050df3945dafe1e30fab0a5dd9d5e998e4595144e963264d87585c238fb0916198d942f984612b01e610645f5da67c63ef33b2302
7
+ data.tar.gz: 18f09893ef9c952b124f79f119379c0a16bcb86b2b60e9a022b2ac0f61c49a202ddcf4f28ce6ba1743e824e8988171befbfb23640504f16aa5073896444ea8fd
data/.gitignore CHANGED
@@ -6,6 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
-
9
+ /lib/cow.rb
10
10
  # rspec failure tracking
11
11
  .rspec_status
@@ -38,17 +38,15 @@ module Watchcow
38
38
  best_cw = cw.first
39
39
  best_nw = nw.first
40
40
  text = [best_nq, best_cq, best_nw, best_cw].each do |x|
41
- t =
42
- <<-CONTENT
43
- #{x.dig('coin')}
44
- remained: #{x.dig('days')}
45
- annual margin: #{x.dig('margin')}%
46
- expected margin: #{x.dig('expected_margin')}%
47
- landed margin: #{x.dig('real_margin_expected')}%
48
- first dm bid: #{x.dig('dm_first_bid')}
49
- first spot bid: #{x.dig('spot_first_bid')}
50
-
51
- CONTENT
41
+ t =
42
+ <<-CONTENT
43
+ #{x.dig('coin')}, #{x.dig('days')} days left
44
+ annual margin: #{x.dig('margin')}%
45
+ landed margin: #{x.dig('real_margin_expected')}%
46
+ dm bid: #{x.dig('dm_first_bid')}, spot bid: #{x.dig('spot_first_bid')}
47
+ ---
48
+
49
+ CONTENT
52
50
  puts t
53
51
  end
54
52
  end
data/lib/watchcow/rate.rb CHANGED
@@ -21,18 +21,18 @@ module Watchcow
21
21
  # puts dm_symbol.dig(:symbol)
22
22
  spot_result = Watchcow::MarketDepth.call(params: spot_symbol, k: :spot)
23
23
  # puts spot_symbol.dig(:symbol)
24
+ dm_result = JSON.parse dm_result
25
+ days_remain = self.days_remain_of(coin, t)
24
26
  rescue
25
27
  redo
26
28
  end
27
- dm_result = JSON.parse dm_result
28
- days_remain = self.days_remain_of(coin, t)
29
+
29
30
  dm_first_bid = dm_result.dig('tick', 'bids')[0][0].to_f
30
31
  spot_first_bid = spot_result.dig('tick', 'bids')[0][0].to_f
31
32
  margin_annual = (((dm_first_bid - spot_first_bid) / spot_first_bid) / days_remain * 365 * 100).round(6)
32
33
  margin_expect = margin_annual / 365 * days_remain
33
34
 
34
35
  real_margin_expect = (1.0 / spot_first_bid - 1.0 / dm_first_bid) * spot_first_bid * 100
35
-
36
36
  result = {
37
37
  coin: "#{coin}_#{t}",
38
38
  margin: margin_annual,
@@ -60,11 +60,10 @@ module Watchcow
60
60
  def days_remain_of symbol, t
61
61
  @contract_info ||= Watchcow::ContractInfo.call
62
62
  line = @contract_info.dig('data').select do |h|
63
- # mark = t == 'cq' ? 'quarter' : 'next_quarter'
64
- # h.dig('symbol') == symbol.upcase && h.dig('contract_type') == mark
65
63
  h.dig('symbol') == symbol.upcase && h.dig('contract_type') == KEYS[t]
66
64
  end.first
67
- (line.dig("delivery_date").to_s.to_date - Time.now.to_date).to_i
65
+ contract_time = "#{line.dig("delivery_date").to_date.to_s} 16:00".in_time_zone('Asia/Chongqing').to_time
66
+ ((contract_time - Time.now.to_time) / 1.hours) / 24
68
67
  end
69
68
  end
70
69
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Watchcow
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.9"
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.4
4
+ version: 0.1.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-19 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty