stockcruncher 1.3.2 → 1.4.0

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: 56cbc10941fcfdc6ccee0273cf5b2f43f4a98c1f3b53b1554a53ea45020c604e
4
- data.tar.gz: ce451b4498697f9c6148167771296219c4f83ffdef3f1fbefb4c8a12f7a747e4
3
+ metadata.gz: d575ec081ba8f154b940a03a7eda7d79606bc78ff9c01132f2da78170b641367
4
+ data.tar.gz: 5949b3b5108d9d0d67907e49711ae9ecf8dbdfebfba669b9ed952f8592cfa95a
5
5
  SHA512:
6
- metadata.gz: 5b3bcfdbe1805e95c4729e33ad26b4ea676d63a5e638150fca0a26d75682a96d6d4d71a16e9458ef75423f82fc4ba0a4f7442e838865ac9d27b57fbb817dbaed
7
- data.tar.gz: fbe77bb52c0b0d51d6f480246c9467ca4838f9afd385e573c35342b40ada8973f0f5f52c65d159ae85f332d8e0a38e244cf5149b386dc10872323d5990726451
6
+ metadata.gz: 6f3dbd7ade6b0ad21e39842111ba21aa21ddf38ac0d984a24cf786a9bcd503c5427b85c5e5c500a0acc278fda9e83a08472144117148a8f624c49c724269884c
7
+ data.tar.gz: 98690a9871f4d68c2a199cdbcce134690a12b594aba5c4842f4c36346dcd143b8ea15079ff69e7996af19958a1feec5859340e0ea6657d3c649c24cc66007832
@@ -45,12 +45,20 @@ module StockCruncher
45
45
  default: false,
46
46
  desc: 'Full data size.'
47
47
  )
48
+ option(
49
+ :catchup,
50
+ aliases: ['-u'],
51
+ type: :boolean,
52
+ default: false,
53
+ desc: 'Catch up the missing data only.'
54
+ )
48
55
  def daily(symbol)
49
56
  opts = options.dup
50
57
  config = YAML.load_file(opts['config'])
51
58
  cruncher = StockCruncher::AlphaVantage.new(config, opts['insecure'])
52
59
  data = cruncher.crunch_daily(symbol, opts['full'])
53
- StockCruncher::InfluxDB.new(config).export_history(symbol, data)
60
+ influx = StockCruncher::InfluxDB.new(config)
61
+ influx.export_history(symbol, data, opts['catchup'])
54
62
  puts JSON.pretty_generate(data) unless opts['quiet']
55
63
  end
56
64
 
@@ -63,10 +71,18 @@ module StockCruncher
63
71
  default: false,
64
72
  desc: 'Recalculate all MA historical values.'
65
73
  )
74
+ option(
75
+ :catchup,
76
+ aliases: ['-u'],
77
+ type: :boolean,
78
+ default: false,
79
+ desc: 'Catch up the missing data only.'
80
+ )
66
81
  def movingaverages(symbol)
67
82
  opts = options.dup
68
83
  config = YAML.load_file(opts['config'])
69
- StockCruncher::InfluxDB.new(config).moving_averages(symbol, opts['all'])
84
+ influx = StockCruncher::InfluxDB.new(config)
85
+ influx.moving_averages(symbol, opts['all'], opts['catchup'])
70
86
  end
71
87
 
72
88
  desc('quote SYMBOL [options]',
@@ -76,7 +92,8 @@ module StockCruncher
76
92
  config = StockCruncher::Config.load(opts['config'])
77
93
  cruncher = StockCruncher::AlphaVantage.new(config, opts['insecure'])
78
94
  data = cruncher.crunch_quote(symbol)
79
- StockCruncher::InfluxDB.new(config).export_last_day(data)
95
+ influx = StockCruncher::InfluxDB.new(config)
96
+ influx.export_last_day(data)
80
97
  puts JSON.pretty_generate(data) unless opts['quiet']
81
98
  end
82
99
  end
@@ -20,15 +20,22 @@ module StockCruncher
20
20
  data['columns'].zip(data['values'].transpose).to_h
21
21
  end
22
22
 
23
+ def get_ma_values(symbol, fullsize)
24
+ values = %w[ema200]
25
+ data = query('ema', symbol, values, fullsize)
26
+ data['columns'].zip(data['values'].transpose).to_h
27
+ end
28
+
23
29
  # Method to calculate moving averages based on last day values
24
- def moving_averages(symbol, fullsize)
30
+ def moving_averages(symbol, fullsize, catchup)
25
31
  series = get_daily_values(symbol, fullsize)
32
+ mas = catchup ? get_ma_values(symbol, fullsize) : {}
26
33
  tags = create_tags(symbol)
27
34
  series['close'].each_index do |i|
28
35
  date = series['time'][i]
29
36
  serie = series['close'][i, 201]
30
37
  weights = series['volume'][i, 201]
31
- write_moving_averages(tags, serie, weights, date)
38
+ write_moving_averages(tags, serie, weights, date) unless mas.key? date
32
39
  break unless fullsize
33
40
  end
34
41
  end
@@ -39,8 +46,12 @@ module StockCruncher
39
46
  end
40
47
 
41
48
  # Method to export historical data to database
42
- def export_history(symbol, timeseries)
49
+ def export_history(symbol, timeseries, catchup)
43
50
  tags = create_tags(symbol)
51
+ if catchup
52
+ series = get_daily_values(symbol, fullsize)
53
+ series['time'].each { |date| timeseries.delete(date) }
54
+ end
44
55
  timeseries.each_pair do |date, values|
45
56
  write('daily', tags, values, date)
46
57
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module StockCruncher
5
- VERSION = '1.3.2'
5
+ VERSION = '1.4.0'
6
6
  end
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.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Delaplace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2021-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler