Class FrankfurterExchangeRates

java.lang.Object
com.eqixiac.equinix.design.cost.FrankfurterExchangeRates
All Implemented Interfaces:
CurrencyConverter

public final class FrankfurterExchangeRates extends Object implements CurrencyConverter
Live ECB reference rates from the Frankfurter API (no key): one GET <baseUrl>/latest?base=<target> per converter, made on the first conversion that needs it and cached for the converter's life; never retried. The request carries only the currency code and a generic User-Agent. Shape observed 2026-11-12: {"amount":1.0,"base":"USD","date":"2026-11-11","rates":{"EUR":0.89871,"GBP":0.75149,...}} (no AED).

When the call fails, times out (3 s connect, 5 s overall) or returns another shape, or a currency is absent, rate(String, String) is empty so the chain falls back to the bundled table; fallbackNote() says why. Never throws. Rates are reference mid rates, not dealing rates, so converted ranges are widened by 2.0% either side.

  • Field Details

    • DEFAULT_BASE_URL

      public static final String DEFAULT_BASE_URL
      The default endpoint root.
      See Also:
    • BAND_PERCENT

      public static final double BAND_PERCENT
      Widening for live ECB reference rates, either side, in percent.
      See Also:
  • Constructor Details

  • Method Details

    • httpFetcher

      public static FrankfurterExchangeRates.Fetcher httpFetcher()
      Returns:
      a java.net.http fetch with a 3 s connect and 5 s request timeout and a generic User-Agent
    • rate

      public Optional<CurrencyConverter.Rate> rate(String from, String to)
      Specified by:
      rate in interface CurrencyConverter
      Parameters:
      from - ISO 4217 code
      to - ISO 4217 code
      Returns:
      the rate, or empty when this converter has none for the pair
    • fallbackNote

      public Optional<String> fallbackNote()
      Returns:
      why live rates were not used, empty when they were fetched (or no conversion needed them yet)
    • attempted

      public boolean attempted()
      Returns:
      whether the single fetch has been attempted
    • name

      public String name()
      Specified by:
      name in interface CurrencyConverter
      Returns:
      a short name for reasons and diagnostics