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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 241ac82617b49386e5ab3b2291a0d5a0e6f6f792a1184ad5956ec5eedce56d5e
4
- data.tar.gz: a70bb34fe89fdc62138e2efbb8dcc7119f5e07d58672c4c9bb6923da95ab1bd1
3
+ metadata.gz: 7db21286fcb1a011326db3d27333b3417ec497db6c5b005250e0dcc11d355839
4
+ data.tar.gz: 1eca29b839ae84d43c601f793501237cabc5de25363ea1bd55f6c707393d98ba
5
5
  SHA512:
6
- metadata.gz: 5e80e2f64b55ea2df59ca62d2407ea7d534568d0bcdbd75eed6c0df233fc16f9e9c0651213f0d53401a9ac336eb4fb4e4325d874fb299ce8ba01dee53c7d25d0
7
- data.tar.gz: 875c0bcca1eab089286a7ecb94979db433d15d6cb5c4a45fccc46695615da632aa48f68ae3119a908287f127cee0dd93f24319e02d45103148eb7acdad992de8
6
+ metadata.gz: 3b46cbfbd3bf8117a5076691d9eaa8985ea551d822838e69cf4336a97161e77d3c0ab5b9427f957a08a219a19290d76832527cadbf2956d16053762443e8f25b
7
+ data.tar.gz: b082544cd2ac1c4a36a5e23a7ce2da9764fd9ce4fa7f09a72b28a579301eb007fda3ea8c8856cb5f9a9fea6756d2c6ee2a4d84224195840793ff49d1c7985855
@@ -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.6
1
+ 0.1.7
@@ -60,6 +60,8 @@ module Cotcube
60
60
  :trading_hours,
61
61
  # receive id / symbol information on an uncertain set of parameters
62
62
  :get_id_set,
63
+ :select_specific_date,
64
+ :extended_select_for_range,
63
65
  :provide_cached,
64
66
  :compare,
65
67
  :holidays,
@@ -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
- return base
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
- return base
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
- "returning '[ ]'".colorize(:light_red)
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
- base
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
- data
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
- x[:volume].select do
123
- x[:contract] == k
124
- end
125
- end.size
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 :raw, :_24x7_, :full and :rth (and custom named, if provided as file)
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
- base = provide_daily contract: contract, symbol: symbol, id: id, config: config
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.6
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-07 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport