Class: Alphavantage::TimeSeries

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
lib/alphavantage/time_series.rb

Constant Summary collapse

FUNCTIONS =
{
  search: 'SYMBOL_SEARCH',
  quote: 'GLOBAL_QUOTE',
  monthly: 'TIME_SERIES_MONTHLY',
  monthly_adjusted: 'TIME_SERIES_MONTHLY_ADJUSTED',
  weekly: 'TIME_SERIES_WEEKLY',
  weekly_adjusted: 'TIME_SERIES_WEEKLY_ADJUSTED',
  daily: 'TIME_SERIES_DAILY',
  daily_adjusted: 'TIME_SERIES_DAILY_ADJUSTED',
  intraday: 'TIME_SERIES_INTRADAY',
  intraday_extended_history: 'TIME_SERIES_INTRADAY_EXTENDED'
}

Constants included from Validations

Validations::VALID_DATATYPES, Validations::VALID_INDICATOR_INTERVALS, Validations::VALID_INTERVALS, Validations::VALID_OUTPUTSIZES, Validations::VALID_SERIES_TYPES, Validations::VALID_SLICES

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol:) ⇒ TimeSeries

Returns a new instance of TimeSeries.



22
23
24
# File 'lib/alphavantage/time_series.rb', line 22

def initialize(symbol:)
  @symbol = symbol
end

Class Method Details

.search(keywords:) ⇒ Object



18
19
20
# File 'lib/alphavantage/time_series.rb', line 18

def self.search(keywords:)
  Client.get(params: { function: self::FUNCTIONS[__method__], keywords: keywords }).best_matches
end

Instance Method Details

#daily(adjusted: false, outputsize: 'compact') ⇒ Object



40
41
42
43
# File 'lib/alphavantage/time_series.rb', line 40

def daily(adjusted: false, outputsize: 'compact')
  function = adjusted ? FUNCTIONS[:daily_adjusted] : FUNCTIONS[__method__]
  Client.get(params: { function: function, symbol: @symbol, outputsize: validate_outputsize(outputsize) })
end

#intraday(adjusted: true, outputsize: 'compact', interval: '5min', datatype: 'json') ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/alphavantage/time_series.rb', line 45

def intraday(adjusted: true, outputsize: 'compact', interval: '5min', datatype: 'json')
  params = {
    function: FUNCTIONS[__method__],
    symbol: @symbol,
    outputsize: validate_outputsize(outputsize),
    interval: validate_interval(interval),
    datatype: datatype,
    adjusted: adjusted
  }

  Client.get(datatype: validate_datatype(datatype), params: params)
end

#intraday_extended_history(adjusted: true, outputsize: 'compact', interval: '5min', slice: 'year1month1') ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/alphavantage/time_series.rb', line 58

def intraday_extended_history(adjusted: true, outputsize: 'compact', interval: '5min', slice: 'year1month1')
    params = {
      function: FUNCTIONS[:intraday_extended_history],
      symbol: @symbol,
      slice: validate_slice(slice),
      interval: validate_interval(interval),
      adjusted: adjusted
    }

  Client.get(datatype: :csv, params: params)
end

#monthly(adjusted: false) ⇒ Object



30
31
32
33
# File 'lib/alphavantage/time_series.rb', line 30

def monthly(adjusted: false)
  function = adjusted ? FUNCTIONS[:monthly_adjusted] : FUNCTIONS[__method__]
  Client.get(params: { function: function, symbol: @symbol })
end

#quoteObject



26
27
28
# File 'lib/alphavantage/time_series.rb', line 26

def quote
  Client.get(params: { function: FUNCTIONS[__method__], symbol: @symbol }).global_quote
end

#weekly(adjusted: false) ⇒ Object



35
36
37
38
# File 'lib/alphavantage/time_series.rb', line 35

def weekly(adjusted: false)
  function = adjusted ? FUNCTIONS[:weekly_adjusted] : FUNCTIONS[__method__]
  Client.get(params: { function: function, symbol: @symbol })
end