cotcube-bardata 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/VERSION +1 -1
- data/lib/cotcube-bardata.rb +2 -0
- data/lib/cotcube-bardata/cached.rb +45 -4
- data/lib/cotcube-bardata/daily.rb +29 -6
- data/lib/cotcube-bardata/provide.rb +3 -6
- 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: 7db21286fcb1a011326db3d27333b3417ec497db6c5b005250e0dcc11d355839
|
4
|
+
data.tar.gz: 1eca29b839ae84d43c601f793501237cabc5de25363ea1bd55f6c707393d98ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b46cbfbd3bf8117a5076691d9eaa8985ea551d822838e69cf4336a97161e77d3c0ab5b9427f957a08a219a19290d76832527cadbf2956d16053762443e8f25b
|
7
|
+
data.tar.gz: b082544cd2ac1c4a36a5e23a7ce2da9764fd9ce4fa7f09a72b28a579301eb007fda3ea8c8856cb5f9a9fea6756d2c6ee2a4d84224195840793ff49d1c7985855
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 0.1.7 (January 14, 2021)
|
2
|
+
- added :range parameter to :provide, hence to :provide_cached, :provide_daily
|
3
|
+
- added forgotten module_functions
|
4
|
+
|
1
5
|
## 0.1.6 (January 07, 2021)
|
2
6
|
- prefering datetime instead date (in helpers and daily)
|
3
7
|
- changed keyword :set to :filter in cached, provide and trading_hours
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/lib/cotcube-bardata.rb
CHANGED
@@ -6,12 +6,28 @@ module Cotcube
|
|
6
6
|
# send pre-created days based on quarters
|
7
7
|
def provide_cached(contract:, # rubocop:disable Metrics/ParameterLists
|
8
8
|
symbol: nil, id: nil,
|
9
|
+
range: nil,
|
9
10
|
config: init,
|
10
11
|
timezone: Time.find_zone('America/Chicago'),
|
11
12
|
filter: :full, # most probably either :full or :rth
|
12
13
|
force_update: false, # force reloading via provide_quarters
|
13
14
|
force_recent: false) #
|
14
15
|
|
16
|
+
unless range.nil? ||
|
17
|
+
range.is_a?(Range) &&
|
18
|
+
[Date, DateTime, ActiveSupport::TimeWithZone].map do |cl|
|
19
|
+
(range.begin.nil? || range.begin.is_a?(cl)) &&
|
20
|
+
(range.end.nil? || range.end.is_a?(cl))
|
21
|
+
end.reduce(:|)
|
22
|
+
raise ArgumentError, 'Range, if given, must be either (Integer..Integer) or (Timelike..Timelike)'
|
23
|
+
end
|
24
|
+
|
25
|
+
unless range.nil?
|
26
|
+
range_begin = range.begin.nil? ? nil : timezone.parse(range.begin.to_s)
|
27
|
+
range_end = range.end.nil? ? nil : timezone.parse(range.end.to_s)
|
28
|
+
range = (range_begin..range_end)
|
29
|
+
end
|
30
|
+
|
15
31
|
headers = %i[contract datetime open high low close volume]
|
16
32
|
sym = get_id_set(symbol: symbol, id: id, contract: contract)
|
17
33
|
contract = contract[-3..]
|
@@ -33,9 +49,27 @@ module Cotcube
|
|
33
49
|
if base.last[:high].zero?
|
34
50
|
# contract exists but is closed (has the CLOSED marker)
|
35
51
|
base.pop
|
36
|
-
|
52
|
+
# rubocop:disable Metrics/BlockNesting
|
53
|
+
result = if range.nil?
|
54
|
+
base
|
55
|
+
else
|
56
|
+
base.select do |x|
|
57
|
+
(range.begin.nil? ? true : x[:datetime] >= range.begin) and
|
58
|
+
(range.end.nil? ? true : x[:datetime] <= range.end)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
return result
|
37
62
|
elsif File.mtime(file) < File.mtime(quarters_file)
|
38
|
-
|
63
|
+
result = if range.nil?
|
64
|
+
base
|
65
|
+
else
|
66
|
+
base.select do |x|
|
67
|
+
(range.begin.nil? ? true : x[:datetime] >= range.begin) and
|
68
|
+
(range.end.nil? ? true : x[:datetime] <= range.end)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
# rubocop:enable Metrics/BlockNesting
|
72
|
+
return result
|
39
73
|
else
|
40
74
|
puts "File #{file} exists, but is neither closed nor current. Running update.".colorize(:light_green)
|
41
75
|
end
|
@@ -44,7 +78,7 @@ module Cotcube
|
|
44
78
|
data = provide_quarters(contract: contract, id: sym[:id], keep_marker: true)
|
45
79
|
rescue StandardError
|
46
80
|
puts "Cannot provide quarters for requested contract #{sym[:symbol]}:#{contract},"\
|
47
|
-
|
81
|
+
"returning '[ ]'".colorize(:light_red)
|
48
82
|
return []
|
49
83
|
end
|
50
84
|
|
@@ -73,7 +107,14 @@ module Cotcube
|
|
73
107
|
csv << marker
|
74
108
|
end
|
75
109
|
end
|
76
|
-
|
110
|
+
if range.nil?
|
111
|
+
base
|
112
|
+
else
|
113
|
+
base.select do |x|
|
114
|
+
(range.begin.nil? ? true : x[:date] >= range.begin) and
|
115
|
+
(range.end.nil? ? true : x[:date] <= range.end)
|
116
|
+
end
|
117
|
+
end
|
77
118
|
end
|
78
119
|
end
|
79
120
|
end
|
@@ -4,14 +4,30 @@ module Cotcube
|
|
4
4
|
# Missing top level documentation comment
|
5
5
|
module Bardata
|
6
6
|
# just reads bardata/daily/<id>/<contract>.csv
|
7
|
-
def provide_daily(contract:,
|
7
|
+
def provide_daily(contract:, # rubocop:disable Metrics/ParameterLists
|
8
8
|
symbol: nil, id: nil,
|
9
|
+
range: nil,
|
9
10
|
timezone: Time.find_zone('America/Chicago'),
|
10
11
|
config: init)
|
11
12
|
contract = contract.to_s.upcase
|
12
13
|
unless contract.is_a?(String) && [3, 5].include?(contract.size)
|
13
14
|
raise ArgumentError, "Contract '#{contract}' is bogus, should be like 'M21' or 'ESM21'"
|
14
15
|
end
|
16
|
+
unless range.nil? ||
|
17
|
+
(range.is_a?(Range) &&
|
18
|
+
[Date, DateTime, ActiveSupport::TimeWithZone].map do |cl|
|
19
|
+
(range.begin.nil? || range.begin.is_a?(cl)) &&
|
20
|
+
(range.end.nil? || range.end.is_a?(cl))
|
21
|
+
end.reduce(:|))
|
22
|
+
|
23
|
+
raise ArgumentError, 'Range, if given, must be either (Integer..Integer) or (Timelike..Timelike)'
|
24
|
+
end
|
25
|
+
|
26
|
+
unless range.nil?
|
27
|
+
range_begin = range.begin.nil? ? nil : timezone.parse(range.begin.to_s)
|
28
|
+
range_end = range.end.nil? ? nil : timezone.parse(range.end.to_s)
|
29
|
+
range = (range_begin..range_end)
|
30
|
+
end
|
15
31
|
|
16
32
|
sym = get_id_set(symbol: symbol, id: id, contract: contract)
|
17
33
|
contract = contract[2..4] if contract.to_s.size == 5
|
@@ -33,7 +49,14 @@ module Cotcube
|
|
33
49
|
row
|
34
50
|
end
|
35
51
|
data.pop if data.last[:high].zero?
|
36
|
-
|
52
|
+
if range.nil?
|
53
|
+
data
|
54
|
+
else
|
55
|
+
data.select do |x|
|
56
|
+
(range.begin.nil? ? true : x[:datetime] >= range.begin) and
|
57
|
+
(range.end.nil? ? true : x[:datetime] <= range.end)
|
58
|
+
end
|
59
|
+
end
|
37
60
|
end
|
38
61
|
|
39
62
|
# reads all files in bardata/daily/<id> and aggregates by date
|
@@ -119,10 +142,10 @@ module Cotcube
|
|
119
142
|
}\t#{v.last[:date]
|
120
143
|
}\t#{format('%4d', (Date.parse(v.last[:date]) - Date.parse(v.first[:date])))
|
121
144
|
}\t#{result[k].map do |x|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
145
|
+
x[:volume].select do
|
146
|
+
x[:contract] == k
|
147
|
+
end
|
148
|
+
end.size
|
126
149
|
}"
|
127
150
|
# rubocop:enable Layout/ClosingParenthesisIndentation
|
128
151
|
end
|
@@ -10,7 +10,7 @@ module Cotcube
|
|
10
10
|
config: init,
|
11
11
|
# supported types are :quarters, :hours, :days, :rth, :dailies, :weeks, :months
|
12
12
|
interval: :days,
|
13
|
-
# supported filters are :
|
13
|
+
# supported filters are :full and :rth (and custom named, if provided as file)
|
14
14
|
filter: :full,
|
15
15
|
# TODO: for future compatibility and suggestion: planning to include a function to update
|
16
16
|
# with live data from broker
|
@@ -33,16 +33,13 @@ module Cotcube
|
|
33
33
|
|
34
34
|
when :days, :weeks, :months
|
35
35
|
base = provide_cached contract: contract, symbol: symbol, id: id, config: config, filter: filter,
|
36
|
-
force_recent: force_recent
|
37
|
-
base = extended_select_for_range(range: range, base: base) if range
|
36
|
+
range: range, force_recent: force_recent
|
38
37
|
return base if %i[day days].include? interval
|
39
38
|
|
40
39
|
# TODO: Missing implementation to reduce cached days to weeks or months
|
41
40
|
raise 'Missing implementation to reduce cached days to weeks or months'
|
42
41
|
when :dailies, :daily
|
43
|
-
|
44
|
-
base = extended_select_for_range(range: range, base: base) if range
|
45
|
-
base
|
42
|
+
provide_daily contract: contract, symbol: symbol, id: id, config: config, range: range
|
46
43
|
else
|
47
44
|
raise ArgumentError, "Unsupported or unknown interval '#{interval}' in Bardata.provide"
|
48
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cotcube-bardata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin L. Tischendorf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|