stockcruncher 1.3.0 → 1.3.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: '00734941064bb0a639312c8908fb983698df14f5ccfe50b5957c0631998d0da7'
4
- data.tar.gz: 5e27da219578442b05ceebc79863d7e02048d1b97a13b5bd5fa6c8939e1fe2a4
3
+ metadata.gz: 6c5f9d2cc2dba8ad0fbd9882cebcda893500e0f029610107004481b0b236d6b9
4
+ data.tar.gz: 65815caea89d856ef4e4c76365df166bdb971302a95f6665d657c0ba6420e671
5
5
  SHA512:
6
- metadata.gz: 27ed506233c74a8690cb75e1e994f5ae639d55e281cd9adde3f2af9b96a675f7043d87395dfd42898af50b6759da7471352716bdd844f3a743ff3f1482ab4dae
7
- data.tar.gz: 9780064a2b3928040b7acbababb3ba47f2b4ca115c750e8765a8d5bce48b7584c3542c87f2f996c31d81a62eb01676324254fd40c3db6778b9913b03599adbd6
6
+ metadata.gz: 19b7f5eafd15cbcc5713a6729e17c3a2ae5dd4c471f0d77c7becb4ba10be08c6c492f4469b7ab4a93858215a406d95fced52cde98cffd0644c081ce331b43e9a
7
+ data.tar.gz: c73d7c0caa396f0cf1b06f88f74e2e1cdbd0c7b7fa1739e4b72df4e5852b16e847a46d09071699db51bc6ed07a85e51766c8259221214d62e845ed15331bc980
data/.gitlab-ci.yml CHANGED
@@ -1,9 +1,11 @@
1
+
1
2
  image: ruby:2.4
2
3
 
4
+ before_script:
5
+ - bundle install
6
+
3
7
  rubocop:
4
8
  stage: test
5
- before_script:
6
- - gem install --silent rubocop
7
9
  script:
8
10
  - rubocop
9
11
 
@@ -25,7 +27,6 @@ git_history:
25
27
  rspec:
26
28
  stage: test
27
29
  script:
28
- - bundle install
29
30
  - rspec
30
31
  artifacts:
31
32
  paths:
data/.rubocop.yml CHANGED
@@ -4,3 +4,4 @@ AllCops:
4
4
  DisplayStyleGuide: true
5
5
  DisplayCopNames: false
6
6
  TargetRubyVersion: 2.4
7
+ NewCops: disable
@@ -39,7 +39,7 @@ module StockCruncher
39
39
  # Main method to crunch data.
40
40
  def crunch_daily(symbol, fullsize)
41
41
  url = API_URL + parameters(symbol, 'TIME_SERIES_DAILY')
42
- url += '&datatype=csv&outputsize=' + (fullsize ? 'full' : 'compact')
42
+ url += "&datatype=csv&outputsize=#{fullsize ? 'full' : 'compact'}"
43
43
  res = request(url)
44
44
  transform_daily(res.body)
45
45
  end
@@ -63,9 +63,9 @@ module StockCruncher
63
63
 
64
64
  # Set parameters of api call
65
65
  def parameters(symbol, serie)
66
- p = 'function=' + serie
67
- p += '&symbol=' + symbol
68
- p += '&apikey=' + @config[self.class.name.split('::').last]['apikey']
66
+ p = "function=#{serie}"
67
+ p += "&symbol=#{symbol}"
68
+ p += "&apikey=#{@config[self.class.name.split('::').last]['apikey']}"
69
69
  p
70
70
  end
71
71
 
@@ -87,8 +87,7 @@ module StockCruncher
87
87
  raise StandardError, 'No data' if rawdata.match?(/Error Message/)
88
88
 
89
89
  values = prepare_daily_timeserie(rawdata)
90
- values = calculate_missing_data(values)
91
- values
90
+ calculate_missing_data(values)
92
91
  end
93
92
 
94
93
  # Method to transform quote result to hash
@@ -73,7 +73,7 @@ module StockCruncher
73
73
  'Crunch SYMBOL stock market data for last day quote.')
74
74
  def quote(symbol)
75
75
  opts = options.dup
76
- config = YAML.load_file(opts['config'])
76
+ config = StockCruncher::Config.load(opts['config'])
77
77
  cruncher = StockCruncher::AlphaVantage.new(config, opts['insecure'])
78
78
  data = cruncher.crunch_quote(symbol)
79
79
  StockCruncher::InfluxDB.new(config).export_last_day(data)
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'yaml'
5
+
6
+ module StockCruncher
7
+ # this is a module to load configuration file and environment variable
8
+ module Config
9
+ module_function
10
+
11
+ # Load config file and override with env variables
12
+ def load(file)
13
+ config = YAML.load_file(file)
14
+ overload_alphavantage(config)
15
+ overload_influxdb(config)
16
+ end
17
+
18
+ def overload(config, prefix, component, items)
19
+ items.each do |key|
20
+ var = "#{prefix}#{key.upcase}"
21
+ config[component][key] = ENV[var] unless ENV[var].nil?
22
+ end
23
+ config
24
+ end
25
+
26
+ def overload_alphavantage(config)
27
+ prefix = 'SCR_AV_'
28
+ component = 'AlphaVantage'
29
+ items = %w[apikey]
30
+ overload(config, prefix, component, items)
31
+ end
32
+
33
+ def overload_influxdb(config)
34
+ prefix = 'SCR_IDB_'
35
+ component = 'InfluxDB'
36
+ items = %w[scheme host port user password dbname]
37
+ overload(config, prefix, component, items)
38
+ end
39
+ end
40
+ end
@@ -95,7 +95,7 @@ module StockCruncher
95
95
  def write(name, tags, values, date)
96
96
  url = "#{@cfg['scheme']}://#{@cfg['host']}:#{@cfg['port']}/write?" \
97
97
  "db=#{@cfg['dbname']}"
98
- timestamp = DateTime.parse(date + 'T18:00:00').strftime('%s%N')
98
+ timestamp = DateTime.parse("#{date}T18:00:00").strftime('%s%N')
99
99
  body = "#{name},#{format_values(tags)} #{format_values(values)} " \
100
100
  "#{timestamp}"
101
101
  request(url, body)
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module StockCruncher
5
- VERSION = '1.3.0'
5
+ VERSION = '1.3.1'
6
6
  end
@@ -8,7 +8,7 @@ dev_deps = {
8
8
  'bundler' => '~> 1.17',
9
9
  'rspec' => '~> 3.9',
10
10
  'rake' => '~> 11.3',
11
- 'rubocop' => '0.88',
11
+ 'rubocop' => '0.90',
12
12
  'webmock' => '~> 2.0.3',
13
13
  'simplecov' => '~> 0.18'
14
14
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stockcruncher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Delaplace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-03 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: '0.88'
61
+ version: '0.90'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: '0.88'
68
+ version: '0.90'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +129,7 @@ files:
129
129
  - lib/stockcruncher.rb
130
130
  - lib/stockcruncher/alphavantage.rb
131
131
  - lib/stockcruncher/cli.rb
132
+ - lib/stockcruncher/config.rb
132
133
  - lib/stockcruncher/cruncher.rb
133
134
  - lib/stockcruncher/influxdb.rb
134
135
  - lib/stockcruncher/stats.rb