alphavantage 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +43 -2
- data/bin/console +1 -1
- data/lib/alphavantage/client.rb +51 -16
- data/lib/alphavantage/crypto.rb +3 -3
- data/lib/alphavantage/forex.rb +6 -6
- data/lib/alphavantage/fundamental.rb +1 -1
- data/lib/alphavantage/indicator.rb +26 -26
- data/lib/alphavantage/time_series.rb +24 -20
- data/lib/alphavantage/validations.rb +29 -20
- data/lib/alphavantage/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4af01723c92ed138d5832918e67d7adb92c107977b12917fc94cbf70306699c3
|
4
|
+
data.tar.gz: b5888849f631c9cf0e355ffe23cffb0a4b93e6e307aeebfb7f6f5f2cc19097d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83346ba63c53cc11074b28895d9fcfc26c554015e280db93af4282573fd447cec3c83d1e41f058a66397ef7b2bd669627f587ae83b0bd7d2fbb276a710ac2bab
|
7
|
+
data.tar.gz: 3f95b5891d4ac386ad01eccf09f15166b7defc1b00afc6369cdad6304e6d2f2ae7b9930584965c5e933f6a9a2a8fb85cd395edc64183abcd62b5fde72a951a2c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -42,9 +42,9 @@ quote.volume #=> "27879033"
|
|
42
42
|
|
43
43
|
All hash keys are also normalized to provide clean and consistent access to values since the Alphavantage API returns arbitrarily formatted keys with numbers, spaces, letters and symbols (i.e. "Crypto Rating (FCAS)", "3. fcas rating", "4. Last Refreshed", "Time Series FX (5min)", "1a. open (CNY)")
|
44
44
|
|
45
|
-
With this normalization, you can now access via
|
45
|
+
With this normalization, you can now access via
|
46
46
|
|
47
|
-
`intraday.time_series_fx_5min`
|
47
|
+
`intraday.time_series_fx_5min`
|
48
48
|
|
49
49
|
instead of
|
50
50
|
|
@@ -64,6 +64,7 @@ stock_timeseries.weekly(adjusted: true)
|
|
64
64
|
stock_timeseries.daily(outputsize: 'compact')
|
65
65
|
stock_timeseries.daily(adjusted: true, outputsize: 'full')
|
66
66
|
stock_timeseries.intraday(adjusted: true, outputsize: 'compact', interval: '5min')
|
67
|
+
stock_timeseries.intraday_extended_history(adjusted: true, outputsize: 'compact', interval: '5min', slice: 'year1month1')
|
67
68
|
```
|
68
69
|
### Fundamental Data
|
69
70
|
```
|
@@ -93,6 +94,46 @@ crypto.daily
|
|
93
94
|
crypto.weekly
|
94
95
|
crypto.monthly
|
95
96
|
```
|
97
|
+
|
98
|
+
### Technical Indicators
|
99
|
+
You can access all available indicators by simply using the actual technical indicator name listed on the [Alpha Vantage Documenetation](https://www.alphavantage.co/documentation/#technical-indicators) as the method name (i.e. `.stoch`, `.rsi`, `.plus_dm`, `.ht_trendline`, etc.).
|
100
|
+
|
101
|
+
You can also dig into [alphavantage/indicator.rb](https://github.com/codespore/alphavantage_ruby/blob/main/lib/alphavantage/indicator.rb) to view the list of available indicators.
|
102
|
+
|
103
|
+
```
|
104
|
+
indicator = Alphavantage::Indicator.new(symbol: 'TSLA', interval: '5min')
|
105
|
+
indicator.sma(time_period: 7, series_type: 'close')
|
106
|
+
indicator.macd(series_type: 'open', fastperiod: 12, slowperiod: 26, signalperiod: 9)
|
107
|
+
|
108
|
+
indicator.macdext(
|
109
|
+
series_type:,
|
110
|
+
fastperiod: 12,
|
111
|
+
slowperiod: 26,
|
112
|
+
signalperiod: 9,
|
113
|
+
fastmatype: 'sma',
|
114
|
+
slowmatype: 'sma',
|
115
|
+
signalmatype: 'sma'
|
116
|
+
)
|
117
|
+
```
|
118
|
+
|
119
|
+
Moving average indicator as parameters have been mapped to allow you to simply provide the actual indicator name rather than the number value specified in the Alpha Vantage Documentation. Below is the mapping available that I've used in the above `.macdext` example for the `fastmatype`, `slowmatype` and `signalmatype` parameters
|
120
|
+
|
121
|
+
```
|
122
|
+
MOVING_AVERAGE_TYPES = {
|
123
|
+
sma: 0,
|
124
|
+
ema: 1,
|
125
|
+
wma: 2,
|
126
|
+
dema: 3,
|
127
|
+
tema: 4,
|
128
|
+
trima: 5,
|
129
|
+
t3: 6,
|
130
|
+
kama: 7,
|
131
|
+
mama: 8
|
132
|
+
}
|
133
|
+
```
|
134
|
+
|
135
|
+
Validations are also implemented to ensure correct values are provided for the various parameters. You can view a list of the validations in [alphavantage/validations.rb](https://github.com/codespore/alphavantage_ruby/blob/main/lib/alphavantage/validations.rb)
|
136
|
+
|
96
137
|
## Development
|
97
138
|
|
98
139
|
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/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
|
-
|
4
|
+
require_relative "../lib/alphavantage"
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
data/lib/alphavantage/client.rb
CHANGED
@@ -1,27 +1,62 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'json'
|
3
|
+
require 'csv'
|
4
|
+
|
1
5
|
module Alphavantage
|
2
6
|
class Client
|
3
7
|
|
4
8
|
class << self
|
5
|
-
def get(params:)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def get(params:, datatype: :json)
|
10
|
+
new(params).public_send(datatype)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize params
|
15
|
+
@params = params
|
16
|
+
end
|
17
|
+
attr_reader :params
|
18
|
+
|
19
|
+
def json
|
20
|
+
Hashie::Mash.new(convert_hash_keys(JSON.parse(response.body))).tap do |response|
|
21
|
+
raise Error, response.error_message if response.error_message
|
12
22
|
end
|
23
|
+
end
|
13
24
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
def csv
|
26
|
+
CSV.parse response.body
|
27
|
+
rescue CSV::MalformedCSVError
|
28
|
+
# if we can not parse it, we probably have JSON from API with an error
|
29
|
+
json
|
30
|
+
raise
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def convert_hash_keys(value)
|
36
|
+
case value
|
37
|
+
when Array
|
38
|
+
value.map { |v| convert_hash_keys(v) }
|
39
|
+
when Hash
|
40
|
+
Hash[value.map { |k, v| [ NormalizeKey.new(key: k).call, convert_hash_keys(v) ] }]
|
41
|
+
else
|
42
|
+
value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def response
|
47
|
+
@response ||= Faraday.get('https://www.alphavantage.co/query') do |req|
|
48
|
+
req.params = default_params.merge(params)
|
49
|
+
end.tap do |response|
|
50
|
+
next if response.status == 200
|
51
|
+
|
52
|
+
raise Error, "Response status: #{response.status}, body: #{response.body}"
|
23
53
|
end
|
24
54
|
end
|
25
55
|
|
56
|
+
def default_params
|
57
|
+
{
|
58
|
+
apikey: Alphavantage.configuration.api_key || raise("Api key is missing")
|
59
|
+
}
|
60
|
+
end
|
26
61
|
end
|
27
62
|
end
|
data/lib/alphavantage/crypto.rb
CHANGED
@@ -11,7 +11,7 @@ module Alphavantage
|
|
11
11
|
}
|
12
12
|
|
13
13
|
def self.health_index(symbol:)
|
14
|
-
Client.get(params: {
|
14
|
+
Client.get(params: {
|
15
15
|
function: self::FUNCTIONS[__method__],
|
16
16
|
symbol: symbol
|
17
17
|
}).crypto_rating_fcas
|
@@ -23,7 +23,7 @@ module Alphavantage
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def intraday(interval: '5min')
|
26
|
-
Client.get(params: {
|
26
|
+
Client.get(params: {
|
27
27
|
function: FUNCTIONS[__method__],
|
28
28
|
symbol: @symbol,
|
29
29
|
market: @market,
|
@@ -32,7 +32,7 @@ module Alphavantage
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def daily
|
35
|
-
Client.get(params: {
|
35
|
+
Client.get(params: {
|
36
36
|
function: FUNCTIONS[__callee__],
|
37
37
|
symbol: @symbol,
|
38
38
|
market: @market
|
data/lib/alphavantage/forex.rb
CHANGED
@@ -2,7 +2,7 @@ module Alphavantage
|
|
2
2
|
class Forex
|
3
3
|
include Validations
|
4
4
|
|
5
|
-
FUNCTIONS = {
|
5
|
+
FUNCTIONS = {
|
6
6
|
exchange_rates: 'CURRENCY_EXCHANGE_RATE',
|
7
7
|
intraday: 'FX_INTRADAY',
|
8
8
|
daily: 'FX_DAILY',
|
@@ -16,7 +16,7 @@ module Alphavantage
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def exchange_rates
|
19
|
-
Client.get(params: {
|
19
|
+
Client.get(params: {
|
20
20
|
function: FUNCTIONS[__method__],
|
21
21
|
from_currency: @from_symbol,
|
22
22
|
to_currency: @to_symbol
|
@@ -24,7 +24,7 @@ module Alphavantage
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def intraday(interval: '5min', outputsize: 'compact')
|
27
|
-
Client.get(params: {
|
27
|
+
Client.get(params: {
|
28
28
|
function: FUNCTIONS[__method__],
|
29
29
|
from_symbol: @from_symbol,
|
30
30
|
to_symbol: @to_symbol,
|
@@ -34,16 +34,16 @@ module Alphavantage
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def daily(outputsize: 'compact')
|
37
|
-
Client.get(params: {
|
37
|
+
Client.get(params: {
|
38
38
|
function: FUNCTIONS[__method__],
|
39
39
|
from_symbol: @from_symbol,
|
40
40
|
to_symbol: @to_symbol,
|
41
41
|
outputsize: validate_outputsize(outputsize)
|
42
42
|
})
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def weekly
|
46
|
-
Client.get(params: {
|
46
|
+
Client.get(params: {
|
47
47
|
function: FUNCTIONS[__callee__],
|
48
48
|
from_symbol: @from_symbol,
|
49
49
|
to_symbol: @to_symbol
|
@@ -8,7 +8,7 @@ module Alphavantage
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def sma(time_period:,series_type:)
|
11
|
-
Client.get(params: {
|
11
|
+
Client.get(params: {
|
12
12
|
function: __callee__.upcase,
|
13
13
|
symbol: @symbol,
|
14
14
|
interval: validate_indicator_interval(@interval),
|
@@ -32,8 +32,8 @@ module Alphavantage
|
|
32
32
|
alias :trix :sma
|
33
33
|
alias :midpoint :sma
|
34
34
|
|
35
|
-
def macd(series_type:, fastperiod: 12, slowperiod: 26, signalperiod: 9)
|
36
|
-
Client.get(params: {
|
35
|
+
def macd(series_type:, fastperiod: 12, slowperiod: 26, signalperiod: 9)
|
36
|
+
Client.get(params: {
|
37
37
|
function: __callee__.upcase,
|
38
38
|
symbol: @symbol,
|
39
39
|
interval: validate_indicator_interval(@interval),
|
@@ -57,15 +57,15 @@ module Alphavantage
|
|
57
57
|
}
|
58
58
|
|
59
59
|
def macdext(
|
60
|
-
series_type:,
|
61
|
-
fastperiod: 12,
|
62
|
-
slowperiod: 26,
|
60
|
+
series_type:,
|
61
|
+
fastperiod: 12,
|
62
|
+
slowperiod: 26,
|
63
63
|
signalperiod: 9,
|
64
64
|
fastmatype: 'sma',
|
65
65
|
slowmatype: 'sma',
|
66
66
|
signalmatype: 'sma'
|
67
67
|
)
|
68
|
-
Client.get(params: {
|
68
|
+
Client.get(params: {
|
69
69
|
function: __callee__.upcase,
|
70
70
|
symbol: @symbol,
|
71
71
|
interval: validate_indicator_interval(@interval),
|
@@ -80,13 +80,13 @@ module Alphavantage
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def stoch(
|
83
|
-
fastkperiod: 5,
|
83
|
+
fastkperiod: 5,
|
84
84
|
slowkperiod: 3,
|
85
85
|
slowdperiod: 3,
|
86
86
|
slowkmatype: 'sma',
|
87
87
|
slowdmatype: 'sma'
|
88
88
|
)
|
89
|
-
Client.get(params: {
|
89
|
+
Client.get(params: {
|
90
90
|
function: __callee__.upcase,
|
91
91
|
symbol: @symbol,
|
92
92
|
interval: validate_indicator_interval(@interval),
|
@@ -99,11 +99,11 @@ module Alphavantage
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def stochf(
|
102
|
-
fastkperiod: 5,
|
102
|
+
fastkperiod: 5,
|
103
103
|
fastdperiod: 3,
|
104
104
|
fastdmatype: 'sma'
|
105
105
|
)
|
106
|
-
Client.get(params: {
|
106
|
+
Client.get(params: {
|
107
107
|
function: __callee__.upcase,
|
108
108
|
symbol: @symbol,
|
109
109
|
interval: validate_indicator_interval(@interval),
|
@@ -116,11 +116,11 @@ module Alphavantage
|
|
116
116
|
def stochrsi(
|
117
117
|
time_period:,
|
118
118
|
series_type:,
|
119
|
-
fastkperiod: 5,
|
119
|
+
fastkperiod: 5,
|
120
120
|
fastdperiod: 3,
|
121
121
|
fastdmatype: 'sma'
|
122
122
|
)
|
123
|
-
Client.get(params: {
|
123
|
+
Client.get(params: {
|
124
124
|
function: __callee__.upcase,
|
125
125
|
symbol: @symbol,
|
126
126
|
interval: validate_indicator_interval(@interval),
|
@@ -133,7 +133,7 @@ module Alphavantage
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def willr(time_period:)
|
136
|
-
Client.get(params: {
|
136
|
+
Client.get(params: {
|
137
137
|
function: __callee__.upcase,
|
138
138
|
symbol: @symbol,
|
139
139
|
interval: validate_indicator_interval(@interval),
|
@@ -155,7 +155,7 @@ module Alphavantage
|
|
155
155
|
alias :natr :willr
|
156
156
|
|
157
157
|
def vwap
|
158
|
-
Client.get(params: {
|
158
|
+
Client.get(params: {
|
159
159
|
function: __callee__.upcase,
|
160
160
|
symbol: @symbol,
|
161
161
|
interval: [:bop,:trange,:ad,:obv].include?(__callee__) ? validate_indicator_interval(@interval) : validate_interval(@interval)
|
@@ -166,8 +166,8 @@ module Alphavantage
|
|
166
166
|
alias :ad :vwap
|
167
167
|
alias :obv :vwap
|
168
168
|
|
169
|
-
def adosc(fastperiod: 3, slowperiod: 10)
|
170
|
-
Client.get(params: {
|
169
|
+
def adosc(fastperiod: 3, slowperiod: 10)
|
170
|
+
Client.get(params: {
|
171
171
|
function: __callee__.upcase,
|
172
172
|
symbol: @symbol,
|
173
173
|
interval: validate_indicator_interval(@interval),
|
@@ -177,7 +177,7 @@ module Alphavantage
|
|
177
177
|
end
|
178
178
|
|
179
179
|
def ht_trendline(series_type:)
|
180
|
-
Client.get(params: {
|
180
|
+
Client.get(params: {
|
181
181
|
function: __callee__.upcase,
|
182
182
|
symbol: @symbol,
|
183
183
|
interval: validate_indicator_interval(@interval),
|
@@ -190,8 +190,8 @@ module Alphavantage
|
|
190
190
|
alias :ht_dcphase :ht_trendline
|
191
191
|
alias :ht_phasor :ht_trendline
|
192
192
|
|
193
|
-
def apo(series_type:, fastperiod: 12, slowperiod: 26, matype: 'sma')
|
194
|
-
Client.get(params: {
|
193
|
+
def apo(series_type:, fastperiod: 12, slowperiod: 26, matype: 'sma')
|
194
|
+
Client.get(params: {
|
195
195
|
function: __callee__.upcase,
|
196
196
|
symbol: @symbol,
|
197
197
|
interval: validate_indicator_interval(@interval),
|
@@ -203,8 +203,8 @@ module Alphavantage
|
|
203
203
|
end
|
204
204
|
alias :ppo :apo
|
205
205
|
|
206
|
-
def bbands(time_period:, series_type:, nbdevup: 2, nbdevdn: 2, matype: 'sma')
|
207
|
-
Client.get(params: {
|
206
|
+
def bbands(time_period:, series_type:, nbdevup: 2, nbdevdn: 2, matype: 'sma')
|
207
|
+
Client.get(params: {
|
208
208
|
function: __callee__.upcase,
|
209
209
|
symbol: @symbol,
|
210
210
|
interval: validate_indicator_interval(@interval),
|
@@ -216,8 +216,8 @@ module Alphavantage
|
|
216
216
|
})
|
217
217
|
end
|
218
218
|
|
219
|
-
def sar(acceleration: 0.01, maximum: 0.20)
|
220
|
-
Client.get(params: {
|
219
|
+
def sar(acceleration: 0.01, maximum: 0.20)
|
220
|
+
Client.get(params: {
|
221
221
|
function: __callee__.upcase,
|
222
222
|
symbol: @symbol,
|
223
223
|
interval: validate_indicator_interval(@interval),
|
@@ -226,8 +226,8 @@ module Alphavantage
|
|
226
226
|
})
|
227
227
|
end
|
228
228
|
|
229
|
-
def ultosc(timeperiod1: 7, timeperiod2: 14, timeperiod3: 28)
|
230
|
-
Client.get(params: {
|
229
|
+
def ultosc(timeperiod1: 7, timeperiod2: 14, timeperiod3: 28)
|
230
|
+
Client.get(params: {
|
231
231
|
function: __callee__.upcase,
|
232
232
|
symbol: @symbol,
|
233
233
|
interval: validate_indicator_interval(@interval),
|
@@ -2,7 +2,7 @@ module Alphavantage
|
|
2
2
|
class TimeSeries
|
3
3
|
include Validations
|
4
4
|
|
5
|
-
FUNCTIONS = {
|
5
|
+
FUNCTIONS = {
|
6
6
|
search: 'SYMBOL_SEARCH',
|
7
7
|
quote: 'GLOBAL_QUOTE',
|
8
8
|
monthly: 'TIME_SERIES_MONTHLY',
|
@@ -42,26 +42,30 @@ module Alphavantage
|
|
42
42
|
Client.get(params: { function: function, symbol: @symbol, outputsize: validate_outputsize(outputsize) })
|
43
43
|
end
|
44
44
|
|
45
|
-
def intraday(adjusted: true, outputsize: 'compact', interval: '5min',
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
45
|
+
def intraday(adjusted: true, outputsize: 'compact', interval: '5min', datatype: 'json')
|
46
|
+
params = {
|
47
|
+
function: FUNCTIONS[__method__],
|
48
|
+
symbol: @symbol,
|
49
|
+
outputsize: validate_outputsize(outputsize),
|
50
|
+
interval: validate_interval(interval),
|
51
|
+
datatype: datatype,
|
52
|
+
adjusted: adjusted
|
53
|
+
}
|
54
|
+
|
55
|
+
Client.get(datatype: validate_datatype(datatype), params: params)
|
56
|
+
end
|
57
|
+
|
58
|
+
def intraday_extended_history(adjusted: true, outputsize: 'compact', interval: '5min', slice: 'year1month1')
|
59
|
+
params = {
|
60
|
+
function: FUNCTIONS[:intraday_extended_history],
|
61
|
+
symbol: @symbol,
|
62
|
+
slice: validate_slice(slice),
|
63
|
+
interval: validate_interval(interval),
|
64
|
+
adjusted: adjusted
|
62
65
|
}
|
63
|
-
|
64
|
-
Client.get(params: params)
|
66
|
+
|
67
|
+
Client.get(datatype: :csv, params: params)
|
65
68
|
end
|
69
|
+
|
66
70
|
end
|
67
71
|
end
|
@@ -4,38 +4,38 @@ module Alphavantage
|
|
4
4
|
(1..12).map do |month|
|
5
5
|
"year#{year}month#{month}"
|
6
6
|
end
|
7
|
-
end.flatten
|
7
|
+
end.flatten.map(&:to_sym)
|
8
8
|
|
9
|
-
VALID_INTERVALS = %
|
10
|
-
VALID_INDICATOR_INTERVALS = VALID_INTERVALS + %
|
11
|
-
VALID_OUTPUTSIZES = %
|
12
|
-
|
9
|
+
VALID_INTERVALS = %i{ 1min 5min 15min 30min 60min }
|
10
|
+
VALID_INDICATOR_INTERVALS = VALID_INTERVALS + %i{ daily weekly monthly }
|
11
|
+
VALID_OUTPUTSIZES = %i{ compact full }
|
12
|
+
VALID_SERIES_TYPES = %i{ close open high low }
|
13
|
+
VALID_DATATYPES = %i{ json csv }
|
13
14
|
|
14
15
|
private
|
15
16
|
|
16
|
-
def validate_slice(
|
17
|
-
|
18
|
-
slice
|
17
|
+
def validate_slice(value)
|
18
|
+
validate_from_collection(value: value, collection: VALID_SLICES, type: 'slice')
|
19
19
|
end
|
20
20
|
|
21
|
-
def validate_interval(
|
22
|
-
|
23
|
-
interval
|
21
|
+
def validate_interval(value)
|
22
|
+
validate_from_collection(value: value, collection: VALID_INTERVALS, type: 'interval')
|
24
23
|
end
|
25
24
|
|
26
|
-
def validate_outputsize(
|
27
|
-
|
28
|
-
outputsize
|
25
|
+
def validate_outputsize(value)
|
26
|
+
validate_from_collection(value: value, collection: VALID_OUTPUTSIZES, type: 'outputsize')
|
29
27
|
end
|
30
28
|
|
31
|
-
def validate_indicator_interval(
|
32
|
-
|
33
|
-
interval
|
29
|
+
def validate_indicator_interval(value)
|
30
|
+
validate_from_collection(value: value, collection: VALID_INDICATOR_INTERVALS, type: 'interval')
|
34
31
|
end
|
35
32
|
|
36
|
-
def validate_series_type(
|
37
|
-
|
38
|
-
|
33
|
+
def validate_series_type(value)
|
34
|
+
validate_from_collection(value: value, collection: VALID_SERIES_TYPES, type: 'series type')
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_datatype(value)
|
38
|
+
validate_from_collection(value: value, collection: VALID_DATATYPES, type: 'data type')
|
39
39
|
end
|
40
40
|
|
41
41
|
def validate_integer(label:,value:)
|
@@ -51,5 +51,14 @@ module Alphavantage
|
|
51
51
|
def is_integer?(str)
|
52
52
|
Integer(str) rescue false
|
53
53
|
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def validate_from_collection(value:, collection:, type:)
|
58
|
+
return value if collection.include?(value.to_sym)
|
59
|
+
|
60
|
+
message = "Invalid #{type} given. Given #{value}, allowed: #{collection.map{|c| "'#{c}'"}.join(', ')}"
|
61
|
+
raise Alphavantage::Error, message
|
62
|
+
end
|
54
63
|
end
|
55
64
|
end
|
data/lib/alphavantage/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alphavantage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Teh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -121,7 +121,6 @@ files:
|
|
121
121
|
- ".travis.yml"
|
122
122
|
- CODE_OF_CONDUCT.md
|
123
123
|
- Gemfile
|
124
|
-
- Gemfile.lock
|
125
124
|
- LICENSE.txt
|
126
125
|
- README.md
|
127
126
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
alphavantage (1.1.0)
|
5
|
-
faraday (~> 1.4)
|
6
|
-
hashie (~> 4.1)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
addressable (2.7.0)
|
12
|
-
public_suffix (>= 2.0.2, < 5.0)
|
13
|
-
byebug (11.1.3)
|
14
|
-
crack (0.4.5)
|
15
|
-
rexml
|
16
|
-
diff-lcs (1.4.4)
|
17
|
-
faraday (1.4.1)
|
18
|
-
faraday-excon (~> 1.1)
|
19
|
-
faraday-net_http (~> 1.0)
|
20
|
-
faraday-net_http_persistent (~> 1.1)
|
21
|
-
multipart-post (>= 1.2, < 3)
|
22
|
-
ruby2_keywords (>= 0.0.4)
|
23
|
-
faraday-excon (1.1.0)
|
24
|
-
faraday-net_http (1.0.1)
|
25
|
-
faraday-net_http_persistent (1.1.0)
|
26
|
-
hashdiff (1.0.1)
|
27
|
-
hashie (4.1.0)
|
28
|
-
multipart-post (2.1.1)
|
29
|
-
public_suffix (4.0.6)
|
30
|
-
rake (13.0.3)
|
31
|
-
rexml (3.2.5)
|
32
|
-
rspec (3.10.0)
|
33
|
-
rspec-core (~> 3.10.0)
|
34
|
-
rspec-expectations (~> 3.10.0)
|
35
|
-
rspec-mocks (~> 3.10.0)
|
36
|
-
rspec-core (3.10.1)
|
37
|
-
rspec-support (~> 3.10.0)
|
38
|
-
rspec-expectations (3.10.1)
|
39
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.10.0)
|
41
|
-
rspec-mocks (3.10.2)
|
42
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.10.0)
|
44
|
-
rspec-support (3.10.2)
|
45
|
-
ruby2_keywords (0.0.4)
|
46
|
-
webmock (3.12.2)
|
47
|
-
addressable (>= 2.3.6)
|
48
|
-
crack (>= 0.3.2)
|
49
|
-
hashdiff (>= 0.4.0, < 2.0.0)
|
50
|
-
|
51
|
-
PLATFORMS
|
52
|
-
x86_64-darwin-19
|
53
|
-
|
54
|
-
DEPENDENCIES
|
55
|
-
alphavantage!
|
56
|
-
bundler (~> 2.2)
|
57
|
-
byebug
|
58
|
-
rake (>= 12.3.3)
|
59
|
-
rspec (~> 3.0)
|
60
|
-
webmock
|
61
|
-
|
62
|
-
BUNDLED WITH
|
63
|
-
2.2.16
|