Class: Alphavantage::Stock

Inherits:
Object
  • Object
show all
Includes:
HelperFunctions
Defined in:
lib/Stock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HelperFunctions

#check_argument, #check_datatype, #method_missing, #open_struct, #recreate_metadata_key, #return_client, #return_int_val, #return_matype, #return_series, #return_value, #which_series

Constructor Details

#initialize(symbol:, datatype: "json", key:, verbose: false) ⇒ Stock

Returns a new instance of Stock.



4
5
6
7
8
9
# File 'lib/Stock.rb', line 4

def initialize symbol:,  datatype: "json", key:, verbose: false
  check_argument([true, false], verbose, "verbose")
  @client = return_client(key, verbose)
  @symbol = symbol
  @datatype = datatype
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HelperFunctions

Instance Attribute Details

#datatypeObject

Returns the value of attribute datatype.



12
13
14
# File 'lib/Stock.rb', line 12

def datatype
  @datatype
end

#symbolObject

Returns the value of attribute symbol.



11
12
13
# File 'lib/Stock.rb', line 11

def symbol
  @symbol
end

Instance Method Details

#indicator(function:, interval: "daily", time_period: "60", series_type: "close", fastlimit: "0.01", slowlimit: "0.01", fastperiod: "12", slowperiod: "26", signalperiod: "9", fastmatype: "0", slowmatype: "0", signalmatype: "0", fastkperiod: "5", slowkperiod: "3", slowdperiod: "3", slowkmatype: "0", slowdmatype: "0", fastdperiod: "3", fastdmatype: "0", matype: "0", timeperiod1: "7", timeperiod2: "14", timeperiod3: "28", nbdevup: "2", nbdevdn: "2", acceleration: "0.01", maximum: "0.20") ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/Stock.rb', line 33

def indicator function:, interval: "daily", time_period: "60",
  series_type: "close", fastlimit: "0.01", slowlimit: "0.01",
  fastperiod: "12", slowperiod: "26", signalperiod: "9",
  fastmatype: "0", slowmatype: "0", signalmatype: "0",
  fastkperiod: "5", slowkperiod: "3", slowdperiod: "3",
  slowkmatype: "0", slowdmatype: "0", fastdperiod: "3",
  fastdmatype: "0", matype: "0", timeperiod1: "7", timeperiod2: "14",
  timeperiod3: "28", nbdevup: "2", nbdevdn: "2", acceleration: "0.01",
  maximum: "0.20"
  Alphavantage::Indicator.new function: function, symbol: @symbol,
    interval: interval, time_period: time_period, series_type: series_type,
    fastlimit: fastlimit, slowlimit: slowlimit, fastperiod: fastperiod,
    slowperiod: slowperiod, signalperiod: signalperiod,
    fastmatype: fastmatype, slowmatype: slowmatype,
    signalmatype: signalmatype, fastkperiod: fastkperiod, slowkperiod: slowkperiod,
    slowdperiod: slowdperiod, slowkmatype: slowkmatype, slowdmatype: slowdmatype,
    fastdperiod: fastdperiod, fastdmatype: fastdmatype, matype: matype,
    timeperiod1: timeperiod1, timeperiod2: timeperiod2, timeperiod3: timeperiod3,
    nbdevup: nbdevup, nbdevdn: nbdevdn, acceleration: acceleration,
    maximum: maximum, key: @client
end

#quote(file: nil, datatype: @datatype) ⇒ Object



19
20
21
22
23
24
# File 'lib/Stock.rb', line 19

def quote file: nil, datatype: @datatype
  check_datatype(datatype, file)
  url = "function=GLOBAL_QUOTE&symbol=#{symbol}"
  return @client.download(url, file) if datatype == "csv"
  return open_struct(url, "Global Quote")
end

#timeseries(type: "daily", interval: nil, outputsize: "compact", file: nil, datatype: @datatype, adjusted: false) ⇒ Object



26
27
28
29
30
31
# File 'lib/Stock.rb', line 26

def timeseries type: "daily", interval: nil, outputsize: "compact",
  file: nil, datatype: @datatype, adjusted: false
  Alphavantage::Timeseries.new type: type, interval: interval,
    outputsize: outputsize, symbol: @symbol, datatype: datatype, file: file,
    key: @client, adjusted: adjusted
end