cotcube-cftcsource 0.1.1 → 0.1.2.1

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: 75a8631a91ea90a9fdf4505c9265508cfac8b06d385ab1b41f2e5683876e8617
4
- data.tar.gz: db8caed963d6dcd7dc13d29faac945965bf1b55dfbeb36ce51a89ace235c149a
3
+ metadata.gz: '039cece5ef2151259826355643ab8152ff6d1c9f8a2b5d82cac3ace762116e1f'
4
+ data.tar.gz: 65fc1e380a478b512eb73d8a616eef82f1ab230364b9d1f6b32333220cb91661
5
5
  SHA512:
6
- metadata.gz: 38aa716749ec46151657f0e503019ba05de75b3f26e461a7df850ba3b3580f7ece53b00ed9bc9fde3f667200dd74972060fdf7f71f8a1d13403b6238943fa060
7
- data.tar.gz: d53d40b0b11e515b8cc405e915aca658e1fbafeb5a8b9cd6dc495bfb338bcd76daff3934a9c1e4674e3b147c28e74652cc733dd11914984a8534862e4a361d75
6
+ metadata.gz: 814b0ff7264211aad78993a3dcfbd382e56b5a33d1796bb1c9f1017ebab9221b98ee6bf1e2b4ff3a11b0a0a9304ebd486188a54619ce72354dd7c97c6960dfab
7
+ data.tar.gz: 402253ffafe44e028a9ef86046f6f206d7f50195a6f9e7dc779d0ddce6d3dce4836e630f76ebaa3e11d7b3d31a857de2322d73c801a2b25aaeef3ef58d0da70e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 0.1.2.1 (July 25, 2021)
2
+ - series / provide: adopted proper Helpers.symbols usage
3
+ - bin/signals added :lookback parameter
4
+ - using .symbols from Helpers
5
+ - init.rb: added format support (due update symbols.csv)
6
+ - some minor bugs + enhanced debug output in .distribute
7
+ - minor enhancement in debug output
8
+ - added TODO: make cc::cftcs::private another gem
9
+ - added bounded versions to gemspec
10
+
11
+ ## 0.1.2 (December 30, 2020)
12
+ - minor change to README.md
13
+ - minor changes
14
+
1
15
  ## 0.1.1 (December 12, 2020)
2
16
 
3
17
 
data/README.md CHANGED
@@ -70,6 +70,7 @@ Returns the requested series of raw COT data for given either :symbol or :id. Th
70
70
  Based on the data returned by CftcSource.provide and the given indicator set, a series is created, cached and returned.
71
71
 
72
72
  The default indicator simply calculates the net positions for pairs of `_long` and `_short`. Other indicator sets can be created. A simple example is in `etc/cotcube/indicators-example.rb`.
73
+
73
74
  ## Development
74
75
 
75
76
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2.1
data/bin/signals.rb CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  require_relative '../lib/cotcube-cftcsource.rb'
4
4
 
5
- s = Cotcube::CftcSource.signals symbol: ARGV[0], report: ARGV[1].downcase.to_sym, human: false, count: 800, quiet: true
6
- s.each {|x| puts x}
5
+ if ARGV[0].nil?
6
+ raise ArgumentError, "Need symbol to continue"
7
+ end
8
+ symbol = ARGV[0].upcase
9
+ lookback = ARGV[1].nil? ? 55 : ARGV[1].to_i
10
+ report = ARGV[2].nil? ? :legacy : ARGV[2].downcase
11
+ filter = ARGV[3].nil? ? nil : /_#{ARGV[3].downcase}_/
7
12
 
13
+ s = Cotcube::CftcSource.signals symbol: symbol, lookback: lookback, report: report.to_sym, human: false, count: 800, quiet: true, filter: filter
14
+ s.each {|x| puts x}
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.email = ['donkeybridge@jtown.eu']
8
8
 
9
9
  spec.summary = 'Functions to download and process COT data, aggregated into a module'
10
- spec.description = 'Functions to download and process COT data, aggregated into a module'
10
+ spec.description = 'Functions to download and process COT data, aggregated into a module '
11
11
 
12
12
  spec.homepage = 'https://github.com/donkeybridge/'+ spec.name
13
13
  spec.license = 'BSD-4-Clause'
@@ -26,15 +26,16 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
- spec.add_dependency 'cotcube-indicators'
30
- spec.add_dependency 'yaml'
31
- spec.add_dependency 'activesupport'
32
- spec.add_dependency 'colorize'
33
- spec.add_dependency 'httparty'
34
- spec.add_dependency 'rubyzip'
29
+ spec.add_dependency 'cotcube-indicators', '~> 0.1.10'
30
+ spec.add_dependency 'cotcube-helpers', '~> 0.1'
31
+ spec.add_dependency 'yaml', '~> 0.1'
32
+ spec.add_dependency 'activesupport', '~> 6'
33
+ spec.add_dependency 'colorize', '~> 0.8'
34
+ spec.add_dependency 'httparty', '~> 0.16'
35
+ spec.add_dependency 'rubyzip', '~> 2.3'
35
36
 
36
37
 
37
- spec.add_development_dependency 'rake'
38
+ spec.add_development_dependency 'rake', '~> 13'
38
39
  spec.add_development_dependency 'rspec', '~>3.6'
39
40
  spec.add_development_dependency 'yard', '~>0.9'
40
41
  end
@@ -4,6 +4,7 @@
4
4
  # require 'rubygems/package'
5
5
  require 'active_support'
6
6
  require '../ci-dev/lib/cotcube-indicators'
7
+ require 'cotcube-helpers'
7
8
  require 'colorize'
8
9
  require 'date' unless defined?(DateTime)
9
10
  require 'csv' unless defined?(CSV)
@@ -20,18 +21,19 @@ require_relative 'cotcube-cftcsource/distribute'
20
21
  require_relative 'cotcube-cftcsource/provide'
21
22
  require_relative 'cotcube-cftcsource/series'
22
23
 
24
+ # TODO: make these private files another gem, that finally requires _this_ gem to run
23
25
  private_files = Dir[__dir__ + '/cotcube-cftcsource/private/*.rb']
24
26
  private_files.each do |file|
25
- # puts 'Loading private module extension ' + file.chomp
27
+ # # puts 'Loading private module extension ' + file.chomp
26
28
  require file.chomp
27
29
  end
28
30
 
29
31
  module Cotcube
30
32
  module CftcSource
33
+ include Cotcube::Helpers
31
34
  module_function :config_path, # provides the path of configuration directory
32
35
  :config_prefix, # provides the prefix of the configuration directory according to OS-specific FSH
33
36
  :init, # checks whether environment is prepared and returns the config hash
34
- :symbols, # reads and provides the symbols file
35
37
  :date_of_last_report, # returns the date of the currently last locally available report
36
38
  :current_cot_date_on_website, # returns the date of the current report officially available on cftc.gov
37
39
  :fetch, # downloads all (annual) reports, based on given year
@@ -8,18 +8,18 @@ module Cotcube
8
8
  # @param [Hash] opts
9
9
  # @option [Integer, String] Year to be processed, defaults to current year
10
10
 
11
- def distribute(year: Time.now.year, debug: false, config: init)
11
+ def distribute(year: Time.now.year, debug: false, config: init, quiet: false)
12
12
  raw_path = "#{config[:data_path]}/raw"
13
13
  cot_path = "#{config[:data_path]}/cot"
14
14
  CFTC_LINKS.each do |report, a|
15
15
  a.each do |combined, _b|
16
- puts ("Processing #{report}\t#{combined}\t#{year}") if debug
16
+ puts ("Processing #{report}\t#{combined}\t#{year}") unless quiet
17
17
 
18
18
  infile = "#{raw_path}/#{report}_#{combined}_#{year}.csv"
19
19
  outfile = ->(symbol) { "#{cot_path}/#{symbol}/#{report}_#{combined}.csv" }
20
20
 
21
21
  last_report = lambda do |symbol|
22
- CSV.read("#{cot_path}/#{symbol}/#{report}_#{combined}.csv").last[1]
22
+ CSV.parse(`tail -n1 #{cot_path}/#{symbol}/#{report}_#{combined}.csv`).last[1]
23
23
  rescue StandardError
24
24
  '1900-01-01'
25
25
  end
@@ -27,15 +27,18 @@ module Cotcube
27
27
  cache = {}
28
28
  csv_data = CSV.read(infile).tap { |lines| lines.shift if lines[0][0] =~ /Market/ }
29
29
  csv_data.sort_by { |x| x[2] }.each do |line|
30
+ puts "processing #{line.take(5)}" if debug
30
31
  next if line[3].length != 6
31
32
 
32
33
  sym = line[3]
33
34
  cache[sym] ||= last_report.call(sym)
34
- next if cache[sym] >= line[2]
35
+ puts "#{cache[sym]} >= #{line[2]}" if debug
36
+ next if cache[sym] >= line[1]
35
37
 
36
38
  line << "#{report} #{combined}"
37
39
  line.map! { |x| x&.strip }
38
40
  begin
41
+ puts "Writing to #{outfile.call(sym)}: #{line.take(5)}" unless quiet
39
42
  CSV.open(outfile.call(sym), 'a+') { |f| f << line }
40
43
  rescue StandardError
41
44
  puts ("Found new id: #{sym}").colorize(:light_green)
@@ -50,7 +53,8 @@ module Cotcube
50
53
  # print list
51
54
 
52
55
  def available_cftc_ids(config: init, print: true, sort: :exchange)
53
- result = CSV.parse(`find #{init[:data_path]}/cot/* | grep legacy | xargs head -n1 | grep , | awk -v FS=, -v OFS=, '{print $5,$4,$1}' | sed 's/"//g' | sort | uniq`.chomp, headers: %i{ exchange id name }).map{|x| x.to_h}
56
+ command = %Q[find #{init[:data_path]}/cot/* | grep legacy | xargs head -n1 | grep , | awk -v FS=, -v OFS=, '{print $5,$4,$1}' | sed 's/"//g' | sort | uniq]
57
+ result = CSV.parse(`#{command}`.chomp, headers: %i{ exchange id name }).map{|x| x.to_h}
54
58
  result = result.uniq{|row| row[:id] }
55
59
  if print
56
60
  result.sort_by{|x| x[sort]}.each {|row| puts "#{row[:exchange]}\t#{row[:id]}\t#{row[:name]}" }
@@ -10,6 +10,7 @@ module Cotcube
10
10
  # @param [Boolean] debug
11
11
  # @param [Hash] config
12
12
  def fetch(year: Time.now.year, debug: false, silent: false, config: init)
13
+ recent_report_date = `tail -n1 #{config[:data_path]}/cot/13874A/legacy_com.csv | cut -d ',' -f 3`.chomp
13
14
 
14
15
  CFTC_LINKS.each do |report, a|
15
16
  a.each do |combined, _b|
@@ -28,8 +29,10 @@ module Cotcube
28
29
  File.write(file, file_data)
29
30
 
30
31
  puts "Contents have been written to '#{file}'." if debug
31
- print "Check whether current date for #{report}_#{combined}_#{year} makes sense: " unless silent
32
- puts `head -n2 #{file} | tail -n1 | cut -d, -f1,3`.chomp.light_white unless silent
32
+ current_report_date = `head -n2 #{file} | tail -n1 | cut -d, -f3`.chomp
33
+ if recent_report_date == current_report_date || current_report_date==''
34
+ puts "#{report}:#{combined}\tLast date '#{current_report_date}' is same as recent_date '#{recent_report_date}', please re_run".colorize(:light_yellow)
35
+ end
33
36
  end
34
37
  end
35
38
  end
@@ -4,17 +4,19 @@ module Cotcube
4
4
  module CftcSource
5
5
 
6
6
 
7
- def symbols(config: init)
8
- if config[:symbols_file].nil?
9
- CFTC_SYMBOL_EXAMPLES
10
- else
11
- CSV
12
- .read(config[:symbols_file], headers: %i{ id symbol ticksize power months type bcf reports name})
13
- .map{|row| row.to_h }
14
- .map{|row| [ :ticksize, :power, :bcf ].each {|z| row[z] = row[z].to_f}; row }
15
- .reject{|row| row[:id].nil? }
16
- end
17
- end
7
+ # def symbols(config: init, type: nil, symbol: nil)
8
+ # type = [type] unless [NilClass, Array].include?(type.class)
9
+ # if config[:symbols_file].nil?
10
+ # SYMBOL_EXAMPLES
11
+ # else
12
+ # CSV.read(config[:symbols_file], headers: %i{ id symbol ticksize power months type bcf reports format name}).
13
+ # map{|row| row.to_h }.
14
+ # map{|row| [ :ticksize, :power, :bcf ].each {|z| row[z] = row[z].to_f}; row }.
15
+ # reject{|row| row[:id].nil? }.
16
+ # tap{|all| all.select!{|x| type.include?(x[:type])} unless type.nil? }.
17
+ # tap{|all| all.select!{|x| symbol.include?(x[:symbol])} unless symbol.nil? }
18
+ # end
19
+ # end
18
20
 
19
21
  def config_prefix
20
22
  os = Gem::Platform.local.os
@@ -15,7 +15,8 @@ module Cotcube
15
15
  after = DateTime.strptime(after, '%Y-%m-%d') if after.is_a? String
16
16
 
17
17
  unless symbol.nil?
18
- symbol_id = symbols.select{|s| s[:symbol] == symbol.to_s.upcase}.first[:id]
18
+ symbol_config = Cotcube::Helpers.symbols(symbol: symbol).first
19
+ symbol_id = symbol_config[:id]
19
20
  raise ArgumentError, "Could not find match in #{config[:symbols_file]} for given symbol #{symbol}" if symbol_id.nil?
20
21
  raise ArgumentError, "Mismatching symbol #{symbol} and given id #{id}" if not id.nil? and symbol_id != id
21
22
  id = symbol_id
@@ -21,7 +21,7 @@ module Cotcube
21
21
  debug: false
22
22
  )
23
23
  raise ArgumentError, "Can only build series with given symbol" if symbol.nil?
24
- symbol_config = symbols.select{|s| s[:symbol] == symbol.to_s.upcase }.first
24
+ symbol_config = Cotcube::Helpers.symbols(symbol: symbol).first
25
25
  raise ArgumentError, "Can only build series with known symbol, '#{symbol}' is unknown." if symbol_config.nil?
26
26
  puts "Using symbol_config '#{symbol_config}'" if debug
27
27
 
metadata CHANGED
@@ -1,113 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-cftcsource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2.1
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: 2020-12-12 00:00:00.000000000 Z
11
+ date: 2021-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cotcube-indicators
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.1.10
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: cotcube-helpers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '0'
40
+ version: '0.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: yaml
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '0.1'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '0.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: activesupport
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: '6'
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: '6'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: colorize
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: '0.8'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '0.8'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: httparty
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ">="
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: '0.16'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: '0.16'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubyzip
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ">="
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: '2.3'
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ">="
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: '2.3'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: '13'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ">="
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: '13'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rspec
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +150,7 @@ dependencies:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0.9'
139
- description: Functions to download and process COT data, aggregated into a module
153
+ description: 'Functions to download and process COT data, aggregated into a module '
140
154
  email:
141
155
  - donkeybridge@jtown.eu
142
156
  executables: []