jopanel / cryptocompare-api-php-wrapper

Php wrapper class based on guzzle to query the cryptocompare.com api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cryptocompare-api-php-wrapper

1.) Installation

the easiest way to get started is to use composer to retrieve the files.

prepare composer inside your project folder

The following commands will download the pre compiled composer.phar, which will download the project for us.

cd ~/Projectfolder
wget https://getcomposer.org/composer.phar

create composer.json or add to your existing composer.json

minimal composer.json

{
  "require": {
    "loeken/cryptocompare-api-php-wrapper": "dev-master"
  }
}

single line to add composer.json

    "loeken/cryptocompare-api-php-wrapper": "dev-master",

make composer update from github/packagist

php composer.phar update

short explanation of composer

composer retrieves the last version of the code from github and downloads it to the vendor/* folder inside your project. It will also generate a autoload.php which you can then load inside your php code, this will then load all classes included in this project. This is also usefull if you want to update our api wrapper to the last version, simply run the composer update command again.

including our classes in your files

if your .php script file is in the same folder as the vendor folder, use the following line, else adjust the path.

<?php
require_once('vendor/autoload.php');

create object of class

There are currently 3 available classes under the namespaces \Cryptocompare\CryptocompareApi, \Cryptocompare\Price and \Cryptocompare\Coin.

The first can be used to get info about the api, the second one will display info about crypto prices/conversions.

$cryptocompareApi = new Cryptocompare\CryptocompareApi();

$cryptocomparePrice = new Cryptocompare\Price();

$cryptocompareCoin = new Cryptocompare\Coin();

$cryptocompareMarket = new Cryptocompare\Market();

Cryptocompare\CryptocompareApi

get all available calls

$example1 = $cryptocompareApi->getAvailableCalls();

get rate limits for your IP

$example2 = $cryptocompareApi->getRateLimits();

get mining contracts

$example3 = $cryptocompareApi->getMiningContracts();

get mining equipment

$example4 = $cryptocompareApi->getMiningEquipment();

get news providers

$example5 = $cryptocompareApi->getNewsProviders();

get news

$example6 = $cryptocompareApi->getNews("ALL_NEWS_FEEDS", false, "EN",false);

Cryptocompare\Price

convert a currency to an array of other currencies

$example1 = $cryptocomparePrice->getSinglePrice("1","BTC",array("USD", "EUR"),"CCCAGG","false");

convert an array of currencies to another array of currencies

$example2 = $cryptocomparePrice->getMultiPrice("1",array("BTC","ETH"),array("USD","EUR","ETH"),"CCCAGG","false");

convert an a currency to another array of currencies at a specific point in time

$example3 = $cryptocomparePrice->getHistoricalPrice("1", "BTC", array("USD","EUR"), "1507469305", "CCCAGG", false);

convert an array of currencies to another array of currencies and get full trading information

$example4 = $cryptocomparePrice->getMultiPriceFull("1", array("BTC","ETH"), array("USD","EUR"),"CCCAGG", false);

get trading information for a currency pair on specific markets as aggregated information

$example5 = $cryptocomparePrice->getGenerateAvg("1", "BTC", "EUR", "Coinbase,Kraken",false);

get open/high/low/close at a specific point in time

$example6 = $cryptocomparePrice->getDayAvg("1", "BTC", "EUR", "CCCAGG", "HourVWAP", 0, "1487116800", false);

get information required for streaming

$example7 = $cryptocomparePrice->getSubsWatchlist("1", array("BTC", "ETH"), "EUR", "CCCAGG",false);

get all streamer subscription channels for the requested pair

$example8 = $cryptocomparePrice->getSubs("1", "BTC", array("USD", "EUR"), "CCCAGG", false);

get all historical data for minute

$example9 = $cryptocompareCoin->getHistoMinute(1,"BTC", "EUR","CCCAGG", false, 1, 1440, NULL);

get all historical data for hour

$example10 = $cryptocompareCoin->getHistoHour(1,"BTC", "EUR","CCCAGG", false, 1, 1440, NULL);

get all historical data for day

$example11 = $cryptocompareCoin->getHistoDay(1,"BTC", "EUR","CCCAGG", false, 1, 1440, NULL);

Cryptocompare\Coin

get all coins

$example1 = $cryptocompareCoin->getList();

get top pairs

$example2 = $cryptocompareCoin->getTopPairs("BTC", "EUR", 5, false);

get snapshot

$example3 = $cryptocompareCoin->getSnapshot("BTC", "EUR");

get snapshot by coin id ( get id from ->getList() )

$example4 = $cryptocompareCoin->getSnapshotFullById(1182);

get social stats by coin id ( get id from ->getList() )

$example5 = $cryptocompareCoin->getSocialStats(1182);

Cryptocompare\Market

get top pairs

$example1 = $cryptocompareMarket->getTopPairs("BTC", 5,false );

get top exchanges

$example1 = $cryptocompareMarket->getTopExchanges("BTC", "EUR", 5, false);

get top volumes

$example1 = $cryptocompareMarket->getTopVolumes("EUR", 20, false);

get all markets

$example1 = $cryptocompareMarket->getList(false);

full working code example

<?php
require_once('vendor/autoload.php');

$cryptocompareApi = new Cryptocompare\CryptocompareApi();
$example1 = $cryptocompareApi->getAvailableCalls();
print_r($example1);

$cryptocomparePrice = new Cryptocompare\Price();
$example2 = $cryptocomparePrice->getSinglePrice("1","BTC","USD","CCCAGG","false");
print_r($example2);


$cryptocompareCoin = new Cryptocompare\Coin();
$example3 = $cryptocompareCoin->getList();
print_r($example3);

?>

About

Php wrapper class based on guzzle to query the cryptocompare.com api


Languages

Language:PHP 100.0%