Class: Alphavantage::Forex

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

Constant Summary collapse

FUNCTIONS =
{
  exchange_rates: 'CURRENCY_EXCHANGE_RATE',
  intraday: 'FX_INTRADAY',
  daily: 'FX_DAILY',
  weekly: 'FX_WEEKLY',
  monthly: 'FX_MONTHLY'
}

Constants included from Validations

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

Instance Method Summary collapse

Constructor Details

#initialize(from_symbol:, to_symbol:) ⇒ Forex

Returns a new instance of Forex.



13
14
15
16
# File 'lib/alphavantage/forex.rb', line 13

def initialize(from_symbol:,to_symbol:)
  @from_symbol = from_symbol
  @to_symbol = to_symbol
end

Instance Method Details

#daily(outputsize: 'compact') ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/alphavantage/forex.rb', line 36

def daily(outputsize: 'compact')
  Client.get(params: {
    function: FUNCTIONS[__method__],
    from_symbol: @from_symbol,
    to_symbol: @to_symbol,
    outputsize: validate_outputsize(outputsize)
  })
end

#exchange_ratesObject



18
19
20
21
22
23
24
# File 'lib/alphavantage/forex.rb', line 18

def exchange_rates
  Client.get(params: {
    function: FUNCTIONS[__method__],
    from_currency: @from_symbol,
    to_currency: @to_symbol
  }).realtime_currency_exchange_rate
end

#intraday(interval: '5min', outputsize: 'compact') ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/alphavantage/forex.rb', line 26

def intraday(interval: '5min', outputsize: 'compact')
  Client.get(params: {
    function: FUNCTIONS[__method__],
    from_symbol: @from_symbol,
    to_symbol: @to_symbol,
    interval: validate_interval(interval),
    outputsize: validate_outputsize(outputsize)
  })
end

#weeklyObject Also known as: monthly



45
46
47
48
49
50
51
# File 'lib/alphavantage/forex.rb', line 45

def weekly
  Client.get(params: {
    function: FUNCTIONS[__callee__],
    from_symbol: @from_symbol,
    to_symbol: @to_symbol
  })
end