cotcube-bardata 0.1.4 → 0.1.5

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: ad166746ea75e103e71ce235710267f98fc6a1b13705b73dc978bd0001b282ed
4
- data.tar.gz: 94b63c1eab7181655f99484ffcb27a29eadef2e2befa03e0301e1f82dc5e2b42
3
+ metadata.gz: c6685b99ba2fcbd933356ebefad21f83c3ec641101b8772419c030b3d197f0de
4
+ data.tar.gz: 825d415ff9c9f3a5ffe072ff1cec47e8238ce63399c9c7519e7a496392aef4f8
5
5
  SHA512:
6
- metadata.gz: 07a2d4ffc5291c1474f14c49ce1d9d42804b2a5bb5ce9fabfef048904a7d8455a106381e76ec6c8bbe05feeda50afb9db9b6f56087c572b704bbce2e7ab313c9
7
- data.tar.gz: d3e83e577ad407550ab590dcd8b5c2880c05939197b80d67a07de117d2ffba918adc852f1de87e16b7262e22d71c53a1bd789d700b6ae3ef82be645adc532b52
6
+ metadata.gz: dff1e21c1076d0d566a088a0e8af2955abaf4d9d3c26ddfa33685f4b8fa660744dfbd3210ede01badf71bd85398cb064d292f0ec6998f7784d3db4f06bac2b88
7
+ data.tar.gz: ed811a9909dc7c08b08030c07b8c4ee811c13e1313a7481d8747f4ca4107b0597f5abde1e2eb8f78ac907e15f37aa494398144df565e354b00042b41bc00265e
@@ -1,3 +1,6 @@
1
+ ## 0.1.5 (January 02, 2021)
2
+ - applied some still missing cops
3
+
1
4
  ## 0.1.4 (January 02, 2021)
2
5
  - two minor fixes (cached.rb, daily.rb)
3
6
  - adding first (shy) specs ... to be continued
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -3,35 +3,34 @@
3
3
  module Cotcube
4
4
  # missing top level documentation
5
5
  module Bardata
6
-
7
6
  # send pre-created days based on quarters
8
- def provide_cached(contract:,
7
+ def provide_cached(contract:, # rubocop:disable Metrics/ParameterLists
9
8
  symbol: nil, id: nil,
10
9
  config: init,
11
10
  timezone: Time.find_zone('America/Chicago'),
12
- set: :full, # most probably either :full or :rth
13
- force_update: false, # force reloading via provide_quarters
14
- force_recent: false) #
11
+ filter: :full, # most probably either :full or :rth
12
+ force_update: false, # force reloading via provide_quarters
13
+ force_recent: false) #
15
14
 
16
15
  headers = %i[contract datetime open high low close volume]
17
16
  sym = get_id_set(symbol: symbol, id: id, contract: contract)
18
- contract = contract[-3..-1]
19
- dir = "#{config[:data_path]}/cached/#{sym[:id]}_#{set.to_s.downcase}"
20
- symlink = "#{config[:data_path]}/cached/#{sym[:symbol]}_#{set.to_s.downcase}"
17
+ contract = contract[-3..]
18
+ dir = "#{config[:data_path]}/cached/#{sym[:id]}_#{filter.to_s.downcase}"
19
+ symlink = "#{config[:data_path]}/cached/#{sym[:symbol]}_#{filter.to_s.downcase}"
21
20
  `mkdir -p #{dir}` unless Dir.exist? dir
22
21
  `ln -s #{dir} #{symlink}` unless File.exist? symlink
23
22
  file = "#{dir}/#{contract}.csv"
24
- quarters_file = "#{config[:data_path]}/quarters/#{sym[:id]}/#{contract[-3..-1]}.csv"
25
- if File.exist?(file) and not force_update
26
- base = CSV.read(file, headers: headers).map{|x|
23
+ quarters_file = "#{config[:data_path]}/quarters/#{sym[:id]}/#{contract[-3..]}.csv"
24
+ if File.exist?(file) && (not force_update)
25
+ base = CSV.read(file, headers: headers).map do |x|
27
26
  x = x.to_h
28
27
  x[:datetime] = timezone.parse(x[:datetime])
29
- %i[open high low close].each{|z| x[z] = x[z].to_f.round(9)}
28
+ %i[open high low close].each { |z| x[z] = x[z].to_f.round(9) }
30
29
  x[:volume] = x[:volume].to_i
31
- x[:type] = "#{set.to_s.downcase}_day".to_sym
30
+ x[:type] = "#{filter.to_s.downcase}_day".to_sym
32
31
  x
33
- }
34
- if base.last[:high].zero?
32
+ end
33
+ if base.last[:high].zero?
35
34
  # contract exists but is closed (has the CLOSED marker)
36
35
  base.pop
37
36
  return base
@@ -41,40 +40,40 @@ module Cotcube
41
40
  puts "File #{file} exists, but is neither closed nor current. Running update.".colorize(:light_green)
42
41
  end
43
42
  end
44
- begin
43
+ begin
45
44
  data = provide_quarters(contract: contract, id: sym[:id], keep_marker: true)
46
- rescue
47
- puts "Cannot provide quarters for requested contract #{sym[:symbol]}:#{contract}, returning '[ ]'".colorize(:light_red)
48
- return []
45
+ rescue StandardError
46
+ puts "Cannot provide quarters for requested contract #{sym[:symbol]}:#{contract},"\
47
+ "returning '[ ]'".colorize(:light_red)
48
+ return []
49
49
  end
50
50
 
51
51
  # removing marker if existing
52
52
  contract_is_marked = data.last[:high].zero?
53
53
  data.pop if contract_is_marked
54
- unless set == :full or data.size < 3
55
- requested_set = trading_hours(symbol: sym[:symbol], set: set)
56
- data = data.select_within(ranges: requested_set, attr: :datetime) {|x| x.to_datetime.to_sssm }
54
+ unless (filter == :full) || (data.size < 3)
55
+ requested_set = trading_hours(symbol: sym[:symbol], set: filter)
56
+ data = data.select_within(ranges: requested_set, attr: :datetime) { |x| x.to_datetime.to_sssm }
57
57
  end
58
58
 
59
59
  base = Cotcube::Helpers.reduce(bars: data, to: :days)
60
60
 
61
61
  # remove last day of result if not marked
62
- base.pop unless contract_is_marked or force_recent
62
+ base.pop unless contract_is_marked || force_recent
63
63
 
64
- base.map do |x|
64
+ base.map do |x|
65
65
  x[:datetime] = x[:datetime].to_date
66
- x[:type]= "#{set}_day".to_sym
66
+ x[:type] = "#{filter}_day".to_sym
67
67
  x.delete(:day)
68
68
  end
69
69
  CSV.open(file, 'w') do |csv|
70
- base.each{|b| csv << b.values_at(*headers) }
70
+ base.each { |b| csv << b.values_at(*headers) }
71
71
  if contract_is_marked
72
- marker = [ "#{sym[:symbol]}#{contract}",base.last[:datetime]+1.day,0,0,0,0,0 ]
72
+ marker = ["#{sym[:symbol]}#{contract}", base.last[:datetime] + 1.day, 0, 0, 0, 0, 0]
73
73
  csv << marker
74
74
  end
75
75
  end
76
76
  base
77
77
  end
78
-
79
78
  end
80
79
  end
@@ -4,7 +4,10 @@ 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:, symbol: nil, id: nil, timezone: Time.find_zone('America/Chicago'), config: init)
7
+ def provide_daily(contract:,
8
+ symbol: nil, id: nil,
9
+ timezone: Time.find_zone('America/Chicago'),
10
+ config: init)
8
11
  contract = contract.to_s.upcase
9
12
  unless contract.is_a?(String) && [3, 5].include?(contract.size)
10
13
  raise ArgumentError, "Contract '#{contract}' is bogus, should be like 'M21' or 'ESM21'"
@@ -96,6 +99,7 @@ module Cotcube
96
99
 
97
100
  sym = get_id_set(symbol: symbol, id: id)
98
101
  id = sym[:id]
102
+ # noinspection RubyNilAnalysis
99
103
  data = continuous(id: id, config: config).map do |x|
100
104
  {
101
105
  date: x[:date],
@@ -15,7 +15,8 @@ module Cotcube
15
15
  date: last_trade_date,
16
16
  filter: :volume_part,
17
17
  age: 1.hour)
18
- sym = get_id_set(symbol: symbol, id: id) if symbol or id
18
+ sym = get_id_set(symbol: symbol, id: id) if symbol || id
19
+ # noinspection RubyScope
19
20
  eods = provide_eods(id: sym.nil? ? nil : sym[:id], config: config, dates: date, filter: filter)
20
21
  result = []
21
22
  eods.map do |eod|
@@ -79,26 +79,29 @@ module Cotcube
79
79
 
80
80
  def compare(contract:, format: '%5.2f')
81
81
  format = "%#{format}" unless format[0] == '%'
82
- daily = provide(contract: contract, type: :daily)
83
- full = provide(contract: contract, type: :days, set: :full)
84
- rth = provide(contract: contract, type: :days, set: :rth)
85
- rth_dates = rth.map{|x| x[:datetime] }
86
- daily.select!{ |x| rth_dates.include? x[:datetime] }
87
- full.select!{ |x| rth_dates.include? x[:datetime] }
82
+ daily = provide(contract: contract, interval: :daily)
83
+ full = provide(contract: contract, interval: :days, filter: :full)
84
+ rth = provide(contract: contract, interval: :days, filter: :rth)
85
+ rth_dates = rth.map { |x| x[:datetime] }
86
+ daily.select! { |x| rth_dates.include? x[:datetime] }
87
+ full.select! { |x| rth_dates.include? x[:datetime] }
88
88
 
89
- printer = lambda {|z| "#{z[:datetime].strftime("%m-%d")
90
- }\t#{format format, z[:open]
91
- }\t#{format format, z[:high]
92
- }\t#{format format, z[:low]
93
- }\t#{format format, z[:close]
94
- }\t#{format '%7d', z[:volume]}" }
95
- daily.each_with_index do |x, i|
89
+ printer = lambda { |z|
90
+ # rubocop:disable Layout/ClosingParenthesisIndentation
91
+ "#{z[:datetime].strftime('%m-%d') # rubocop:disable Layout/IndentationWidth
92
+ }\t#{format format, z[:open]
93
+ }\t#{format format, z[:high]
94
+ }\t#{format format, z[:low]
95
+ }\t#{format format, z[:close]
96
+ }\t#{format '%7d', z[:volume]}"
97
+ # rubocop:enable Layout/ClosingParenthesisIndentation
98
+ }
99
+ daily.each_with_index do |_x, i|
96
100
  puts "DAILY #{printer.call daily[i]}"
97
101
  puts "FULL #{printer.call full[i]}"
98
102
  puts "RTH #{printer.call rth[i]}"
99
- puts " "
103
+ puts ' '
100
104
  end
101
-
102
105
  end
103
106
  end
104
107
  end
@@ -1,48 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cotcube
4
+ # Missing top level documentation comment
4
5
  module Bardata
5
-
6
- def provide(contract:,
6
+ def provide(contract:, # rubocop:disable Metrics/ParameterLists
7
7
  # Can be like ("2020-12-01 12:00"..."2020-12-14 11:00")
8
- range: nil,
8
+ range: nil,
9
9
  symbol: nil, id: nil,
10
10
  config: init,
11
11
  # supported types are :quarters, :hours, :days, :rth, :dailies, :weeks, :months
12
- type: :days,
13
- # supported fills are :raw, :_24x7_, :full and :rth (and custom named, if provided as file)
14
- set: :full,
12
+ interval: :days,
13
+ # supported filters are :raw, :_24x7_, :full and :rth (and custom named, if provided as file)
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
17
17
  force_recent: false)
18
18
 
19
19
  sym = get_id_set(symbol: symbol, id: id, contract: contract, config: config)
20
20
 
21
- case type
21
+ case interval
22
22
  when :quarters, :hours, :quarter, :hour
23
23
  base = provide_quarters(contract: contract, symbol: symbol, id: id, config: config)
24
24
  base = extended_select_for_range(range: range, base: base) if range
25
- requested_set = trading_hours(symbol: sym[:symbol], set: set)
25
+ requested_set = trading_hours(symbol: sym[:symbol], set: filter)
26
26
 
27
- base = base.select_within(ranges: requested_set, attr: :datetime) {|x| x.to_datetime.to_sssm }
28
- return base if [:quarters, :quarter].include? type
27
+ base = base.select_within(ranges: requested_set, attr: :datetime) { |x| x.to_datetime.to_sssm }
28
+ return base if %i[quarters quarter].include? interval
29
29
 
30
- base = Cotcube::Helpers.reduce(bars: base, to: :hours){|c,b|
31
- c[:day] == b[:day] and c[:datetime].hour == b[:datetime].hour
32
- }
30
+ Cotcube::Helpers.reduce(bars: base, to: :hours) do |c, b|
31
+ c[:day] == b[:day] and c[:datetime].hour == b[:datetime].hour
32
+ end
33
33
 
34
34
  when :days, :weeks, :months
35
- base = provide_cached contract: contract, symbol: symbol, id: id, config: config, set: set, force_recent: force_recent
35
+ base = provide_cached contract: contract, symbol: symbol, id: id, config: config, filter: filter,
36
+ force_recent: force_recent
36
37
  base = extended_select_for_range(range: range, base: base) if range
37
- return base if [:day, :days].include? type
38
- # TODO: Missing implemetation to reduce cached days to weeks or months
39
- raise "Missing implementation to reduce cached days to weeks or months"
38
+ return base if %i[day days].include? interval
39
+
40
+ # TODO: Missing implementation to reduce cached days to weeks or months
41
+ raise 'Missing implementation to reduce cached days to weeks or months'
40
42
  when :dailies, :daily
41
43
  base = provide_daily contract: contract, symbol: symbol, id: id, config: config
42
44
  base = extended_select_for_range(range: range, base: base) if range
43
- return base
45
+ base
44
46
  else
45
- raise ArgumentError, "Unsupported or unknown type '#{type}' in Bardata.provide"
47
+ raise ArgumentError, "Unsupported or unknown interval '#{interval}' in Bardata.provide"
46
48
  end
47
49
  end
48
50
  end
@@ -39,6 +39,5 @@ module Cotcube
39
39
  data.pop if data.last[:high].zero? && (not keep_marker)
40
40
  data
41
41
  end
42
-
43
42
  end
44
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-bardata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin L. Tischendorf