## 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.
• ### Method Detail

• #### 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:
java.lang.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:
java.lang.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:
java.lang.RuntimeException - if no FX rate could be found