florianv / swap
Exchange rates library for PHP
Installs: 5 183 825
Dependents: 16
Suggesters: 7
Security: 0
Stars: 1 312
Watchers: 36
Forks: 138
Open Issues: 0
Requires
- php: ^7.1.3 || ^8.0
- florianv/exchanger: ^2.0
Requires (Dev)
- nyholm/psr7: ^1.0
- php-http/message: ^1.7
- php-http/mock-client: ^1.0
- phpunit/phpunit: ^7 || ^8 || ^9
This package is auto-updated.
Last update: 2024-11-11 10:03:01 UTC
README
Swap allows you to retrieve currency exchange rates from various services such as Fixer, Currency Data or Exchange Rates Data and optionally cache the results. It is integrated to other libraries like moneyphp/money and provides a Symfony Bundle and a Laravel Package.
Sponsors
QuickStart
$ composer require php-http/curl-client nyholm/psr7 php-http/message florianv/swap
use Swap\Builder; // Build Swap $swap = (new Builder()) // Use the Fixer service as first level provider ->add('apilayer_fixer', ['api_key' => 'Get your key here: https://fixer.io/']) // Use the currencylayer service as first fallback ->add('apilayer_currency_data', ['api_key' => 'Get your key here: https://currencylayer.com']) // Use the exchangerates service as second fallback ->add('apilayer_exchange_rates_data', ['api_key' => 'Get your key here: https://exchangeratesapi.io/']) ->build(); // Get the latest EUR/USD rate $rate = $swap->latest('EUR/USD'); // 1.129 $rate->getValue(); // 2016-08-26 $rate->getDate()->format('Y-m-d'); // Get the EUR/USD rate 15 days ago $rate = $swap->historical('EUR/USD', (new \DateTime())->modify('-15 days'));
We recommend to use the services that support our project, providing a free plan up to 100 requests per month.
Documentation
The documentation for the current branch can be found here.
Services
Here is the list of the currently implemented services:
Additionally, you can add your own services as long as they implement the ExchangeRateService
interface.
Integrations
- A Symfony Bundle FlorianvSwapBundle
- A Laravel Package florianv/laravel-swap
Credits
License
The MIT License (MIT). Please see LICENSE for more information.