Coinmarketcap API v2 for Faucethub.io

  PHP

STEP 1: Function to get real time market price of faucethub coins , add this function in your config.php or function.php files.

function realValueOfCoin($coinname)
  {
    if($coinname == 'BTC')
    {
      $coinnumber = 1;
    }
    else if($coinname == 'LTC')
    {
      $coinnumber = 2;
    }
    else if($coinname == 'DOGE')
    {
      $coinnumber = 74;
    }
    else if($coinname == 'ZEC')
    {
      $coinnumber = 1437;
    }
    else if($coinname == 'BTX')
    {
      $coinnumber = 1654;
    }
    else if($coinname == 'DASH')
    {
      $coinnumber = 131;
    }
    else if($coinname == 'ETH')
    {
      $coinnumber = 1027;
    }
    else if($coinname == 'PPC')
    {
      $coinnumber = 5;
    }
    else if($coinname == 'BLK')
    {
      $coinnumber = 170;
    }
    else if($coinname == 'POT')
    {
      $coinnumber = 122;
    }
    else if($coinname == 'XPM')
    {
      $coinnumber = 42;
    }
    else if($coinname == 'BCH')
    {
      $coinnumber = 1831;
    }
    else if($coinname == 'XMR')
    {
      $coinnumber = 328;
    }	
    else if($coinname == 'DGB')
    {
      $coinnumber = 109;
    }		
    $extract = file_get_contents('https://api.coinmarketcap.com/v2/ticker/'.$coinnumber.'/?convert=BTC');
    $coinarray = json_decode($extract,true);
    $coinarray = $coinarray['data']['quotes'];
    $coinvalueinbtc = $coinarray['BTC']['price'];
    $coinvalueinusd = $coinarray['USD']['price'];
    $returnvalue = $coinvalueinbtc.'+'.$coinvalueinusd;
    return $returnvalue;
  }

 

STEP 2 : Then use this code where you want your price to be used.

#REALVALUE OF LITECOIN FROM COINMARKET#

$ltcvalue = realValueOfCoin('LTC');
$ltcvalue = explode('+',$dogevalue);
$ltcvalueinbtc = $dogevalue[0];
$ltcvalueinusd = $dogevalue[1];

echo 'LTC value in BTC :'.$ltcvalueinbtc.' & LTC value in USD :'.$ltcvalueinusd;

You have any Question or doubt  ? Make comment to get help.

LEAVE A COMMENT


2 + 5 =