stockcruncher 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stockcruncher.rb +0 -3
- data/lib/stockcruncher/alphavantage.rb +16 -14
- data/lib/stockcruncher/cli.rb +27 -5
- data/lib/stockcruncher/cruncher.rb +1 -1
- data/lib/stockcruncher/version.rb +1 -1
- data/spec/stockcruncher/alphavantage_spec.rb +5 -5
- data/spec/stockcruncher/cli_spec.rb +7 -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: c1fe544c0ab3e0bb05c2cca11cb4363bce698cf88b565d897098420b3b8206ac
|
4
|
+
data.tar.gz: bc0de76838cf286f9c5400ddc368da33ee2bd748f0a5a29ebed653010e183d8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b69c6d91c2160e1e70a339ea68616b27012839b105dcfd0cef5ccf7a9643e3a08fb88738d794cf98e3d4de03e505c32db4a827d45a296d734f7e10d2334eb287
|
7
|
+
data.tar.gz: 44ecc54323e85117c04bb0aa8b9c2ab54421020a2614b01356988700f610264e1e82a07e88d5fd62f62945c1469c508699b3a78c2dad52a73b988e508ce2264d
|
data/lib/stockcruncher.rb
CHANGED
@@ -7,32 +7,34 @@ module StockCruncher
|
|
7
7
|
# This is an data cruncher class for AlphaVantage API.
|
8
8
|
class AlphaVantage < Cruncher
|
9
9
|
API_URL = 'https://www.alphavantage.co/query?'
|
10
|
-
SERIE = {
|
11
|
-
'daily' => 'TIME_SERIES_DAILY',
|
12
|
-
'quote_endpoint' => 'GLOBAL_QUOTE'
|
13
|
-
}.freeze
|
14
10
|
|
15
11
|
# Main method to crunch data.
|
16
|
-
def
|
17
|
-
|
18
|
-
|
12
|
+
def crunch_daily(symbol, opts)
|
13
|
+
url = API_URL + parameters(symbol, 'TIME_SERIES_DAILY') + options_d(opts)
|
14
|
+
res = request(url)
|
15
|
+
puts res.body
|
16
|
+
end
|
19
17
|
|
20
|
-
|
18
|
+
# Main method to crunch data.
|
19
|
+
def crunch_quote(symbol, opts)
|
20
|
+
url = API_URL + parameters(symbol, 'GLOBAL_QUOTE') + options_q(opts)
|
21
21
|
res = request(url)
|
22
22
|
puts res.body
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def options_d(opts)
|
26
|
+
o = '&datatype=' + (opts['json'] ? 'json' : 'csv')
|
27
|
+
o += '&outputsize=' + (opts['full'] ? 'full' : 'compact')
|
28
|
+
o
|
29
|
+
end
|
30
|
+
|
31
|
+
def options_q(opts)
|
26
32
|
o = '&datatype=' + (opts['json'] ? 'json' : 'csv')
|
27
|
-
if serie == 'daily'
|
28
|
-
o += '&outputsize='
|
29
|
-
o += opts['full'] ? 'full' : 'compact'
|
30
|
-
end
|
31
33
|
o
|
32
34
|
end
|
33
35
|
|
34
36
|
def parameters(symbol, serie)
|
35
|
-
p = 'function=' +
|
37
|
+
p = 'function=' + serie
|
36
38
|
p += '&symbol=' + symbol
|
37
39
|
p += '&apikey=' + @config[self.class.name.split('::').last]['apikey']
|
38
40
|
p
|
data/lib/stockcruncher/cli.rb
CHANGED
@@ -11,9 +11,8 @@ module StockCruncher
|
|
11
11
|
puts "StockCruncher version #{StockCruncher::VERSION}"
|
12
12
|
end
|
13
13
|
|
14
|
-
desc('
|
15
|
-
'Crunch SYMBOL stock market data for time series.'
|
16
|
-
'Possible timeseries: daily, quote_endpoint.')
|
14
|
+
desc('daily SYMBOL [options]',
|
15
|
+
'Crunch SYMBOL stock market data for daily time series.')
|
17
16
|
option(
|
18
17
|
:config,
|
19
18
|
aliases: ['-c'],
|
@@ -36,10 +35,33 @@ module StockCruncher
|
|
36
35
|
default: false,
|
37
36
|
desc: 'Full data size.'
|
38
37
|
)
|
39
|
-
def
|
38
|
+
def daily(symbol)
|
40
39
|
opts = options.dup
|
41
40
|
cruncher = StockCruncher::AlphaVantage.new(opts['config'])
|
42
|
-
cruncher.
|
41
|
+
cruncher.crunch_daily(symbol, opts)
|
42
|
+
end
|
43
|
+
|
44
|
+
desc('quote SYMBOL [options]',
|
45
|
+
'Crunch SYMBOL stock market data for last day quote.')
|
46
|
+
option(
|
47
|
+
:config,
|
48
|
+
aliases: ['-c'],
|
49
|
+
type: :string,
|
50
|
+
default: '/etc/stockcruncher/stockcruncher.yml',
|
51
|
+
desc: 'Yaml formatted config file to load ' \
|
52
|
+
'(default to /etc/stockcruncher/stockcruncher.yml).'
|
53
|
+
)
|
54
|
+
option(
|
55
|
+
:json,
|
56
|
+
aliases: ['-j'],
|
57
|
+
type: :boolean,
|
58
|
+
default: false,
|
59
|
+
desc: 'Json format data (default to csv).'
|
60
|
+
)
|
61
|
+
def quote(symbol)
|
62
|
+
opts = options.dup
|
63
|
+
cruncher = StockCruncher::AlphaVantage.new(opts['config'])
|
64
|
+
cruncher.crunch_quote(symbol, opts)
|
43
65
|
end
|
44
66
|
end
|
45
67
|
end
|
@@ -3,14 +3,14 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe StockCruncher::AlphaVantage do
|
6
|
-
context '
|
7
|
-
it 'requests a
|
6
|
+
context 'daily SYM -c spec/files/stockcruncher.yml' do
|
7
|
+
it 'requests a daily time serie.' do
|
8
8
|
expect { start(self) }.to output("{}\n").to_stdout
|
9
9
|
end
|
10
10
|
end
|
11
|
-
context '
|
12
|
-
it 'requests a
|
13
|
-
expect { start(self) }.to
|
11
|
+
context 'quote SYM -c spec/files/stockcruncher.yml' do
|
12
|
+
it 'requests a quote endpoint.' do
|
13
|
+
expect { start(self) }.to output("{}\n").to_stdout
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -10,7 +10,13 @@ describe StockCruncher::CLI do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
context '
|
13
|
+
context 'daily SYM -c spec/files/stockcruncher.yml' do
|
14
|
+
it 'Get the daily time serie for SYM.' do
|
15
|
+
expect { start(self) }.to output("{}\n").to_stdout
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'quote SYM -c spec/files/stockcruncher.yml' do
|
14
20
|
it 'Get the quote for SYM.' do
|
15
21
|
expect { start(self) }.to output("{}\n").to_stdout
|
16
22
|
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.0.
|
4
|
+
version: 1.0.2
|
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-07-
|
11
|
+
date: 2020-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|