4

EUR と USD の間の特定の日付の為替レートを取得しようとしています。問題は、私は常に日付の交換を取得していることです:LocalDate{year=2016, month=1, dayOfMonth=8}クエリで日付を指定しても問題ありません。

これが私のmaven依存関係です:

        <dependency>
            <groupId>javax.money</groupId>
            <artifactId>money-api-bp</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.javamoney</groupId>
            <artifactId>moneta-bp</artifactId>
            <version>1.1</version>
        </dependency>

ソースコード:

public class Test {
    public static void main(String[] args) {
        ConversionQuery query = ConversionQueryBuilder.of()
                .setProviderName("ECB")
                .setBaseCurrency(Monetary.getCurrency("EUR"))
                .setTermCurrency(Monetary.getCurrency("USD"))
                .set(LocalDate.class, LocalDate.of(2017, Month.SEPTEMBER, 10))
                .build();
        final ExchangeRateProvider provider = getExchangeRateProvider(query);
        final ExchangeRate rate1 = provider.getExchangeRate(query);
        System.out.println(rate1);

        ExchangeRateProvider ecbExchangeRateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
        ExchangeRate rate = ecbExchangeRateProvider.getExchangeRate("EUR", "USD");
        System.out.println(rate);

    }
}

そしてsoutからの出力:

sep. 11, 2017 9:58:29 AM org.javamoney.moneta.internal.convert.ECBAbstractRateProvider newDataLoaded
INFO: Loaded ECBCurrentRateProvider exchange rates for days:1
sep. 11, 2017 9:58:30 AM org.javamoney.moneta.internal.convert.ECBAbstractRateProvider newDataLoaded
INFO: Loaded ECBHistoric90RateProvider exchange rates for days:63
ExchangeRate [base=EUR, factor=1.0861, conversionContext=ConversionContext (
{provider=ECB, rateTypes=[DEFERRED], providerDescription=European Central Bank, days=1, org.javamoney.moneta.internal.convert.LocalDate=LocalDate{year=2016, month=1, dayOfMonth=8}, javax.money.convert.RateType=HISTORIC})]
ExchangeRate [base=EUR, factor=1.0861, conversionContext=ConversionContext (
{provider=ECB, rateTypes=[DEFERRED], providerDescription=European Central Bank, days=1, org.javamoney.moneta.internal.convert.LocalDate=LocalDate{year=2016, month=1, dayOfMonth=8}, javax.money.convert.RateType=HISTORIC})]
ExchangeRate [base=USD, factor=0.9207255317189946, conversionContext=ConversionContext (
{provider=ECB, rateTypes=[DEFERRED], providerDescription=European Central Bank, days=1, org.javamoney.moneta.internal.convert.LocalDate=LocalDate{year=2016, month=1, dayOfMonth=8}, javax.money.convert.RateType=HISTORIC})]
sep. 11, 2017 9:58:35 AM org.javamoney.moneta.internal.convert.ECBAbstractRateProvider newDataLoaded
INFO: Loaded ECBHistoricRateProvider exchange rates for days:4358

ありがとう!

4

1 に答える 1