Coder Social home page Coder Social logo

cmc-api-php's Introduction

CoinMarketCap API Wrapper

codecov Build Status

This php package is a wrapper for the coinmarketcap.com API. It supports three endpoints:

  • The ticker endpoint "/ticker", which returns all crypto currencies, and their vital statistics like price, volume, market cap and percentage changes
  • The currency ticker endpoint "/ticker/", which returns all the data in the previous endpoint, except for only the specified coin.
  • The global data endpoint "/global", which returns some stats like the total market cap, active currencies, active markets and so on.

Install

composer require cointokenhub/cmc-api-php

Usage

In a PHP app:

use GuzzleHttp\Client;
use CoinTokenHub\CoinMarketCapApi\CoinMarketCap;

$httpClient = new Client();
$cmcApi = new CoinMarketCap($httpClient);


$api->ticker('AUD', false, 5);
$api->currencyTicker($coin);
$api->globalData();

In Laravel:

Add a route to routes/web.php that looks like below:

Route::get('coin/{coin}', 'CoinController@coin');
Route::get('ticker', 'CoinController@ticker');
Route::get('global_data', 'CoinController@globalData');

Controller looks like below:

<?php

namespace App\Http\Controllers;

use GuzzleHttp\Client;
use CoinTokenHub\CoinMarketCapApi\CoinMarketCap;

class CoinController extends Controller
{
	private $httpClient;

	public function __construct(Client $httpClient) {
		$this->httpClient = $httpClient;
	}

    public function coin($coin) {
		$api = new CoinMarketCap($this->httpClient);
		return json_encode($api->currencyTicker($coin));
    }

    public function ticker() {
	    $api = new CoinMarketCap($this->httpClient);
	    return json_encode($api->ticker('AUD', false, 5));
    }

    public function globalData() {
	    $api = new CoinMarketCap($this->httpClient);
	    return json_encode($api->globalData());
    }
}

Configuring for Laravel

Laravel 5.5 and higher

You don't need to change or add any config as this package uses Package Auto Discovery.

Laravel 5.4 and lower

After installing, register the CoinTokenHub\CoinMarketCapApi\CoinMarketCapServiceProvider service provider in your config/app.php file.

'providers' => [
    // Other service providers...

    CoinTokenHub\CoinMarketCapApi\CoinMarketCapServiceProvider::class,
],

Also add the facade to your aliases array in the config/app.php file in order to easily access this wrapper using the CoinMarketCap alias

'CoinMarketCap' => CoinTokenHub\CoinMarketCapApi\CoinMarketCapFacade::class,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.