Class: OandaRubyClient::ExchangeRatesClient

Inherits:
Object
  • Object
show all
Defined in:
lib/oanda_ruby_client/exchange_rates_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key = ENV['OANDA_RUBY_CLIENT_API_KEY'], use_ssl = true) ⇒ ExchangeRatesClient

Returns a new instance of ExchangeRatesClient.

Parameters:

  • api_key (String) (defaults to: ENV['OANDA_RUBY_CLIENT_API_KEY'])

    The API key for the Excange Rates API.

  • use_ssl (Boolean) (defaults to: true)

    If true, sets the URL endpoint scheme to https. If false, sets the scheme to http.



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

def initialize(api_key = ENV['OANDA_RUBY_CLIENT_API_KEY'], use_ssl = true)
  @api_key, @use_ssl = api_key, use_ssl
end

Instance Method Details

#currenciesHash<String, String>

Returns a hash of the supported currency codes to their descriptions.

Returns:

  • (Hash<String, String>)

    a hash of the supported currency codes to their descriptions



16
17
18
19
20
21
22
23
24
# File 'lib/oanda_ruby_client/exchange_rates_client.rb', line 16

def currencies
  currencies_response = HTTParty.get("#{oanda_endpoint}#{CURRENCIES_PATH}", headers: oanda_headers)
  handle_response(currencies_response.response)
  result = {}
  currencies_response.parsed_response['currencies'].each do |currency|
    result[currency['code']] = currency['description']
  end
  result
end

#rates(rates_request) ⇒ OpenStruct

Returns the exchanges rates based on the specified request

Parameters:

Returns:

  • (OpenStruct)

    An object structured similarly to the response from the Exchange Rate API



30
31
32
33
34
35
# File 'lib/oanda_ruby_client/exchange_rates_client.rb', line 30

def rates(rates_request)
  rates_uri = "#{oanda_endpoint}#{RATES_BASE_PATH}#{rates_request.base_currency}.json?#{rates_request.query_string}"
  rates_response = HTTParty.get(rates_uri, headers: oanda_headers)
  handle_response(rates_response.response)
  OpenStruct.new(rates_response.parsed_response)
end

#remaining_quotesFixnum, 'unlimited'

Returns the number of remaining quote requests

Returns:

  • (Fixnum, 'unlimited')

    Number of remaining quote requests



40
41
42
43
44
# File 'lib/oanda_ruby_client/exchange_rates_client.rb', line 40

def remaining_quotes
  remaining_quotes_response = HTTParty.get("#{oanda_endpoint}#{REMAINING_QUOTES_PATH}", headers: oanda_headers)
  handle_response(remaining_quotes_response.response)
  remaining_quotes_response.parsed_response['remaining_quotes']
end