PHP code example of npabisz / coingecko-api
1. Go to this page and download the library: Download npabisz/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/ */
npabisz / coingecko-api example snippets
use CoinGecko\Client;
// Basic usage
$client = new Client();
// Modify underlying HTTP client config
$client = new Client([], [
'timeout' => 15,
])
// Use PRO api
$client = new Client([
'api_mode' => 'pro',
'api_key' => '************',
]);
$response = $client->Ping->get();
// [/ping]
$response = $client->Ping->get();
// [/simple/price]
$response = $client->Simple->Price->get([
'ids' => 'bitcoin',
'vs_currencies' => 'usd',
]);
// [/simple/token_price/{id}]
$response = $client->Simple->TokenPrice('ethereum')->get([
'contract_addresses' => '0xdac17f958d2ee523a2206206994597c13d831ec7',
'vs_currencies' => 'usd',
]);
// [/simple/supported_vs_currencies]
$response = $client->Simple->SupportedVsCurrencies->get()
// [/coins/list]
$response = $client->Coins->List->get();
// [/coins/markets]
$response = $client->Coins->Markets->get([
'vs_currency' => 'usd',
]);
// [/coins/{id}]
$response = $client->Coins('bitcoin')->get();
// [/coins/{id}/tickers]
$response = $client->Coins('bitcoin')->Tickers->get();
// [/coins/{id}/history]
$response = $client->Coins('bitcoin')->History->get([
'date' => '30-11-2022'
]);
// [/coins/{id}/market_chart]
$response = $client->Coins('bitcoin')->MarketChart->get([
'vs_currency' => 'usd',
'days' => 7,
]);
// [/coins/{id}/market_chart/range]
$response = $client->Coins('bitcoin')->MarketChart->Range->get([
'vs_currency' => 'usd',
'from' => 1669676400,
'to' => 1669762800,
]);
// [/coins/{id}/ohlc]
$response = $client->Coins('bitcoin')->Ohlc->get([
'vs_currency' => 'usd',
'days' => 7,
]);
// [/coins/{id}/contract/{contract_address}]
$response = $client->Coins('ethereum')->Contract('0xdac17f958d2ee523a2206206994597c13d831ec7')->get();
// [/coins/{id}/contract/{contract_address}/market_chart]
$response = $client->Coins('ethereum')->Contract('0xdac17f958d2ee523a2206206994597c13d831ec7')->MarketChart->get([
'vs_currency' => 'usd',
'days' => 7,
]);
// [/coins/{id}/contract/{contract_address}/market_chart/range]
$response = $client->Coins('ethereum')->Contract('0xdac17f958d2ee523a2206206994597c13d831ec7')->MarketChart->Range->get([
'vs_currency' => 'usd',
'from' => 1669676400,
'to' => 1669762800,
]);
// [/assets_platforms]
$response = $client->AssetPlatforms->get();
// [/coins/categories]
$response = $client->Coins->Categories->get();
// [/coins/categories/list]
$response = $client->Coins->Categories->List->get();
// [/exchanges]
$response = $client->Exchanges->get();
// [/exchanges/list]
$response = $client->Exchanges->List->get();
// [/exchanges/{id}]
$response = $client->Exchanges('binance')->get();
// [/exchanges/{id}/tickers]
$response = $client->Exchanges('binance')->Tickers->get();
// [/exchanges/{id}/volume_chart]
$response = $client->Exchanges('binance')->VolumeChart->get([
'days' => 7,
]);
// [/indexes]
$response = $client->Indexes->get();
// [/indexes/{market_id}/{id}]
$response = $client->Indexes($marketId, $id)->get();
// [/indexes/list]
$response = $client->Indexes->List->get();
// [/derivatives]
$response = $client->Derivatives->get();
// [/derivatives/exchanges]
$response = $client->Derivatives->Exchanges->get();
// [/derivatives/exchanges/list]
$response = $client->Derivatives->Exchanges()->List->get();
// [/derivatives/exchanges/{id}]
$response = $client->Derivatives->Exchanges('binance_futures')->get();
// [/nfts/list]
$response = $client->Nfts->List->get();
// [/nfts/{id}]
$response = $client->Nfts('8bit')->get();
// [/nfts/{asset_platform_id}/contract/{contract_address}]
$response = $client->Nfts('ethereum')->Contract('0xaae71bbbaa359be0d81d5cbc9b1e88a8b7c58a94')->get();
// [/exchange_rates]
$response = $client->ExchangeRates->get();
// [/search]
$response = $client->Search->get([
'query' => 'bitcoin',
]);
// [/search/trending]
$response = $client->Search->Trending->get();
// [/global]
$response = $client->Global->get();
// [/global/decentralized_finance_defi]
$response = $client->Global->DecentralizedFinanceDefi->get();
// [/companies/public_treasury/{coin_id}]
$response = $client->Companies->PublicTreasury('ethereum')->get();
// [/nfts/markets]
$response = $client->Nfts->Markets->get();
// [/nfts/{id}/market_chart]
$response = $client->Nfts('8bit')->MarketChart->get();
// [/nfts/{id}/tickers]
$response = $client->Nfts('8bit')->Tickers->get();
// [/global/market_cap_chart]
$response = $client->Global->MarketCapChart->get();