public class ECBHistoricRateProvider extends AbstractRateProvider
ExchangeRateProvider
that loads data from the European Central Bank data feed (XML). It loads the
current exchange rates, as well as historic rates for the past 1500 days. The
provider loads all data up to 1999 into its historic data cache.
The default date is yesterday or the most recent day of week. To uses exchange rate from a specific date, you can use this way:
CurrencyUnit termCurrency = ...;
LocalDate localDate = ...;
ConversionQuery conversionQuery = ConversionQueryBuilder.of().setTermCurrency(euro).set(localDate).build();v
CurrencyConversion currencyConversion = provider.getCurrencyConversion(conversionQuery);
MonetaryAmount money = ...;
MonetaryAmount result = currencyConversion.apply(money);| Modifier and Type | Field and Description |
|---|---|
static CurrencyUnit |
BASE_CURRENCY
Base currency of the loaded rates is always EUR.
|
protected CountDownLatch |
loadLock |
protected String |
loadState |
protected Map<LocalDate,Map<String,ExchangeRate>> |
rates
Historic exchange rates, rate timestamp as UTC long.
|
LOGGER| Constructor and Description |
|---|
ECBHistoricRateProvider() |
| Modifier and Type | Method and Description |
|---|---|
String |
getDataId() |
ExchangeRate |
getExchangeRate(ConversionQuery query) |
protected LocalDate[] |
getTargetDates(ConversionQuery query) |
void |
newDataLoaded(String data,
InputStream is)
Callback called from the
LoaderService, when new data was
read for a given data item. |
divide, divide, formatLocalDate, getContext, getCurrencyConversion, multiplygetCurrencyConversion, getCurrencyConversion, getExchangeRate, getExchangeRate, getReversed, isAvailable, isAvailable, isAvailablepublic static final CurrencyUnit BASE_CURRENCY
protected final Map<LocalDate,Map<String,ExchangeRate>> rates
protected volatile CountDownLatch loadLock
public ECBHistoricRateProvider() throws MalformedURLException
MalformedURLExceptionpublic void newDataLoaded(String data, InputStream is)
LoaderService.LoaderListenerLoaderService, when new data was
read for a given data item.newDataLoaded in interface LoaderService.LoaderListenerdata - the resource idis - the input stream for accessing the dataprotected LocalDate[] getTargetDates(ConversionQuery query)
public ExchangeRate getExchangeRate(ConversionQuery query)
getExchangeRate in interface ExchangeRateProvidergetExchangeRate in class AbstractRateProviderCopyright © 2012–2020 JavaMoney. All rights reserved.