## Interface FxRateProvider

• All Known Subinterfaces:
BaseProvider, RatesProvider
All Known Implementing Classes:
FxMatrix, FxRate, ImmutableRatesProvider, MarketDataFxRateProvider

public interface FxRateProvider
A provider of FX rates.

This provides the ability to obtain an FX rate. The interface does not mandate when the rate applies, however it typically represents the current rate.

One possible implementation is FxMatrix.

Implementations do not have to be immutable, but calls to the methods must be thread-safe.

• ### Method Summary

All Methods
Modifier and Type Method Description
default double convert​(double amount, Currency fromCurrency, Currency toCurrency)
Converts an amount in a currency to an amount in a different currency using this rate.
default double fxRate​(CurrencyPair currencyPair)
Gets the FX rate for the specified currency pair.
double fxRate​(Currency baseCurrency, Currency counterCurrency)
Gets the FX rate for the specified currency pair.
static FxRateProvider lazy​(Supplier<FxRateProvider> target)
Returns an FxRateProvider that delays fetching its underlying provider until actually necessary.
static FxRateProvider minimal()
Returns a provider that provides minimal behavior.
static FxRateProvider noConversion()
Returns a provider that always throws an exception.
• ### Method Detail

• #### lazy

static FxRateProvider lazy​(Supplier<FxRateProvider> target)
Returns an FxRateProvider that delays fetching its underlying provider until actually necessary.

This is typically useful where you may need a MarketDataFxRateProvider but want to delay loading market data to construct the provider until you are sure you actually do need it.

Parameters:
target - the supplier of the underlying provider
Returns:
the provider
• #### noConversion

static FxRateProvider noConversion()
Returns a provider that always throws an exception.

The provider will always throw an exception, even if the two currencies are the same.

Returns:
the provider
• #### minimal

static FxRateProvider minimal()
Returns a provider that provides minimal behavior.

This provider returns a rate or 1 when the two currencies are the same. When the two currencies differ an exception will be thrown.

Returns:
the provider
• #### convert

default double convert​(double amount,
Currency fromCurrency,
Currency toCurrency)
Converts an amount in a currency to an amount in a different currency using this rate.

The currencies must both be included in the currency pair of this rate.

Parameters:
amount - an amount in fromCurrency
fromCurrency - the currency of the amount
toCurrency - the currency into which the amount should be converted
Returns:
the amount converted into toCurrency
Throws:
IllegalArgumentException - if either of the currencies aren't included in the currency pair of this rate
• #### fxRate

double fxRate​(Currency baseCurrency,
Currency counterCurrency)
Gets the FX rate for the specified currency pair.

The rate returned is the rate from the base currency to the counter currency as defined by this formula: (1 * baseCurrency = fxRate * counterCurrency).

Parameters:
baseCurrency - the base currency, to convert from
counterCurrency - the counter currency, to convert to
Returns:
the FX rate for the currency pair
Throws:
RuntimeException - if no FX rate could be found
• #### fxRate

default double fxRate​(CurrencyPair currencyPair)
Gets the FX rate for the specified currency pair.

The rate returned is the rate from the base currency to the counter currency as defined by this formula: (1 * baseCurrency = fxRate * counterCurrency).

Parameters:
currencyPair - the ordered currency pair defining the rate required
Returns:
the FX rate for the currency pair
Throws:
RuntimeException - if no FX rate could be found