Hello guys!, I was looking for a way to get the prices of $HIVE and $HBD via API in PHP for my startup https://cubees.xyz.
I never found anything (maybe I don't ask in the right place, but isn't matter now). Then I found a way to do it with a Simple Request link from the cryptocompare.com API.
But I don't have many skills on development and the response became in a nested array ({"USD":0.5599}) that I needed to decode. So, I tried and tried, and finally I achieve it.
So, if someone were looking for something similar, they can try this code:
<?php
$url_hive = 'https://min-api.cryptocompare.com/data/price?fsym=HIVE&tsyms=USD'; //URL with a request
$url_hbd = 'https://min-api.cryptocompare.com/data/price?fsym=HBD&tsyms=USD';
$hiveprice = json_decode(file_get_contents($url_hive), true); //Decoding returned json object
$hbdprice = json_decode(file_get_contents($url_hbd), true);
foreach($hiveprice as $a){ //Saving the array nested info to a variable
echo ''.'HIVE: '.''.'$';
print_r($a);
echo '';
echo ' ';
}
foreach($hbdprice as $b){
echo ''.'HBD: '.''.'$';
print_r($b);
}
echo '';
?>
OUTPUT
HIVE: https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=usd
HBD: https://api.coingecko.com/api/v3/simple/price?ids=hive_dollar&vs_currencies=usd
I know there are many ways to do this with plug-ins, frameworks, etc. But maybe it can help someone.
;)