alphavantagerb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9bcc95c4192080579382239738a8f6416dc49d85
4
+ data.tar.gz: dd3332db7c8b9bca2a2d72f3cb29a2270f13b389
5
+ SHA512:
6
+ metadata.gz: 2fd96ffada1d455f88ea6b5cddc4e8386288278662375decb0ebacc90657bdb04c4aea39e2bc03a9d3bd47e7a77765325645b96eabb9bba7da991e9a12785dca
7
+ data.tar.gz: 9e8ac1b906f150071f256d1015f94e5496c725768195c60e5c379037575b4ec0537bf6abd4a84784c9e389bb46c909d5da6f71aa6a909495055e565740231eb3
@@ -0,0 +1,19 @@
1
+ # lib = File.expand_path("../lib", __FILE__)
2
+ # $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "rake"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "alphavantagerb"
7
+ s.version = "1.0.0"
8
+ s.authors = ["Stefano Martin"]
9
+ s.email = ["stefano.martin87@gmail.com"]
10
+ s.homepage = "https://github.com/StefanoMartin/AlphaVantageRB"
11
+ s.license = "MIT"
12
+ s.summary = "A gem for Alpha Vantage"
13
+ s.description = "A ruby wrapper for Alpha Vantage's HTTP API"
14
+ s.platform = Gem::Platform::RUBY
15
+ s.require_paths = ["lib"]
16
+ s.files = FileList["lib/*", "spec/**/*", "AlphavantageRB.gemspec", "Gemfile", "LICENSE.md", "README.md"].to_a
17
+ s.add_dependency "httparty", "0.15.6"
18
+ s.add_dependency "humanize", "1.7.0"
19
+ end
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "httparty", "0.15.6"
4
+ gem "humanize", "1.7.0"
5
+
6
+ group :development, :test do
7
+ gem "pry-byebug"
8
+ gem "rspec", "~>3.5"
9
+ gem "awesome_print", "~>1.7"
10
+ end
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Stefano Martin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,778 @@
1
+ AlphavantageRB
2
+ =========================================================
3
+
4
+ [Alpha Vantage](https://www.alphavantage.co/) is a great API for retrieving Stock
5
+ market data in JSON or CSV format.
6
+ AlphavantageRB is a Gem to use Alpha Vantage with Ruby. AlphavangateRB is based
7
+ on the [HTTP API of Alpha Vantage](https://www.alphavantage.co/documentation/).
8
+
9
+ ## Classes
10
+
11
+ AlphavantateRB has the following classes:
12
+
13
+ * [Alphavantage::Client](#Client): to manage the credentials to contact Alpha
14
+ Vantage
15
+ * [Alphavantage::Stock](#Stock): to create a stock class
16
+ * [Alphavantage::Timeseries](#Timeseries): to retrieve historical data of a stock
17
+ * [Alphavantage::Indicator](#Indicator): to use some technical indicator of a stock
18
+ * [Alphavantage::Crypto](#Crypto): to create a crypto currency class
19
+ * [Alphavantage::Crypto_Timeseries](#Crypto_Timeseries): to retrieve historical
20
+ data of a crypto currency
21
+ * [Alphavantage::Exchange](#Exchange): to retrieve how a currency is exchanged currently on the market
22
+ * [Alphavantage::Sector](#Sector): to retrieve the status of the historical sector performances calculated from S&P500 incumbents
23
+ * [Alphavantage::Error](#Error): to manage AlphavantageRB errors
24
+
25
+ <a name="Client"></a>
26
+ ## Alphavantage::Client
27
+
28
+ Alphavantage::Client is used to create a client that will be used from the AlphavantageRB to contact the website.
29
+ To contact Alpha Vantage you need to use a valid key that you can require from [here](https://www.alphavantage.co/support/#api-key).
30
+
31
+ To setup your credentials use:
32
+ ``` ruby
33
+ client = Alphavantage::Client.new key: "YOURKEY"
34
+ ```
35
+
36
+ If you want to see the request that the client will do to Alpha Vantage you can
37
+ setup verbose equal to true.
38
+
39
+ ``` ruby
40
+ client.verbose = true # You can setup this during the initialization too
41
+ ```
42
+
43
+ <a name="Stock"></a>
44
+ ## Alphavantage::Stock
45
+
46
+ Alphavantage::Stock is used to create a stock class to manage future retrieving of timeseries or technical indicators.
47
+
48
+ To create a new Stock class you can use a client or you can create it directly.
49
+ These two creation commands are equivalent:
50
+
51
+ ``` ruby
52
+ stock = client.stock symbol: "MSFT"
53
+ stock = Alphavantage::Stock.new symbol: "MSFT", key: "YOURKEY"
54
+ ```
55
+
56
+ Note that the initialization owns different entry:
57
+ * symbol: it is a string that denote the stock you want to retrieve.
58
+ * key: authentication key. This value cannot be setup if you are initializing a Stock class from a client
59
+ * verbose: used to see the request to Alpha Vantage (default false). This value cannot be setup if you are initializing a timeseries from a stock
60
+ * datatype: it can be "json" or "csv" (default "json")
61
+
62
+ You can setup the datatype of future retrieving by doing:
63
+
64
+ ``` ruby
65
+ stock.datatype = "csv"
66
+ ```
67
+
68
+ <a name="Timeseries"></a>
69
+ ## Alphavantage::Timeseries
70
+
71
+ Alphavantage::Timeseries is used to retrieve historical data.
72
+ To create a new Timeseries class you can use a Stock class or you can create it directly.
73
+ These two creation commands are equivalent:
74
+
75
+ ``` ruby
76
+ timeseries = stock.timeseries
77
+ timeseries = Alphavantage::Timeseries.new symbol: "MSFT", key: "YOURKEY"
78
+ ```
79
+
80
+ Note that the initialization owns different entries:
81
+ * symbol: it is a string that denote the stock you want to retrieve. This value cannot be setup if you are initializing a timeseries from a stock
82
+ * key: authentication key. This value cannot be setup if you are initializing a timeseries from a stock
83
+ * verbose: used to see the request to Alpha Vantage (default false). This value cannot be setup if you are initializing a timeseries from a stock
84
+ * type: it can be "intraday", "daily", "weekly", "monthly" (default "daily")
85
+ * adjusted: a boolean value, it returns adjusted values (default false)
86
+ * interval: it can be "1min", "5min", "15min", "30min", or "60min". It is used
87
+ only if type is "intraday" (default nil)
88
+ * outputsize: it can be "compact", or "full" (default "compact")
89
+ * datatype: it can be "json" or "csv" (default "json")
90
+ * file: path where a csv file should be saved (default "nil")
91
+
92
+ You can retrieve all the output from Alpha Vantage by doing.
93
+ ``` ruby
94
+ timeseries.hash
95
+ ```
96
+
97
+ Specific information about the timeseries can be retrieved using the following methods:
98
+
99
+ ``` ruby
100
+ timeseries.information # Retrieve information about the timeseries
101
+ timeseries.symbol # Symbol used by the timeseries
102
+ timeseries.last_refreshed # A timestamp that show when last time the data were refreshed
103
+ timeseries.output_size # Size of the output
104
+ timeseries.time_zone # Time zone of the timeseries
105
+ ```
106
+
107
+ Specific data can be retrieved using the following methods.
108
+ These methods will return an array of couples where the first entry is a timestamp
109
+ and the second one is the value of the stock at the timestamp.
110
+
111
+ ``` ruby
112
+ timeseries.open
113
+ timeseries.close
114
+ timeseries.high
115
+ timeseries.low
116
+ timeseries.volume
117
+ timeseries.adjusted_close # Available only if adjusted is true
118
+ timeseries.dividend_amount # Available only if adjusted is true
119
+ timeseries.split_coefficient # Available only if adjusted is true
120
+ ```
121
+
122
+ You can order the data in ascending or descending order.
123
+
124
+ ``` ruby
125
+ timeseries.open("desc") # Default
126
+ timeseries.open("asc")
127
+ ```
128
+
129
+ <a name="Indicator"></a>
130
+ ## Alphavantage::Indicator
131
+
132
+ Alphavantage::Indicator is for using technical indicator.
133
+ To create a new Indicator class you can use a Stock class or you can create it directly.
134
+ These two creation commands are equivalent:
135
+
136
+ ``` ruby
137
+ indicator = stock.indicator function: "SMA"
138
+ indicator = Alphavantage::Indicator.new function: "SMA", symbol: "MSFT", key: "YOURKEY"
139
+ ```
140
+
141
+ Note that the initialization owns different entries (for deeper explanation on the parameters, please consult the Alpha Vantage documentation).
142
+ Some of these parameters are necessary for each functions.
143
+ * symbol: it is a string that denote the stock you want to retrieve. This value cannot be setup if you are initializing a timeseries from a stock
144
+ * key: authentication key. This value cannot be setup if you are initializing a timeseries from a stock
145
+ * verbose: used to see the request to Alpha Vantage (default false). This value cannot be setup if you are initializing a timeseries from a stock
146
+ * function: denote the type of function that you want to use. It can be "SMA", "EMA", "WMA", "DEMA", "TEMA", "TRIMA", "KAMA", "T3", "RSI","MAMA", "MACD", "MACDEXT", "STOCH", "STOCHF", "STOCHRSI", "WILLR", "ADX", "ADXR", "APO", "PPO", "MOM", "BOP", "CCI", "CMO", "ROC", "ROCR", "AROON", "AROONOSC", "MFI", "TRIX", "ULTOSC", "DX", "MINUS_DI", "PLUS_DI", "MINUS_DM", "PLUS_DM", "BBANDS", "MIDPOINT", "MIDPRICE", "SAR", "TRANGE", "ATR", "NATR", "AD", "ADOSC", "OBV", "HT_SINE", "HT_TRENDLINE", "HT_TRENDMODE", "HT_DCPERIOD", "HT_DCPHASE", or "HT_PHASOR".
147
+ * interval: it can be "1min", "5min", "15min", "30min", "60min", "daily", "weekly", or "monthly" (default "daily").
148
+
149
+ Others are used only for some functions.
150
+
151
+ * time_period: it can be a positive integer (default "60"). These functions support this attribute: "SMA", "EMA", "WMA", "DEMA", "TEMA", "TRIMA", "KAMA", "T3", "RSI", "STOCHRSI", "WILLR", "ADX", "ADXR", "MOM", "CCI", "CMO", "ROC", "ROCR", "AROON", "AROONOSC", "MFI", "TRIX", "DX", "MINUS_DI", "PLUS_DI", "MINUS_DM", "PLUS_DM", "BBANDS", "MIDPOINT", "MIDPRICE", "ATR", "NATR"
152
+ * series_type: it can be "close", "open", "high", "low" (default "close"). These functions support this attribute: "SMA", "EMA", "WMA", "DEMA", "TEMA", "TRIMA", "KAMA", "T3", "RSI", "MAMA", "MACD", "MACDEXT", "STOCHRSI", "APO", "PPO", "MOM", "ROC", "ROCR", "TRIX", "BBANDS", "MIDPOINT", "HT_SINE", "HT_TRENDLINE", "HT_TRENDMODE", "HT_DCPERIOD", "HT_DCPHASE", "HT_PHASOR", "CMO"
153
+
154
+ Others are even more specific for the function used. These are in general of three type:
155
+ positive integer parameters, positive float parameters and MA parameters.
156
+ The MA parameters accept as an entry one of these attributes: "0", "1", "2", "3", "4", "5", "6", "7", "8", "SMA", "EMA", "WMA", "DEMA", "TEMA", "TRIMA", "T3", "KAMA", or "MAMA".
157
+
158
+ Each indicator has several methods that can use in relation of the type. Some are used for each indicator.
159
+ ``` ruby
160
+ indicator = stock.indicator(function: "SMA", interval: "weekly", time_period: "60", series_type: "close")
161
+ indicator.hash # Retrieve the output from Alpha vantage
162
+ indicator.symbol
163
+ indicator.interval
164
+ indicator.indicator
165
+ indicator.last_refreshed
166
+ indicator.time_zone
167
+ ```
168
+
169
+ Some other are more specific in relation of the type of indicator used.
170
+ ``` ruby
171
+ indicator.time_period # time_period is only supported by "SMA", "EMA", "WMA", "DEMA", "TEMA", "TRIMA", "KAMA", "T3", "RSI", "STOCHRSI", "WILLR", "ADX", "ADXR", "MOM", "CCI", "CMO", "ROC", "ROCR", "AROON", "AROONOSC", "MFI", "TRIX", "DX", "MINUS_DI", "PLUS_DI", "MINUS_DM", "PLUS_DM", "BBANDS", "MIDPOINT", "MIDPRICE", "ATR","NATR"
172
+ indicator.series_type # series_type is only supported by "SMA", "EMA", "WMA", "DEMA", "TEMA", "TRIMA", "KAMA", "T3", "RSI", "MAMA", "MACD", "MACDEXT", "STOCHRSI", "APO", "PPO", "MOM", "ROC","ROCR", "TRIX", "BBANDS", "MIDPOINT", "HT_SINE", "HT_TRENDLINE", "HT_TRENDMODE", "HT_DCPERIOD", "HT_DCPHASE", "HT_PHASOR", "CMO"
173
+ ```
174
+ Then there are really specific indicator, for only some functions.
175
+
176
+ ### SMA
177
+ ``` ruby
178
+ indicator = stock.indicator(function: "SMA", interval: "weekly", time_period: "60", series_type: "close")
179
+ indicator.sma
180
+ ```
181
+
182
+ ### EMA
183
+ ``` ruby
184
+ indicator = stock.indicator(function: "EMA", interval: "weekly", time_period: "60", series_type: "close")
185
+ indicator.ema
186
+ ```
187
+
188
+ ### WMA
189
+ ``` ruby
190
+ indicator = stock.indicator(function: "WMA", interval: "weekly", time_period: "60", series_type: "close")
191
+ indicator.wma
192
+ ```
193
+
194
+ ### DEMA
195
+ ``` ruby
196
+ indicator = stock.indicator(function: "DEMA", interval: "weekly", time_period: "60", series_type: "close")
197
+ indicator.dema
198
+ ```
199
+
200
+ ### TEMA
201
+ ``` ruby
202
+ indicator = stock.indicator(function: "TEMA", interval: "weekly", time_period: "60", series_type: "close")
203
+ indicator.tema
204
+ ```
205
+
206
+ ### TRIMA
207
+ ``` ruby
208
+ indicator = stock.indicator(function: "TRIMA", interval: "weekly", time_period: "60", series_type: "close")
209
+ indicator.trima
210
+ ```
211
+
212
+ ### KAMA
213
+ ``` ruby
214
+ indicator = stock.indicator(function: "KAMA", interval: "weekly", time_period: "60", series_type: "close")
215
+ indicator.kama
216
+ ```
217
+
218
+ ### MAMA
219
+ * fastlimit: it can be a positive float (default "0.01")
220
+ * slowlimit: it can be a positive float (default "0.01")
221
+
222
+ ``` ruby
223
+ indicator = stock.indicator(function: "MAMA", interval: "weekly", series_type: "close", fastlimit: "0.02", slowlimit: "0.01")
224
+ indicator.fast_limit
225
+ indicator.slow_limit
226
+ indicator.fama
227
+ indicator.mama
228
+ ```
229
+
230
+ ### T3
231
+ ``` ruby
232
+ indicator = stock.indicator(function: "T3", interval: "weekly", time_period: "60", series_type: "close")
233
+ indicator.t3
234
+ ```
235
+
236
+ ### MACD
237
+ * fastperiod: it can be a positive integer (default "12")
238
+ * slowperiod: it can be a positive integer (default "26")
239
+ * signalperiod: it can be a positive integer (default "9")
240
+
241
+ ``` ruby
242
+ indicator = stock.indicator(function: "MACD", interval: "weekly", time_period: "60", series_type: "close", fastperiod: "12", slowperiod: "26", signalperiod: "9")
243
+ indicator.fast_period
244
+ indicator.slow_period
245
+ indicator.signal_period
246
+ indicator.macd_signal
247
+ indicator.macd_hist
248
+ indicator.macd
249
+ ```
250
+
251
+ ### MACDEXT
252
+ * fastperiod: it can be a positive integer (default "12")
253
+ * slowperiod: it can be a positive integer (default "26")
254
+ * signalperiod: it can be a positive integer (default "9")
255
+ * fastmatype: it is a MA parameter (default "0")
256
+ * slowmatype: it is a MA parameter (default "0")
257
+ * signalmatype: it is a MA parameter (default "0")
258
+
259
+ ``` ruby
260
+ indicator = stock.indicator(function: "MACDEXT", interval: "weekly", time_period: "60", series_type: "close", fastperiod: "12", slowperiod: "26", signalperiod: "9", fastmatype: "0", slowmatype: "0", signalmatype: "0")
261
+ indicator.fast_period
262
+ indicator.slow_period
263
+ indicator.signal_period
264
+ indicator.signal_ma_type
265
+ indicator.fast_ma_type
266
+ indicator.slow_ma_type
267
+ indicator.macd_signal
268
+ indicator.macd_hist
269
+ indicator.macd
270
+ ```
271
+
272
+ ### STOCH
273
+ * fastkperiod: it can be a positive integer (default "5")
274
+ * slowkperiod: it can be a positive integer (default "3")
275
+ * slowdperiod: it can be a positive integer (default "3")
276
+ * slowkmatype: it is a MA parameter (default "0")
277
+ * slowdmatype: it is a MA parameter (default "0")
278
+
279
+ ``` ruby
280
+ indicator = stock.indicator(function: "STOCH", interval: "weekly", fastkperiod: "5", slowkperiod: "3", slowdperiod: "3", slowkmatype: "0", slowdmatype: "0")
281
+ indicator.fastk_period
282
+ indicator.slowk_period
283
+ indicator.slowk_ma_type
284
+ indicator.slowd_period
285
+ indicator.slowd_ma_type
286
+ indicator.slowk
287
+ indicator.slowd
288
+ ```
289
+
290
+ ### STOCHF
291
+ * fastkperiod: it can be a positive integer (default "5")
292
+ * fastdperiod: it can be a positive integer (default "3")
293
+ * fastdmatype: it is a MA parameter (default "0")
294
+
295
+ ``` ruby
296
+ indicator = stock.indicator(function: "STOCHF", interval: "weekly", fastkperiod: "5", fastdperiod: "3", fastdmatype: "0")
297
+ indicator.fastk_period
298
+ indicator.fastd_period
299
+ indicator.fastd_ma_type
300
+ indicator.fastk
301
+ indicator.fastd
302
+ ```
303
+
304
+ ### RSI
305
+ ``` ruby
306
+ indicator = stock.indicator(function: "RSI", interval: "weekly", time_period: "60", series_type: "close")
307
+ indicator.rsi
308
+ ```
309
+
310
+ ### STOCHRSI
311
+ * fastkperiod: it can be a positive integer (default "5")
312
+ * fastdperiod: it can be a positive integer (default "3")
313
+ * fastdmatype: it is a MA parameter (default "0")
314
+
315
+ ``` ruby
316
+ indicator = stock.indicator(function: "STOCHRSI", interval: "weekly", time_period: "60", fastkperiod: "5", fastdperiod: "3", fastdmatype: "0")
317
+ indicator.fastk_period
318
+ indicator.fastd_period
319
+ indicator.fastd_ma_type
320
+ indicator.fastk
321
+ indicator.fastd
322
+ ```
323
+
324
+ ### WILLR
325
+ ``` ruby
326
+ indicator = stock.indicator(function: "WILLR", interval: "weekly", time_period: "60")
327
+ indicator.willr
328
+ ```
329
+
330
+ ### ADX
331
+ ``` ruby
332
+ indicator = stock.indicator(function: "ADX", interval: "weekly", time_period: "60")
333
+ indicator.adx
334
+ ```
335
+
336
+ ### ADXR
337
+ ``` ruby
338
+ indicator = stock.indicator(function: "ADXR", interval: "weekly", time_period: "60")
339
+ indicator.adxr
340
+ ```
341
+
342
+ ### APO
343
+ * fastperiod: it can be a positive integer (default "12")
344
+ * slowperiod: it can be a positive integer (default "26")
345
+ * signalperiod: it can be a positive integer (default "9")
346
+ * matype: it is a MA parameter (default "0")
347
+
348
+ ``` ruby
349
+ indicator = stock.indicator(function: "APO", interval: "weekly", series_type: "close", fastperiod: "12", slowperiod: "26", signalperiod: "9", matype: "0")
350
+ indicator.fast_period
351
+ indicator.slow_period
352
+ indicator.ma_type
353
+ indicator.apo
354
+ ```
355
+
356
+ ### PPO
357
+ * fastperiod: it can be a positive integer (default "12")
358
+ * slowperiod: it can be a positive integer (default "26")
359
+ * signalperiod: it can be a positive integer (default "9")
360
+ * matype: it is a MA parameter (default "0")
361
+
362
+ ``` ruby
363
+ indicator = stock.indicator(function: "PPO", interval: "weekly", series_type: "close", fastperiod: "12", slowperiod: "26", signalperiod: "9", matype: "0")
364
+ indicator.fast_period
365
+ indicator.slow_period
366
+ indicator.ma_type
367
+ indicator.ppo
368
+ ```
369
+
370
+ ### MOM
371
+ ``` ruby
372
+ indicator = stock.indicator(function: "MOM", interval: "weekly", time_period: "60", series_type: "close")
373
+ indicator.mom
374
+ ```
375
+
376
+ ### BOP
377
+ ``` ruby
378
+ indicator = stock.indicator(function: "MOM", interval: "weekly", time_period: "60", series_type: "close")
379
+ indicator.bop
380
+ ```
381
+
382
+ ### CCI
383
+ ``` ruby
384
+ indicator = stock.indicator(function: "CCI", interval: "weekly", time_period: "60")
385
+ indicator.cci
386
+ ```
387
+
388
+ ### CMO
389
+ ``` ruby
390
+ indicator = stock.indicator(function: "CMO", interval: "weekly", time_period: "60")
391
+ indicator.cmo
392
+ ```
393
+
394
+ ### ROC
395
+ ``` ruby
396
+ indicator = stock.indicator(function: "ROC", interval: "weekly", time_period: "60", series_type: "close")
397
+ indicator.roc
398
+ ```
399
+
400
+ ### ROCR
401
+ ``` ruby
402
+ indicator = stock.indicator(function: "ROCR", interval: "weekly", time_period: "60", series_type: "close")
403
+ indicator.rocr
404
+ ```
405
+
406
+ ### AROON
407
+ ``` ruby
408
+ indicator = stock.indicator(function: "AROON", interval: "weekly", time_period: "60")
409
+ indicator.aroon_down
410
+ indicator.aroon_up
411
+ ```
412
+
413
+ ### AROONOSC
414
+ ``` ruby
415
+ indicator = stock.indicator(function: "AROONOSC", interval: "weekly", time_period: "60")
416
+ indicator.aroonosc
417
+ ```
418
+
419
+ ### MFI
420
+ ``` ruby
421
+ indicator = stock.indicator(function: "MFI", interval: "weekly", time_period: "60")
422
+ indicator.mfi
423
+ ```
424
+
425
+ ### TRIX
426
+ ``` ruby
427
+ indicator = stock.indicator(function: "TRIX", interval: "weekly", time_period: "60", series_type: "close")
428
+ indicator.trix
429
+ ```
430
+
431
+ ### ULTOSC
432
+ * timeperiod1: it can be a positive integer (default "7")
433
+ * timeperiod2: it can be a positive integer (default "14")
434
+ * timeperiod3: it can be a positive integer (default "28")
435
+
436
+ ``` ruby
437
+ indicator = stock.indicator(function: "ULTOSC", interval: "weekly", timeperiod1: "7", timeperiod2: "14", timeperiod3: "28")
438
+ indicator.time_period_1
439
+ indicator.time_period_2
440
+ indicator.time_period_3
441
+ indicator.ultosc
442
+ ```
443
+
444
+ ### DX
445
+ ``` ruby
446
+ indicator = stock.indicator(function: "DX", interval: "weekly", time_period: "60")
447
+ indicator.dx
448
+ ```
449
+
450
+ ### MINUS_DI
451
+ ``` ruby
452
+ indicator = stock.indicator(function: "MINUS_DI", interval: "weekly", time_period: "60")
453
+ indicator.minus_di
454
+ ```
455
+
456
+ ### PLUS_DI
457
+ ``` ruby
458
+ indicator = stock.indicator(function: "PLUS_DI", interval: "weekly", time_period: "60")
459
+ indicator.plus_di
460
+ ```
461
+
462
+ ### MINUS_DM
463
+ ``` ruby
464
+ indicator = stock.indicator(function: "PLUS_DI", interval: "weekly", time_period: "60")
465
+ indicator.minus_dm
466
+ ```
467
+
468
+ ### PLUS_DM
469
+ ``` ruby
470
+ indicator = stock.indicator(function: "PLUS_DM", interval: "weekly", time_period: "60", series_type: "close")
471
+ indicator.plus_dm
472
+ ```
473
+
474
+ ### BBANDS
475
+ * matype: it is a MA parameter (default "0")
476
+ * nbdevup: it can be a positive integer (default "2")
477
+ * nbdevdn: it can be a positive integer (default "2")
478
+
479
+ ``` ruby
480
+ indicator = stock.indicator(function: "BBANDS", interval: "weekly", time_period: "60", series_type: "close", matype: "0", nbdevup: "2", nbdevdn: "2")
481
+ indicator.deviation_multiplier_for_upper_band
482
+ indicator.deviation_multiplier_for_lower_band
483
+ indicator.ma_type
484
+ indicator.real_lower_band
485
+ indicator.real_middle_band
486
+ indicator.real_upper_band
487
+ ```
488
+
489
+ ### MIDPOINT
490
+ ``` ruby
491
+ indicator = stock.indicator(function: "MIDPOINT", interval: "weekly", time_period: "60", series_type: "close")
492
+ indicator.midpoint
493
+ ```
494
+
495
+ ### MIDPRICE
496
+ ``` ruby
497
+ indicator = stock.indicator(function: "MIDPRICE", interval: "weekly", time_period: "60", series_type: "close")
498
+ indicator.midprice
499
+ ```
500
+
501
+ ### SAR
502
+ * acceleration: it can be a positive float (default "0.01")
503
+ * maximum: it can be a positive float (default "0.20")
504
+
505
+ ``` ruby
506
+ indicator = stock.indicator(function: "SAR", interval: "weekly", acceleration: "0.01", maximum: "0.20")
507
+ indicator.acceleration
508
+ indicator.maximum
509
+ indicator.sar
510
+ ```
511
+
512
+ ### TRANGE
513
+ ``` ruby
514
+ indicator = stock.indicator(function: "TRANGE", interval: "weekly")
515
+ indicator.trange
516
+ ```
517
+
518
+ ### ATR
519
+ ``` ruby
520
+ indicator = stock.indicator(function: "ATR", interval: "weekly", time_period: "60")
521
+ indicator.atr
522
+ ```
523
+
524
+ ### NATR
525
+ ``` ruby
526
+ indicator = stock.indicator(function: "NATR", interval: "weekly", time_period: "60")
527
+ indicator.natr
528
+ ```
529
+
530
+ ### AD
531
+ ``` ruby
532
+ indicator = stock.indicator(function: "AD", interval: "weekly")
533
+ indicator.chaikin_ad
534
+ ```
535
+
536
+ ### ADOSC
537
+ * fastperiod: it can be a positive integer (default "12")
538
+ * slowperiod: it can be a positive integer (default "26")
539
+
540
+ ``` ruby
541
+ indicator = stock.indicator(function: "ADOSC", interval: "weekly", fastperiod: "12", slowperiod: "26")
542
+ indicator.fastk_period
543
+ indicator.slowk_period
544
+ indicator.adosc
545
+ ```
546
+
547
+ ### OBV
548
+ ``` ruby
549
+ indicator = stock.indicator(function: "OBV", interval: "weekly")
550
+ indicator.obv
551
+ ```
552
+
553
+ ### HT_TRENDLINE
554
+ ``` ruby
555
+ indicator = stock.indicator(function: "HT_TRENDLINE", interval: "weekly", time_period: "60", series_type: "close")
556
+ indicator.ht_trendline
557
+ ```
558
+
559
+ ### HT_SINE
560
+ ``` ruby
561
+ indicator = stock.indicator(function: "HT_SINE", interval: "weekly", series_type: "close")
562
+ indicator.sine
563
+ indicator.lead_sine
564
+ ```
565
+
566
+ ### HT_TRENDMODE
567
+ ``` ruby
568
+ indicator = stock.indicator(function: "HT_TRENDMODE", interval: "weekly", series_type: "close")
569
+ indicator.trendmode
570
+ ```
571
+
572
+ ### HT_DCPERIOD
573
+ ``` ruby
574
+ indicator = stock.indicator(function: "HT_DCPERIOD", interval: "weekly", series_type: "close")
575
+ indicator.dcperiod
576
+ ```
577
+
578
+ ### HT_DCPHASE
579
+ ``` ruby
580
+ indicator = stock.indicator(function: "EMA", interval: "weekly", series_type: "close")
581
+ indicator.ht_dcphase
582
+ ```
583
+
584
+ ### HT_PHASOR
585
+ ``` ruby
586
+ indicator = stock.indicator(function: "HT_PHASOR", interval: "weekly", series_type: "close")
587
+ indicator.quadrature
588
+ indicator.phase
589
+ ```
590
+ <a name="Crypto"></a>
591
+ ## Alphavantage::Crypto
592
+
593
+ Alphavantage::Crypto is used to create a Crypto class to manage future retrieving of
594
+ timeseries of Cryptocurrency.
595
+
596
+ To create a new Crypto class you can use a client or you can create it directly.
597
+ These two creation commands are equivalent:
598
+
599
+ ``` ruby
600
+ stock = client.crypto symbol: "BTC", market: "DKK"
601
+ stock = Alphavantage::Crypto.new symbol: "BTC", market: "DKK", key: "YOURKEY"
602
+ ```
603
+
604
+ Note that the initialization owns different entry:
605
+ * symbol: it is a string that denote the cryptocurrency you want to retrieve.
606
+ * market: denote the market where you want to analyze the cryptocurrency
607
+ * key: authentication key. This value cannot be setup if you are initializing a Stock class from a client
608
+ * verbose: used to see the request to Alpha Vantage (default false). This value cannot be setup if you are initializing a timeseries from a stock
609
+ * datatype: it can be "json" or "csv" (default "json")
610
+
611
+ You can setup the datatype of future retrieving by doing:
612
+
613
+ ``` ruby
614
+ stock.datatype = "csv"
615
+ ```
616
+
617
+ <a name="Crypto_Timeseries"></a>
618
+ ## Alphavantage::Crypto_Timeseries
619
+
620
+ Alphavantage::Crypto_Timeseries is used to retrieve historical data of a cryptocurrency.
621
+ To create a new Crypto_Timeseries class you can use a Crypto class or you can create it directly.
622
+ These two creation commands are equivalent:
623
+
624
+ ``` ruby
625
+ crypto_timeseries = crypto.timeseries type: "daily"
626
+ crypto_timeseries = Alphavantage::Crypto_Timeseries.new type: "daily", symbol: "BTC", market: "DKK", key: "YOURKEY"
627
+ ```
628
+
629
+ Note that the initialization owns different entries:
630
+ * symbol: it is a string that denote the stock you want to retrieve. This value cannot be setup if you are initializing a timeseries from a crypto class from a crypto class
631
+ * market: it is a string that denote the market you want to analyze. This value cannot be setup if you are initializing a timeseries from a stock
632
+ * key: authentication key. This value cannot be setup if you are initializing a timeseries from a crypto class
633
+ * verbose: used to see the request to Alpha Vantage (default false). This value cannot be setup if you are initializing a timeseries from a stock
634
+ * type: it can be "intraday", "daily", "weekly", "monthly" (default "daily")
635
+ * datatype: it can be "json" or "csv" (default "json")
636
+ * file: path where a csv file should be saved (default "nil")
637
+
638
+ You can retrieve all the output from Alpha Vantage by doing.
639
+ ``` ruby
640
+ crypto_timeseries.hash
641
+ ```
642
+
643
+ Specific information about the timeseries can be retrieved using the following methods:
644
+
645
+ ``` ruby
646
+ crypto_timeseries.information # Retrieve information about the timeseries
647
+ crypto_timeseries.digital_currency_code # Code of the cryptocurrency
648
+ crypto_timeseries.digital_currency_name # Name of the cryptocurrency
649
+ crypto_timeseries.market_code # Code of the analysed market
650
+ crypto_timeseries.market_name # Name of the analysed market
651
+ crypto_timeseries.last_refreshed # A timestamp that show when last time the data were refreshed
652
+ crypto_timeseries.output_size # Size of the output
653
+ crypto_timeseries.time_zone # Time zone of the timeseries
654
+ ```
655
+
656
+ Specific data can be retrieved using the following methods.
657
+ These methods will return an array of couples where the first entry is a timestampand the second one is the value of the stock at the timestamp.
658
+ These timeseries return always the corrispective timeseries in relation of the USD market.
659
+
660
+ ``` ruby
661
+ crypto_timeseries.open
662
+ crypto_timeseries.close
663
+ crypto_timeseries.high
664
+ crypto_timeseries.low
665
+ crypto_timeseries.volume
666
+ crypto_timeseries.open_usd
667
+ crypto_timeseries.close_usd
668
+ crypto_timeseries.high_usd
669
+ crypto_timeseries.low_usd
670
+ crypto_timeseries.market_cap_usd
671
+ ```
672
+
673
+ You can order the data in ascending or descending order.
674
+
675
+ ``` ruby
676
+ timeseries.open("desc") # Default
677
+ timeseries.open("asc")
678
+ ```
679
+ <a name="Exchange"></a>
680
+ ## Alphavantage::Exchange
681
+
682
+ You can retrieve the exchange rate between two currencies (even cryptocurrency) by using this class.
683
+
684
+ To create a new Exchange class you can use a client or you can create it directly.
685
+ These two creation commands are equivalent:
686
+
687
+ ``` ruby
688
+ exchange = client.exchange from: "USD", to: "DKK" # Check the value of a USD dollar in Danish Kr.
689
+ exchange = Alphavantage::Exchange.new from: "USD", to: "DKK", key: "YOURKEY"
690
+ ```
691
+
692
+ Note that the initialization owns different entry:
693
+ * from: input currency you want to check the value
694
+ * to: output currency you want to see the value
695
+ * symbol: it is a string that denote the stock you want to retrieve.
696
+ * key: authentication key. This value cannot be setup if you are initializing a Stock class from a client
697
+ * verbose: used to see the request to Alpha Vantage (default false). This value cannot be setup if you are initializing a timeseries from a stock
698
+ * datatype: it can be "json" or "csv" (default "json")
699
+
700
+ You can retrieve all the output from Alpha Vantage by doing.
701
+ ``` ruby
702
+ exchange.hash
703
+ ```
704
+
705
+ Other information can be retrieved using the following methods:
706
+
707
+ ``` ruby
708
+ exchange.from_currency_code # Code of the from currency
709
+ exchange.from_currency_name # Name of the from currency
710
+ exchange.to_currency_code # Code of the to currency
711
+ exchange.to_currency_name # Name of the to currency
712
+ exchange.exchange_rate # Exchange rate between the two currencies
713
+ exchange.information # Retrieve information about the timeseries
714
+ exchange.symbol # Symbol used by the timeseries
715
+ exchange.last_refreshed # A timestamp that show when last time the data were refreshed
716
+ exchange.output_size # Size of the output
717
+ exchange.time_zone # Time zone of the timeseries
718
+ ```
719
+
720
+ <a name="Sector"></a>
721
+ ## Alphavantage::Sector
722
+ This class returns the realtime and historical sector performances calculated from S&P500 incumbents.
723
+
724
+ To create a new Sector class you can use a client or you can create it directly.
725
+ These two creation commands are equivalent:
726
+
727
+ ``` ruby
728
+ sector = client.sector
729
+ sector = Alphavantage::Sector.new key: "YOURKEY"
730
+ ```
731
+
732
+ Note that the initialization owns different entries:
733
+ * key: authentication key. This value cannot be setup if you are initializing a timeseries from a crypto class
734
+
735
+ You can retrieve all the output from Alpha Vantage by doing.
736
+ ``` ruby
737
+ crypto_timeseries.hash
738
+ ```
739
+
740
+ Specific information about the timeseries can be retrieved using the following methods:
741
+ ``` ruby
742
+ exchange.information
743
+ exchange.last_refreshed
744
+ exchange.hash
745
+ exchange.real_time_performance
746
+ exchange.one_day_performance
747
+ exchange.five_day_performance
748
+ exchange.one_month_performance
749
+ exchange.three_month_performance
750
+ exchange.year_to_date_performance
751
+ exchange.one_year_performance
752
+ exchange.three_year_performance
753
+ exchange.five_year_performance
754
+ exchange.ten_year_performance
755
+ ```
756
+
757
+ <a name="Error"></a>
758
+ ## Alphavantage::Error
759
+
760
+ Errors are handled by this class.
761
+ You receive errors in the following cases:
762
+ * "Failed request": a request to Alpha Vantage fails
763
+ * "Parsing failed": the parsing of the JSON from Alpha Vantage fails
764
+ * A generic message from Alpha Vantage (for example by using a wrong key, a wrong query or too many requests at once). This message is equal as the one returned from Alpha Vantage API
765
+ * "Failed to save the CSV file": saving the CSV file failed
766
+ * "No file specified where to save the CSV data": you didn't specify a file to save your CSV data
767
+ * "Hash error: No file necessary": you specify a file to do a JSON request
768
+ * "No Time Series found": no timeseries has been retrieved from Alpha Vantage
769
+ * "[method] is undefined for [class]": you try to use a method not existing for the chosen class
770
+ * "Only [list] are supported for [attribute]": the attribute you are using for your request is not valid
771
+ * "Error: [value] is not a correct positive [integer/float]": you are not insering a positive integer or float (a value bigger and different than zero)
772
+ * "Key should be a string": you are trying to use a wrong key
773
+
774
+ You can retrieve more information from your error by using:
775
+ ``` ruby
776
+ e.message
777
+ e.data # Data retrieved from Alpha vantage or further information to correct the error
778
+ ```