PHP code example of adimiuprix / coinmarketcap

1. Go to this page and download the library: Download adimiuprix/coinmarketcap 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/ */

    

adimiuprix / coinmarketcap example snippets


use adimiuprix\CoinMarketCap\ClientBuilder;

$client = (new ClientBuilder())
    ->setApiKey('your-api-key')
    ->setTimeout(30)
    ->build();

use adimiuprix\CoinMarketCap\Facades\CoinMarketCap;

$quotes = CoinMarketCap::cryptocurrency()->quotesLatest([
    'id' => '1,1027',
    'convert' => 'USD',
]);

foreach ($quotes['data'] as $asset) {
    echo $asset['symbol'] . ': $' . $asset['quote']['USD']['price'] . PHP_EOL;
}

$listings = CoinMarketCap::cryptocurrency()->listingsLatest([
    'start' => 1,
    'limit' => 10,
    'convert' => 'USD',
]);

use adimiuprix\CoinMarketCap\Exception\RateLimitException;

try {
    $data = CoinMarketCap::cryptocurrency()->listingsLatest(['limit' => 10]);
} catch (RateLimitException $exception) {
    $seconds = $exception->getRetryAfter() ?? 60;

    // Queue a retry after $seconds instead of retrying immediately.
}

$client = (new ClientBuilder())
    ->setApiKey('your-sandbox-api-key')
    ->useSandbox()
    ->build();
bash
php artisan vendor:publish --tag=coinmarketcap-config
bash
composer test
composer phpstan
vendor/bin/php-cs-fixer fix --dry-run --diff