Finding BitCoin current price and status in PHP (CoinDesk)

Posted By: Matpal Media - 9:38 AM
CoinDesk provides a REST API for bitcoin price. In this example I am showing how we can call CoinDesk API through PHP. CoinDesk returns a JSON as response.
<?php

$url="https://api.coindesk.com/v1/bpi/currentprice/BTC.json";
$ch = curl_init();


curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);
curl_close($ch);

echo $result;

?>
Following is the output as JSON
{"time":{"updated":"Mar 9, 2018 17:25:00 UTC","updatedISO":"2018-03-09T17:25:00+00:00",
"updateduk":"Mar 9, 2018 at 17:25 GMT"},
"disclaimer":"This data was produced from the CoinDesk Bitcoin Price Index (USD). 
Non-USD currency data converted using hourly conversion rate from openexchangerates.org",
"bpi":{"USD":{"code":"USD","rate":"8,823.5550","description":"United States Dollar",
"rate_float":8823.555},"BTC":{"code":"BTC","rate":"1.0000","description":"Bitcoin","rate_float":1}}}

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.