Skip to content

coinpaprika/coinpaprika-api-php-client

Repository files navigation

Coinpaprika API PHP Client

Coins Bitcoin Price USD

Logo

Latest Stable Version Build Status Software License Quality Score Code Coverage Total Downloads

Usage

This library provides convenient way to use coinpaprika.com API in PHP.

Coinpaprika delivers full market data to the world of crypto: coin prices, volumes, market caps, ATHs, return rates and more.

Requirements

  • PHP >= 8.0
  • (optional) PHPUnit to run tests.

Install

Via Composer:

$ composer require coinpaprika/coinpaprika-api-php-client

Getting started

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

$client = new \Coinpaprika\Client();
$coins = $client->getCoins();

From $client object, you can access all the endpoints.

Cache usage

For deserialization process it is advised to initiate the $client with $cacheDir argument.

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

$client = new \Coinpaprika\Client(cacheDir: 'my/cache/directory');
$coins = $client->getTickers();

Paid API

Pass the API key as the first constructor argument (or use setApiKey() after construction). The client will automatically route requests to api-pro.coinpaprika.com.

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

$client = new \Coinpaprika\Client('PROVIDED_API_KEY');
$coins = $client->getCoins();

API Coverage

$client = new \Coinpaprika\Client();

Market Data

$client->getGlobalStats();                    // Global market overview
$client->getCoins();                          // List all coins
$client->getTokenMeta('btc-bitcoin');         // Coin details
$client->getTickers();                        // All tickers
$client->getTickerByCoinId('btc-bitcoin');    // Ticker for coin
$client->getHistoricalTickerByCoinId('btc-bitcoin', '2024-01-01', '24h'); // Historical

OHLCV

$client->getOHLCV('btc-bitcoin', '24h');                         // Latest OHLCV
$client->getTodayOHLCV('btc-bitcoin');                           // Today's OHLCV
$client->getHistoricalOHLCV('btc-bitcoin', '2024-01-01');        // Historical OHLCV

Exchanges

$client->getExchanges();                             // ExchangeDetail[]
$client->getExchangeById('binance');                 // ExchangeDetail
$client->getExchangeMarkets('binance');              // array (raw)

Coins

$client->getCoinTwitter('btc-bitcoin');              // array (raw)
$client->getCoinEvents('btc-bitcoin');               // array (raw)
$client->getCoinExchanges('btc-bitcoin');            // array (raw)
$client->getCoinMarkets('btc-bitcoin');              // Market[]
$client->getCoinsMappings();                         // array (raw, Pro)

Contracts

$client->getPlatforms();                                          // List platforms
$client->getContracts('eth-ethereum');                            // Contracts on Ethereum
$client->getTickerByContract('eth-ethereum', '0xdac1...');        // Ticker by contract
$client->getHistoricalByContract('eth-ethereum', '0xdac1...', ['start' => '2024-01-01']);

Other

$client->search('bitcoin');                          // Search
$client->priceConverter(['base_currency_id' => 'btc-bitcoin', 'quote_currency_id' => 'usd-us-dollars', 'amount' => 1]);
$client->getPersonById('vitalik-buterin');            // array (raw)
$client->getTags();                                   // array (raw)
$client->getTagById('blockchain-service');             // array (raw)
$client->getKeyInfo();                                // KeyInfo (requires API key)
$client->getCoinsMappings();                          // CoinMapping[] (Business+)
$client->getChangelogIds();                           // ChangelogEntry[] (paid plans)
$client->getIcos();                                   // Ico[]

Return types

Endpoints come in two flavors:

  • Typed — returned as JMS-deserialized model classes under Coinpaprika\Model\*. Covers the bulk of the surface: GlobalStats, Ticker, HistoricalTicker, Coin, CoinMeta, OHLCV, Ico, Search, Market, ExchangeDetail, KeyInfo, CoinMapping, ChangelogEntry.
  • Raw array — auxiliary endpoints whose shape is easier to work with as a plain decoded-JSON blob (Twitter timelines, events, tags, contracts, price converter, etc.). The Coinpaprika API reference is the source of truth for those shapes.

Examples

Check out the ./examples directory. For a quick end-to-end sanity run against the live API:

php examples/smokeTest.php                 # free API
API_KEY=xxx php examples/smokeTest.php     # Pro API

Load/latency profiling:

STRESS_ITERATIONS=100 php examples/stressTest.php              # ~10s at default 100ms delay
STRESS_ITERATIONS=500 STRESS_DELAY_MS=50 php examples/stressTest.php
API_KEY=xxx STRESS_ITERATIONS=1000 php examples/stressTest.php # Pro bypasses rate limits

Changelog

See CHANGELOG.md for release notes and migration guidance.

License

CoinpaprikaAPI is available under the MIT license. See the LICENSE file for more info.

Packages

 
 
 

Contributors

Languages