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());
}