Fixer is a simple and lightweight API for foreign exchange rates that supports up to 170 world currencies. | |
currencylayer provides reliable exchange rates and currency conversions for your business up to 168 world currencies. | |
exchangeratesapi provides reliable exchange rates and currency conversions for your business with over 15 data sources. |
composer require florianv/swap-bundle php-http/message php-http/guzzle6-adapter
Enable the Bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Florianv\SwapBundle\FlorianvSwapBundle(),
);
}
We recommend to use one of the services that support our project, providing a free plan up to 1,000 requests per day.
The complete list of all supported services is available here:
# app/config/config.yml
florianv_swap:
providers:
apilayer_fixer:
api_key: secret # Get your key here: https://fixer.io/
apilayer_currency_data: # Get your key here: https://currencylayer.com
api_key: secret
apilayer_exchange_rates_data: # Get your key here: https://exchangeratesapi.io
api_key: secret
abstract_api: # Get your key here: https://app.abstractapi.com/users/signup
api_key: secret
webservicex: ~ # WebserviceX
cryptonator: ~ # Cryptonator
forge: # Forge
api_key: secret
russian_central_bank: ~ # Russian Central Bank
european_central_bank: ~ # European Central Bank
national_bank_of_romania: ~ # National Bank of Romania
central_bank_of_czech_republic: ~ # Central Bank of the Czech Republic
central_bank_of_republic_turkey: ~ # Central Bank of the Republic of Turkey
open_exchange_rates: # Open Exchange Rates
app_id: secret
enterprise: true
xignite: # Xignite
token: secret
currency_converter: # Currency Converter API
access_key: secret
enterprise: true
xchangeapi: # xChangeApi.com
api-key: secret
array:
latestRates:
'EUR/GBP': 1.5
'EUR/USD': 1.1
historicalRates:
'2017-01-01':
'EUR/GBP': 1.5
'EUR/USD': 1.1
You can register multiple providers, they will be called in chain regarding to their priorities (higher first). In this example, Swap uses the Fixer service, and will fallback to currencylayer in case of failure.
# app/config/config.yml
florianv_swap:
providers:
apilayer_fixer:
api_key: secret
#priority: 0 (default)
apilayer_currency_data:
access_key: secret
priority: 1
Currently only some of the Symfony Cache adapters are supported.
You must specify a lifetime for your cache entries:
# app/config/config.yml
florianv_swap:
cache:
ttl: 3600 # seconds
You can use a service id:
# app/config/config.yml
florianv_swap:
cache:
type: my_cache_service
or one of the implemented providers (array
, apcu
, filesystem
)
# app/config/config.yml
florianv_swap:
cache:
type: apcu
The Swap service is available in the container:
/** @var \Swap\Swap $swap */
$swap = $this->get('florianv_swap.swap');
For more information about how to use it, please consult the Swap documentation.