Download the PHP package cointokio/coingecko-api-client without Composer
On this page you can find all versions of the php package cointokio/coingecko-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cointokio/coingecko-api-client
More information about cointokio/coingecko-api-client
Files in cointokio/coingecko-api-client
Package coingecko-api-client
Short Description Fetch data from the CoinGecko API, intended for use in WordPress plugins or themes.
License GPL-2.0-or-later
Homepage https://github.com/cointokio/coingecko-api-client
Informations about the package coingecko-api-client
CoinGecko API Client for WordPress
A PHP client for fetching data from the CoinGecko API intended to be used in WordPress plugins or themes. Being a good WordPress citizen, this client uses the WordPress core HTTP API to fetch its data.
Installation
This package is available on packagist.org and can be added as a dependency to your project via Composer.
composer require cointokio/coingecko-api-client
Use
Include the main class-client.php file and create an instance of the Client class and use its methods to fetch data from the CoinGecko API. Each method represents a separate API endpoint and will either return a list of response data or a WP_Error object. Note that access to the CoinGecko API requires an API key.
API key
There are two ways to supply your CoinGecko API key:
- Pass the API key into the
Clientconstructor (shown below). The client stores this value and passes it to each request class. - Define the PHP constant
COINGECKO_API_KEY. Endpoint classes extendRequest, which reads that constant when the key string passed fromClientis empty—sonew Cointokio\CoinGecko\Client()with no arguments still works if the constant is defined before you call any API methods.
API endpoint
CoinGecko exposes two hosts so the host must be selected explicitly:
- Demo (free):
https://api.coingecko.com/api/v3, authenticated withx-cg-demo-api-key. - Pro (paid):
https://pro-api.coingecko.com/api/v3, authenticated withx-cg-pro-api-key.
The client defaults to the Demo host. If you have a Pro key, point the client at the Pro host so it switches to the x-cg-pro-api-key header automatically:
As with the API key, the endpoint can also be supplied via a constant (COINGECKO_API_ENDPOINT) so new Cointokio\CoinGecko\Client() with no arguments works.
The auth header is only attached when the configured host is one of the two recognised CoinGecko hosts. Pointing the client at any other host (e.g. a local mock) deliberately suppresses the key header so credentials cannot leak to a third-party server.
Example — demo key, default host
Example — pro key, paid host
The following example uses the $client->coins()->get_markets() method to fetch data from CoinGecko's /coins/markets endpoint. Note that access to the CoinGecko API requires an API key.
Coding Standards
This project aims to adhere to the VIP Coding Standards.