Class ExchangeRateReader

java.lang.Object
org.episteme.core.io.AbstractResourceReader<Real>
org.episteme.social.economics.loaders.ExchangeRateReader
All Implemented Interfaces:
ResourceIO<Real>, ResourceReader<Real>

public class ExchangeRateReader extends AbstractResourceReader<Real>
Modern currency exchange rate reader using free public APIs.

Supports multiple data sources:

  • ECB (European Central Bank) - Free, no API key required, updates daily
  • Frankfurter - Free, based on ECB data, no API key required
  • ExchangeRate-API - Free tier with 1500 requests/month

This replaces the deprecated OandaRateLoader.

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Constructor Details

    • ExchangeRateReader

      public ExchangeRateReader()
    • ExchangeRateReader

      public ExchangeRateReader(ExchangeRateReader.Source source)
  • Method Details

    • getName

      public String getName()
      Description copied from interface: ResourceIO
      Returns the display name of this resource handler. MUST be implemented with I18N support.
      Returns:
      the display name
    • getCategory

      public String getCategory()
      Description copied from interface: ResourceIO
      Returns the category for grouping. MUST be implemented with I18N support.
      Returns:
      the category name
    • getDescription

      public String getDescription()
      Description copied from interface: ResourceIO
      Returns a short description of this resource handler. MUST be implemented with I18N support.
      Returns:
      the description
    • getLongDescription

      public String getLongDescription()
      Description copied from interface: ResourceIO
      Returns a long description of this resource handler. MUST be implemented with I18N support.
      Returns:
      the long description
    • getResourcePath

      public String getResourcePath()
      Description copied from interface: ResourceIO
      Returns the base path where this resource is located.
    • getResourceType

      public Class<Real> getResourceType()
      Description copied from interface: ResourceIO
      Returns the type of resource.
    • getSupportedVersions

      public String[] getSupportedVersions()
      Description copied from interface: ResourceIO
      Returns the supported versions of the format this reader/writer handles.

      Each implementation MUST override this method to declare which versions of the underlying format are supported. The returned array should contain version strings in the format's standard notation (e.g., "3.0", "2.1", "Level 3 Version 2").

      Examples:

      • MathML: {"3.0", "2.0"}
      • SBML: {"Level 3 Version 2", "Level 3 Version 1", "Level 2 Version 5"}
      • PhyloXML: {"1.10", "1.00"}

      Returns:
      array of supported version strings, never null (empty array if version-agnostic)
    • loadFromSource

      protected Real loadFromSource(String currencyPairId) throws Exception
      Loads an exchange rate for a currency pair.
      Specified by:
      loadFromSource in class AbstractResourceReader<Real>
      Parameters:
      currencyPairId - Format: "FROM/TO" (e.g., "USD/EUR" or "EUR/JPY")
      Returns:
      The exchange rate (how many target units per 1 source unit)
      Throws:
      Exception
    • getAllRates

      public Map<String,Real> getAllRates(String baseCurrency) throws Exception
      Gets all available rates for a base currency.
      Parameters:
      baseCurrency - The base currency code (e.g., "USD", "EUR")
      Returns:
      Map of currency codes to exchange rates
      Throws:
      Exception
    • convert

      public Real convert(Real amount, String from, String to) throws Exception
      Converts an amount between currencies.
      Parameters:
      amount - The amount to convert
      from - Source currency code
      to - Target currency code
      Returns:
      The converted amount
      Throws:
      Exception