PHP code example of openwse / swap
1. Go to this page and download the library: Download openwse/swap library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
openwse / swap example snippets
use Swap\Builder;
// Build Swap
$swap = (new Builder())
// Use the Fixer.io service as first level provider
->add('fixer', ['access_key' => 'your-access-key'])
// Use the currencylayer.com service as first fallback
->add('currency_layer', ['access_key' => 'secret', 'enterprise' => false])
// Use the exchangeratesapi.io service as second fallback
->add('exchange_rates_api', ['access_key' => 'secret'])
// Use the abstractapi.com service as third fallback
->add('abstract_api', ['api_key' => 'secret'])
->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'));