watchcow 0.1.12 → 0.2.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 +4 -4
- data/lib/watchcow/api_symbol.rb +0 -14
- data/lib/watchcow/contract_info.rb +4 -1
- data/lib/watchcow/rate.rb +35 -29
- data/lib/watchcow/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1df0dc2cf2e5b29f6a7823afbfb19bf5f5d457cf9b81f06d289130cdf15e4eb2
|
4
|
+
data.tar.gz: 4041b2e5e30678b67db33958b6c86c7399ba01018cef6f5c364899976a9f1789
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e59700b75480c9abb161c0a495f51461918d0e574b531e77f48c3c31bb480836b9356cc08dd7b2c494ee4dcfeb4788c1887a1fcb496bdb42da4176fbfd2c31b
|
7
|
+
data.tar.gz: bcf6f472b21b27f9ea62a029cad0e38a4d6a9953ccb31a5837686ace18b974bb4da19823a1fb7f36857a9dea738ea25216e276fdfe9e53d3d6322a556d14dae1
|
data/lib/watchcow/api_symbol.rb
CHANGED
@@ -1,20 +1,6 @@
|
|
1
1
|
module Watchcow
|
2
2
|
module ApiSymbol
|
3
3
|
class << self
|
4
|
-
def contract_list
|
5
|
-
%w{btc eth link dot eos trx ada ltc bch xrp bsv etc fil}
|
6
|
-
end
|
7
|
-
|
8
|
-
def dm_types
|
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
4
|
def mapping
|
19
5
|
{
|
20
6
|
'cq' => 'quarter',
|
@@ -9,7 +9,10 @@ module Watchcow
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def current_contracts
|
12
|
-
call.dig('data').
|
12
|
+
types = call.dig('data').group_by{|x| x["symbol"]}
|
13
|
+
types.map do |k, v|
|
14
|
+
{ k=> v.map{|x| Watchcow::ApiSymbol.mapping.invert[x["contract_type"]]}}
|
15
|
+
end.inject(&:merge)
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
data/lib/watchcow/rate.rb
CHANGED
@@ -5,40 +5,22 @@ module Watchcow
|
|
5
5
|
class << self
|
6
6
|
def call coin=nil
|
7
7
|
results = []
|
8
|
-
coin_list = coin.nil? ? Watchcow::
|
9
|
-
coin_list.each do |coin|
|
10
|
-
|
8
|
+
coin_list = coin.nil? ? Watchcow::ContractInfo.current_contracts : Watchcow::ContractInfo.current_contracts.select{|k, v| k == coin.upcase}
|
9
|
+
coin_list.each do |coin, contract_types|
|
10
|
+
contract_types.each do |t|
|
11
11
|
dm_symbol = {symbol: "#{coin}_#{t}"}
|
12
|
-
spot_symbol = {symbol: "#{coin}usdt"}
|
12
|
+
spot_symbol = {symbol: "#{coin.downcase}usdt"}
|
13
13
|
begin
|
14
14
|
dm_result = Watchcow::MarketDepth.call(params: dm_symbol, k: :future)
|
15
|
-
# puts dm_symbol.dig(:symbol)
|
16
15
|
spot_result = Watchcow::MarketDepth.call(params: spot_symbol, k: :spot)
|
17
|
-
# puts spot_symbol.dig(:symbol)
|
18
16
|
dm_result = JSON.parse dm_result
|
19
|
-
days_remain =
|
17
|
+
days_remain =
|
18
|
+
n = 1
|
20
19
|
rescue
|
21
|
-
|
20
|
+
n += 1
|
21
|
+
redo if n <= 3
|
22
22
|
end
|
23
|
-
|
24
|
-
dm_first_bid = dm_result.dig('tick', 'bids')[0][0].to_f
|
25
|
-
spot_first_bid = spot_result.dig('tick', 'bids')[0][0].to_f
|
26
|
-
margin_annual = (((dm_first_bid - spot_first_bid) / spot_first_bid) / days_remain * 365 * 100).round(6)
|
27
|
-
margin_expect = margin_annual / 365 * days_remain
|
28
|
-
base_gap = dm_first_bid - spot_first_bid
|
29
|
-
gap_rate = base_gap / dm_first_bid * 100
|
30
|
-
real_margin_expect = (1.0 / spot_first_bid - 1.0 / dm_first_bid) * spot_first_bid * 100
|
31
|
-
result = {
|
32
|
-
coin: "#{coin}_#{t}",
|
33
|
-
margin: margin_annual,
|
34
|
-
days: days_remain,
|
35
|
-
expected_margin: margin_expect,
|
36
|
-
real_margin_expected: real_margin_expect,
|
37
|
-
dm_first_bid: dm_first_bid,
|
38
|
-
spot_first_bid: spot_first_bid,
|
39
|
-
base_gap: base_gap,
|
40
|
-
gap_rate: gap_rate
|
41
|
-
}
|
23
|
+
result = cals dm_result, spot_result, coin, t
|
42
24
|
results.push(result)
|
43
25
|
end
|
44
26
|
end
|
@@ -54,14 +36,38 @@ module Watchcow
|
|
54
36
|
}
|
55
37
|
end
|
56
38
|
|
39
|
+
private
|
40
|
+
|
57
41
|
def days_remain_of symbol, t
|
58
|
-
|
59
|
-
line =
|
42
|
+
contract_info = Watchcow::ContractInfo.call
|
43
|
+
line = contract_info.dig('data').select do |h|
|
60
44
|
h.dig('symbol') == symbol.upcase && h.dig('contract_type') == Watchcow::ApiSymbol.mapping[t]
|
61
45
|
end.first
|
62
46
|
contract_time = "#{line.dig("delivery_date").to_date.to_s} 16:00".in_time_zone('Asia/Chongqing').to_time
|
63
47
|
((contract_time - Time.now.to_time) / 1.hours) / 24
|
64
48
|
end
|
49
|
+
|
50
|
+
def cals dm_result, spot_result, coin, t
|
51
|
+
days_remain = days_remain_of(coin, t)
|
52
|
+
dm_first_bid = dm_result.dig('tick', 'bids')[0][0].to_f
|
53
|
+
spot_first_bid = spot_result.dig('tick', 'bids')[0][0].to_f
|
54
|
+
margin_annual = (((dm_first_bid - spot_first_bid) / spot_first_bid) / days_remain * 365 * 100).round(6)
|
55
|
+
margin_expect = margin_annual / 365 * days_remain
|
56
|
+
base_gap = dm_first_bid - spot_first_bid
|
57
|
+
gap_rate = base_gap / dm_first_bid * 100
|
58
|
+
real_margin_expect = (1.0 / spot_first_bid - 1.0 / dm_first_bid) * spot_first_bid * 100
|
59
|
+
result = {
|
60
|
+
coin: "#{coin}_#{t}",
|
61
|
+
margin: margin_annual,
|
62
|
+
days: days_remain,
|
63
|
+
expected_margin: margin_expect,
|
64
|
+
real_margin_expected: real_margin_expect,
|
65
|
+
dm_first_bid: dm_first_bid,
|
66
|
+
spot_first_bid: spot_first_bid,
|
67
|
+
base_gap: base_gap,
|
68
|
+
gap_rate: gap_rate
|
69
|
+
}
|
70
|
+
end
|
65
71
|
end
|
66
72
|
end
|
67
73
|
end
|
data/lib/watchcow/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2021-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|