Giter VIP home page Giter VIP logo

ecb-rate-client's Introduction

ecb-rate-client

Build Status

This library is a simple wrapper around the Daily exchange rate xml publish by the European Central Bank.

It provides a simple features to get the rate between two currencies as long as they are listed in the aforementioned xml.

Sample usage

Getting the value of 1 EUR in USD

In this case, the library simply parse the corresponding rate in the ECB xml

FxQuoteRequest fxQuoteRequest = FxQuoteRequest.builder().baseCurrency(Currency.getInstance("EUR"))
        .quoteCurrency(Currency.getInstance("USD")).build();

EcbRateClient ecbRateClient = EcbRateClient.getInstance();

try {
    FxQuote quote = ecbRateClient.getQuote(fxQuoteRequest);
    System.out.println("On " + quote.getQuoteDate().format(DateTimeFormatter.ISO_DATE) + " 1 " +
            fxQuoteRequest.getBaseCurrency().getDisplayName() + " was worth " + quote.getRate() + " " +
            fxQuoteRequest.getQuoteCurrency().getDisplayName());

} catch (UnsupportedCurrencyException e) {
    e.printStackTrace();
}

Getting the value of 1 USD in EUR

In this case, the library takes the multiplicative inverse of the EUR/USD rate from the ECB xml

FxQuoteRequest fxQuoteRequest = FxQuoteRequest.builder().baseCurrency(Currency.getInstance("USD"))
        .quoteCurrency(Currency.getInstance("EUR")).build();

EcbRateClient ecbRateClient = EcbRateClient.getInstance();

try {
    FxQuote quote = ecbRateClient.getQuote(fxQuoteRequest);
    System.out.println("On " + quote.getQuoteDate().format(DateTimeFormatter.ISO_DATE) + " 1 " +
            fxQuoteRequest.getBaseCurrency().getDisplayName() + " was worth " + quote.getRate() + " " +
            fxQuoteRequest.getQuoteCurrency().getDisplayName());

} catch (UnsupportedCurrencyException e) {
    e.printStackTrace();
}

Getting the value of 1 CHF in USD

In this case, the libray gets the EUR/CHF and EUR/USD rate and divide the EUR/USD rate by the EUR/CHF rate.

FxQuoteRequest fxQuoteRequest = FxQuoteRequest.builder().baseCurrency(Currency.getInstance("CHF"))
        .quoteCurrency(Currency.getInstance("USD")).build();

EcbRateClient ecbRateClient = EcbRateClient.getInstance();

try {
    FxQuote quote = ecbRateClient.getQuote(fxQuoteRequest);
    System.out.println("On " + quote.getQuoteDate().format(DateTimeFormatter.ISO_DATE) + " 1 " +
            fxQuoteRequest.getBaseCurrency().getDisplayName() + " was worth " + quote.getRate() + " " +
            fxQuoteRequest.getQuoteCurrency().getDisplayName());

} catch (UnsupportedCurrencyException e) {
    e.printStackTrace();
}

Exception

The library will throw a UnsupportedCurrencyException if one of the currency in the currency is pair is not EUR and not listed in the ECB xml (for instance XPF is one of those currency at the time of writing )

ecb-rate-client's People

Contributors

geoffroyw avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.