Interface CurrencyConverter

All Known Implementing Classes:
BundledExchangeRates, CurrencyConverters.Chain, FrankfurterExchangeRates, PinnedExchangeRates

public interface CurrencyConverter
Restates an amount in another currency, so a design whose prices come back in several currencies (the live Fabric price search quotes London in GBP, Frankfurt in EUR, Tokyo in JPY) is priced and ranked in one. Implementations must be deterministic and pure: the same arguments give the same rate, and no call reaches the network unless the implementation was supplied for that purpose.

The SDK resolves rates in this order (see com.eqixiac.equinix.design.cost.CurrencyConverters): rates pinned in the spec's commercial.exchangeRates (part of the spec's fingerprint, never widened unless the spec states a band), then a converter supplied by the caller or a DesignPlugin, then the ECB reference rates fetched once per run from the Frankfurter API, then the bundled reference table. A currency absent from every source leaves the line unpriced with that reason.

  • Method Details

    • rate

      Parameters:
      from - ISO 4217 code
      to - ISO 4217 code
      Returns:
      the rate, or empty when this converter has none for the pair
    • name

      default String name()
      Returns:
      a short name for reasons and diagnostics
    • convert

      default Optional<CurrencyConverter.Converted> convert(BigDecimal amount, String from, String to)
      Converts an amount.
      Parameters:
      amount - the amount in from
      from - ISO 4217 code
      to - ISO 4217 code
      Returns:
      the converted amount (rounded half-up to cents) with the rate used, or empty when there is no rate