Coinlayer#
This service retrieves the data from Coinlayer.
Installation#
Install the service:
composer require peso/coinlayer-service
Install the service with all recommended dependencies:
composer require peso/coinlayer-service php-http/discovery guzzlehttp/guzzle symfony/cache
Usage#
Example:
<?php
use Peso\Peso\CurrencyConverter;
use Peso\Services\Coinlayer\AccessKeyType;
use Peso\Services\CoinlayerService;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;
$cache = new Psr16Cache(new FilesystemAdapter(directory: __DIR__ . '/cache'));
// You need a reversible service to get fiat to crypto rates
// (only crypto to fiat is supported for rate requests)
$service = CoinlayerService::reversible('...', AccessKeyType::Free, cache: $cache);
$converter = new CurrencyConverter($service);
// 6.91 as of 2026-04-06
echo $converter->convert('12500', 'USD', 'ETH', 2), PHP_EOL;