I am new to code, I am trying to pull certain JSON API with PHP. In this case it is ETH_USD. Below is a snippet of the API.
{"symbol":"ETH_USD","volumen24hours":398.18320159,"ask":235.9,"bid":212.50000001,"lastPrice":213.48283633},{"symbol":"ETH_EUR","volumen24hours":101.79246082,"ask":191.51196436,"bid":191.51196436,"lastPrice":191.51196436},{"symbol":"ETH_ARS","volumen24hours":56.42036715,"ask":9365.12240119,"bid":8952,"lastPrice":9365.12240119},
Below is my php code until now. How do I just get the ETH_USD data? Any help is appreciated.
<?php
$url = "https://www.website.com/api/ticker?format=json";
$fgc = file_get_contents($ur);
$json = json_decode($fgc, true);
$price = $json["lastPrice"];
$high = $json["ask"];
$low = $json["bid"];
$open = $json["open"];
if($open < $price){
//price went up
$indicator = "+"
$change = $price - $open;
$percent = $change / $open;
$percent = $percent * 100;
$percentChange = $indicator.number_format($percent, 2);
$color = "green";
}
if($open > $price){
//price went down
$indicator = "-"
$change = $open - $price;
$percent = $change / $open;
$percent = $percent * 100;
$percentChange = $indicator.number_format($percent, 2);
$color = "red";
}
?>