Forex.Fetcher (forex v0.1.1)

View Source

The Forex.Fetcher module is responsible for fetching the exchange rates from the cache or the feed on periodic intervals or on demand.

The exchange rates are fetched from the cache if the cache is enabled and the cache is not stale. Otherwise, the exchange rates are fetched from the feed and stored in the cache.

By default, the exchange rates are fetched from the feed every 12 hours as the European Central Bank (ECB) updates the reference rates at around 16:00 CET every working day. This can be configured by setting the :schedular_interval option in the Forex application environment, example, to fetch the rates every 24 hours:

To configure the Forex.Fetcher module, the following options are available:

  • use_cache - A boolean value that determines if the cache should be used. The default value is true.

  • cache_module - The cache module to use. The default value is Forex.Cache.ETS.

  • schedular_interval - The interval in milliseconds to fetch the exchange rates from the feed. The default value is 12 hours.

To start the Forex.Fetcher process, use the start_link/1 or start/1 functions, or add the Forex.Fetcher.Supervisor to the application supervision tree.

Summary

Functions

Returns a specification to start this module under a supervisor.

Fetch the respective exchange rates from the cache or the feed, based on the key and the opts.

Validate and return the options for the Forex.Fetcher module functions, using default values if the options are not provided.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(key, opts \\ [])

Fetch the respective exchange rates from the cache or the feed, based on the key and the opts.

The key can be one of the following atoms:

  • :current_rates - Fetch the current exchange rates.
  • :last_ninety_days_rates - Fetch the exchange rates for the last 90 days.
  • :historic_rates - Fetch the exchange rates for a specific date.

The opts can be a keyword list with the module options, that is, the options returned from the Forex.Fetcher.options/1 function.

options(opts \\ [])

Validate and return the options for the Forex.Fetcher module functions, using default values if the options are not provided.