PHP code example of xe / xecd-rates-client
1. Go to this page and download the library: Download xe/xecd-rates-client 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/ */
xe / xecd-rates-client example snippets
Xe\Xecd\Client\Rates\XecdRatesClientAspectKernel;
use Xe\Xecd\Client\Rates\Exception\XecdRatesException;
use GuzzleHttp\Exception\RequestException;
XecdRatesClientAspectKernel::getInstance()->init([
'cacheDir' => '/your/cache/directory',
]);
$xecdRatesClient = XecdRatesClient::create(<YOUR_ACCOUNT_ID>, <YOUR_API_KEY>);
try
{
$conversions = $xecdRatesClient->convertFrom(new Currency('CAD'), Currencies::wildcard(), 12345.67)->getBody();
foreach ($conversions->getConversions() as $currency => $currencyConversions) {
foreach ($currencyConversions as $timestamp => $conversion) {
echo "{$conversion->getFromAmount()} {$conversion->getFromCurrency()} = {$conversion->getToAmount()} {$conversion->getToCurrency()}\n";
}
}
} catch (XecdRatesException $e) {
// API errors with error code.
} catch (Exception $e) {
// ALl other errors, such as connection timeout errors.
}