PHP code example of pangzlab / coingecko-api

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

    

pangzlab / coingecko-api example snippets




use PangzLab\CoinGecko\Client\CoinGeckoApiClient;

$client = new CoinGeckoApiClient();




use PangzLab\CoinGecko\Client\CoinGeckoUrlBuilder;

$query = new CoinGeckoUrlBuilder();




use PangzLab\CoinGecko\Client\CoinGeckoApiClient;

$client = new CoinGeckoApiClient();

try {

    $response = $client->set()->ping()->send();
    print_r($response);
    // do something here..

} catch (Exception $e) {
    print($e->getMessage());
}




use PangzLab\CoinGecko\Client\CoinGeckoApiClient;
use PangzLab\CoinGecko\Client\CoinGeckoApiClient;

$q = new CoinGeckoUrlBuilder();
$client = new CoinGeckoApiClient();

try {

    $response = $apiClient->set()
        ->coins()
        ->categories()
        ->send($q->withOrder("name_desc"));
    print_r($response);
    // do something here ...

} catch (Exception $e) {
    print($e->getMessage());
}




use PangzLab\CoinGecko\Client\CoinGeckoApiClient;
use PangzLab\CoinGecko\Client\CoinGeckoUrlBuilder;

$q = new CoinGeckoUrlBuilder();
$client = new CoinGeckoApiClient();

try {

    $response = $apiClient->set()
        ->exchanges("safe_trade")
        ->volumeChart()
        ->send($q->withDays(1));
    print_r($response);
    // do something here ...

} catch (Exception $e) {
    print($e->getMessage());
}




use PangzLab\CoinGecko\Client\CoinGeckoApiClient;
use PangzLab\CoinGecko\Client\CoinGeckoUrlBuilder;

$q = new CoinGeckoUrlBuilder();
$client = new CoinGeckoApiClient();

try {

    $response = $apiClient->set()
        ->coins("verus-coin")
        ->send(
            $q->withLocalization("false")
            ->withDeveloperData("true")
            ->withSparkline("true")
            ->withCommunityData("true")
            ->withMarketData("true")
            ->withTickers("true")
        );
    print_r($response);
    // do something here ...

} catch (Exception $e) {
    print($e->getMessage());
}



use PangzLab\CoinGecko\Client\CoinGeckoApiClient;
use PangzLab\CoinGecko\Client\CoinGeckoUrlBuilder;

$q = new CoinGeckoUrlBuilder();
$client = new CoinGeckoApiClient();

try {

    //No set() method and no send() call
    $apiClient = $apiClient->coins("verus-coin");
    //Separate the call to send
    $response = $apiClient->send(
        $q->withLocalization("false")
        ->withDeveloperData("true")
        ->withSparkline("true")
        ->withCommunityData("true")
        ->withMarketData("true")
        ->withTickers("true")
    );
    print_r($response);

    //Call reset() method to form another request
    $apiClient->reset();
    $apiClient = $apiClient->exchanges("safe_trade")
        ->volumeChart();
    $response = $apiClient->send($q->withDays(1));

    //Call reset() for the next calls
    $apiClient->reset();

    print_r($response);

} catch (Exception $e) {
    print($e->getMessage());
}




use PangzLab\CoinGecko\Client\CoinGeckoApiClient;
use PangzLab\CoinGecko\Client\CoinGeckoUrlBuilder;

$q = new CoinGeckoUrlBuilder();
$client = new CoinGeckoApiClient();

try {
    
    //All caps
    $response = $apiClient->set()
        ->PING()
        ->send();
    print_r($response);

    //All lowercase
    $response = $apiClient->set()
        ->ping()
        ->send();
    print_r($response);

    //UC First
    $response = $apiClient->set()
        ->Ping()
        ->send();
    print_r($response);

    //With underscore - only underscore is allowed
    $response = $apiClient->set()
        ->_PING_()
        ->send();
    print_r($response);

    //With insensitive parameter case
    $response = $apiClient
        ->coins("verus-coin")
        ->send(
            $q->with_LOCALIZATION("false")
            ->withDeveloperData_("true")
            ->withSparkline("true")
            ->withCommunity_DATA("true")
            ->with_Market_Data("true")
            ->withTiCKers("true")
        );
    print_r($response);

} catch (Exception $e) {
    print($e->getMessage());
}




use PangzLab\CoinGecko\Client\CoinGeckoApiClient;
use PangzLab\CoinGecko\Client\CoinGeckoUrlBuilder;

$q = new CoinGeckoUrlBuilder();
$client = new CoinGeckoApiClient();

try {

    $request = $apiClient->set()->ping();

    for($x = 0; $x <= 10; $x++) {
        $response = $request->send();
        sleep(3);
        print_r($response);
    }
    
} catch (Exception $e) {
    print($e->getMessage());
}


$result = $apiClient->set()->ping()->send();

$result = $apiClient->set()->simple()->price()
        ->send(
            $q->withIds('string')
                ->withVsCurrencies('string')
                ->withIncludeMarketCap('string')
                ->withInclude24hrVol('string')
                ->withInclude24hrChange('string')
                ->withIncludeLastUpdatedAt('string')
                ->withPrecision('string')
        );

$result = $apiClient->set()->simple()->tokenPrice('{id}')
        ->send(
            $q->withContractAddresses('string')
                ->withVsCurrencies('string')
                ->withIncludeMarketCap('string')
                ->withInclude24hrVol('string')
                ->withInclude24hrChange('string')
                ->withIncludeLastUpdatedAt('string')
                ->withPrecision('string')
        );

$result = $apiClient->set()->simple()->supportedVsCurrencies()->send();

$result = $apiClient->set()->coins()->list()
        ->send(
            $q->withIncludePlatform('boolean')
        );

$result = $apiClient->set()->coins()->markets()
        ->send(
            $q->withVsCurrency('string')
                ->withIds('string')
                ->withCategory('string')
                ->withOrder('string')
                ->withPerPage('integer')
                ->withPage('integer')
                ->withSparkline('boolean')
                ->withPriceChangePercentage('string')
        );

$result = $apiClient->set()->coins('{id}')
        ->send(
            $q->withLocalization('string')
                ->withTickers('boolean')
                ->withMarketData('boolean')
                ->withCommunityData('boolean')
                ->withDeveloperData('boolean')
                ->withSparkline('boolean')
        );

$result = $apiClient->set()->coins('{id}')->tickers()
        ->send(
            $q->withExchangeIds('string')
                ->withIncludeExchangeLogo('string')
                ->withPage('integer')
                ->withOrder('string')
                ->withDepth('string')
        );

$result = $apiClient->set()->coins('{id}')->history()
        ->send(
            $q->withDate('string')
                ->withLocalization('string')
        );

$result = $apiClient->set()->coins('{id}')->marketChart()
        ->send(
            $q->withVsCurrency('string')
                ->withDays('string')
                ->withInterval('string')
        );

$result = $apiClient->set()->coins('{id}')->marketChart()->range()
        ->send(
            $q->withVsCurrency('string')
                ->withFrom('string')
                ->withTo('string')
        );

$result = $apiClient->set()->coins('{id}')->contract('{contract_address}')->send();

$result = $apiClient->set()->coins('{id}')->contract('{contract_address}')->marketChart()
        ->send(
            $q->withVsCurrency('string')
                ->withDays('string')
        );

$result = $apiClient->set()->coins('{id}')->contract('{contract_address}')->marketChart()->range()
        ->send(
            $q->withVsCurrency('string')
                ->withFrom('string')
                ->withTo('string')
        );

$result = $apiClient->set()->coins('{id}')->ohlc()
        ->send(
            $q->withVsCurrency('string')
                ->withDays('string')
        );

$result = $apiClient->set()->assetPlatforms()
        ->send(
            $q->withFilter('string')
        );

$result = $apiClient->set()->coins()->categories()->list()->send();

$result = $apiClient->set()->coins()->categories()
        ->send(
            $q->withOrder('string')
        );

$result = $apiClient->set()->exchanges()
        ->send(
            $q->withPerPage('integer')
                ->withPage('string')
        );

$result = $apiClient->set()->exchanges()->list()->send();

$result = $apiClient->set()->exchanges('{id}')->send();

$result = $apiClient->set()->exchanges('{id}')->tickers()
        ->send(
            $q->withCoinIds('string')
                ->withIncludeExchangeLogo('string')
                ->withPage('integer')
                ->withDepth('string')
                ->withOrder('string')
        );

$result = $apiClient->set()->indexes()
        ->send(
            $q->withPerPage('integer')
                ->withPage('integer')
        );

$result = $apiClient->set()->indexes('{market_id}','{id}')->send();

$result = $apiClient->set()->indexes()->list()->send();

$result = $apiClient->set()->derivatives()
        ->send(
            $q->withIncludeTickers('string')
        );

$result = $apiClient->set()->derivatives()->exchanges()
        ->send(
            $q->withOrder('string')
                ->withPerPage('integer')
                ->withPage('integer')
        );

$result = $apiClient->set()->derivatives()->exchanges('{id}')
        ->send(
            $q->withIncludeTickers('string')
        );

$result = $apiClient->set()->derivatives()->exchanges()->list()->send();

$result = $apiClient->set()->exchanges('{id}')->volumeChart()
        ->send(
            $q->withDays('integer')
        );

$result = $apiClient->set()->nfts()->list()
        ->send(
            $q->withOrder('string')
                ->withAssetPlatformId('string')
                ->withPerPage('integer')
                ->withPage('integer')
        );

$result = $apiClient->set()->nfts('{id}')->send();

$result = $apiClient->set()->nfts('{asset_platform_id}')->contract('{contract_address}')->send();

$result = $apiClient->set()->exchangeRates()->send();

$result = $apiClient->set()->search()
        ->send(
            $q->withQuery('string')
        );

$result = $apiClient->set()->search()->trending()->send();

$result = $apiClient->set()->global()->send();

$result = $apiClient->set()->global()->decentralizedFinanceDefi()->send();

$result = $apiClient->set()->companies()->publicTreasury('{coin_id}')->send();