cointokio/coinmarketcap-api-client

Fetch data from the CoinMarketCap API, intended for use in WordPress plugins or themes.

Maintainers

Package info

github.com/cointokio/coinmarketcap-api-client

pkg:composer/cointokio/coinmarketcap-api-client

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-24 10:37 UTC

This package is auto-updated.

Last update: 2026-05-24 18:41:43 UTC


README

A PHP client for fetching data from the CoinMarketCap Pro Cryptocurrency API endpoint 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.

Note that this package only covers the Cryptocurrency endpoint family, with the addition of the Key Info endpoint for use as a health probe.

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 CoinMarketCap API. Each method maps to one of the Implemented endpoints listed above and will either return the decoded response body as an array or a WP_Error object. Note that access to the CoinMarketCap API requires an API key.

require_once '/your/cool/path/to/coinmarketcap-client/class-client.php';

/*
 * There are two ways the Client class can use your CoinMarketCap API key:
 *
 * - Pass the API key to the Client class directly like in the example below.
 * - Define a global COINMARKETCAP_API_KEY constant.
 */
$client = new Cointokio\CoinMarketCap\Client( 'your-api-key' );

/*
 * Use the key()->get_info() method to inspect the configured API key
 * (does not consume call credits).
 *
 * @see https://pro.coinmarketcap.com/api/documentation/pro-api-reference/tools/key-info
 */
$response = $client->key()->get_info();

The following example uses the $client->cryptocurrency()->quotes_latest() method to fetch data from the /v3/cryptocurrency/quotes/latest endpoint.

require_once '/your/cool/path/to/coinmarketcap-client/class-client.php';

$client = new Cointokio\CoinMarketCap\Client( 'your-api-key' );

/*
 * Get the latest market quote for one or more cryptocurrencies. The
 * `convert` argument bundles multiple fiat conversions into a single call.
 *
 * @see https://pro.coinmarketcap.com/api/documentation/pro-api-reference/cryptocurrency/cryptocurrency-quotes-latest
 *
 * Note that the $client->cryptocurrency() method returns an instance of the
 * \Cointokio\CoinMarketCap\Cryptocurrency class. This allows us to use the
 * Cryptocurrency class methods more easily via method chaining, eg.:
 *
 * $client->cryptocurrency()->quotes_latest()
 *
 * @see https://en.wikipedia.org/wiki/Method_chaining
 */
$response = $client->cryptocurrency()->quotes_latest( '1,1027', 'USD,EUR' );

convert limit

Every CoinMarketCap plan caps the number of convert values accepted per quotes/latest request, with the free Basic plan capped at one. Bundling more than the per-plan cap into a single call is rejected with a 400 ("Your plan is limited to N convert options"), surfaced by the client as WP_Error( 'http_400', ... ). To stay portable across plan tiers, issue one quotes_latest() request per fiat:

foreach ( $fiats as $fiat ) {
    $response = $client->cryptocurrency()->quotes_latest( $ids_csv, $fiat );
    // Aggregate per-fiat responses into your own structure.
}

Coding Standards

This project aims to adhere to the VIP Coding Standards.