Giter Club home page Giter Club logo

ecb-api's Introduction

ECB-API

European Central Bank EURO exchange PHP API

Installation with Composer

composer require richardds/ecb-api

Examples

EURO to FOREIGN, FOREIGN to EURO

require __DIR__ . '/vendor/autoload.php';

use Richardds\ECBAPI\ECBConverter;

$converter = new ECBConverter();

echo $converter->toEuro(150, 'USD', 3);
echo $converter->toForeign(150, 'USD');
print_r($converter->toForeign(150, ['EUR', 'USD', 'CHF', 'RUB', 'CZK'])) . PHP_EOL;
126.968
177.21
Array
(
    [EUR] => 150
    [USD] => 126.96800406298
    [CHF] => 130.68478829064
    [RUB] => 2.1159184778929
    [CZK] => 5.736137667304
)

Exchange rate list

require __DIR__ . '/vendor/autoload.php';

use Richardds\ECBAPI\ECBConverter;

$converter = new ECBConverter();

$references = $converter->list(true);

foreach ($references as $code => $rate) {
    if ($code === 'EUR') {
        continue;
    }

    printf("1.00 EUR = %.2f %s\n1.00 %s = %.2f EUR\n", $rate, $code, $code, (1 / $rate));
}
1.00 EUR = 1.18 USD
1.00 USD = 0.85 EUR
1.00 EUR = 130.31 JPY
1.00 JPY = 0.01 EUR
1.00 EUR = 1.96 BGN
1.00 BGN = 0.51 EUR
1.00 EUR = 26.15 CZK
1.00 CZK = 0.04 EUR
...

ecb-api's People

Contributors

mike22 avatar mrsimonbennett avatar richardds avatar simonschaufi avatar tsvgos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ecb-api's Issues

Problem with float amount

I am testing the library and I cannot convert quantities with decimals. For example 150.2 and I can't convert amounts like 0.69 to euros either.

Can you tell me how to do these conversions?

Local file caching

Hello!
Thank you very much for implementing this API! I use it and would like to have some small improvement:
Since the xml file is currently fetched on every request, I would like to store it for some hours until I will fetch it again.

As an inspiration, you could do the same like https://github.com/simplepie/simplepie. The file cache would be enough for me right now. This is how they implemented it:

https://github.com/simplepie/simplepie/blob/master/tests/CacheTest.php#L95-L100

PS: Please also tag the current state as I can only require dev-master via composer. Thanx!

Exchange rate at specific time

Hi!
It would be nice if I could fetch the exchange rate on a specific date in the past.

// e.g. 
$date = new \DateTime('2020-10-01');
echo $converter->toEuro(150, 'USD', 3, $date);

cURL error handling

When there is an cULR error it cannot be handled because curl handler ($ch) is closed before error message is extacted:
in ECB.php:
}

    curl_close($ch);

    throw new ECBException(curl_error($ch), ECBException::DATA_DOWNLOAD_FAILED);

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.