I am trying to read JSON formatted prices from: https://poloniex.com/public?command=returnTicker
what I need are two things: symbol names (like BTC_BBR, BTC_BCN, etc) and "highestBid" price for them. To read the ladder I use something like this:
$polo_price = file_get_contents('https://poloniex.com/public?command=returnTicker');
$polo = json_decode($polo_price, true);
$symbol[1] = $polo['BTC_BBR']['highestBid'];
But i need to use symbol name to read it. The symbols disapear and are being added from time to time, so I need to do this more automatically. How can I read symbol names into an array, so the result are:
symbol_name[0] = "BTC_BBR";
symbol_name[1] = "BTC_BCN";
and so on.
Try this:
<?php
$polo_price = file_get_contents('https://poloniex.com/public?command=returnTicker');
$polo = json_decode($polo_price, true);
foreach ($polo as $symbol=>$array){
$symbols[]=$symbol;
$highestBids[] = $array['highestBid'];
}
print_r($symbols);
print_r($highestBids);
<?php
function findHighestBid()
{
$result = [];
$url = "https://poloniex.com/public?command=returnTicker";
$json_data = file_get_contents($url);
$array_data = json_decode($json_data, true);
foreach ($array_data as $currncy_option => $value) {
$result[$currncy_option] = $value["highestBid"];
}
return $result;
}
print_r(findHighestBid());
It will automatically get the highest bid for all the currency option in the json data and also set currency as the key //output
Array
(
[BTC_BBR] => 0.00026283
[BTC_BCN] => 0.00000005
[BTC_BELA] => 0.00002100
[BTC_BITS] => 0.00000892
[BTC_BLK] => 0.00003480
[BTC_BTCD] => 0.00615298
Like this ....