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 +4 -4
- data/lib/stockcruncher/cli.rb +20 -3
- data/lib/stockcruncher/influxdb.rb +14 -3
- data/lib/stockcruncher/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d575ec081ba8f154b940a03a7eda7d79606bc78ff9c01132f2da78170b641367
|
4
|
+
data.tar.gz: 5949b3b5108d9d0d67907e49711ae9ecf8dbdfebfba669b9ed952f8592cfa95a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f3dbd7ade6b0ad21e39842111ba21aa21ddf38ac0d984a24cf786a9bcd503c5427b85c5e5c500a0acc278fda9e83a08472144117148a8f624c49c724269884c
|
7
|
+
data.tar.gz: 98690a9871f4d68c2a199cdbcce134690a12b594aba5c4842f4c36346dcd143b8ea15079ff69e7996af19958a1feec5859340e0ea6657d3c649c24cc66007832
|
data/lib/stockcruncher/cli.rb
CHANGED
@@ -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)
|
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)
|
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)
|
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
|
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.
|
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-
|
11
|
+
date: 2021-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|