PHP json decode - reading category names

0 votes

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.

Sep 7, 2018 in Blockchain by slayer
• 29,370 points
1,231 views

2 answers to this question.

0 votes

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);
answered Sep 7, 2018 by Sunny
0 votes
<?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
answered Sep 7, 2018 by Shotgun

Related Questions In Blockchain

+1 vote
1 answer

How do i change the names of validating peers in IBM Bluemix blockchain?

IBM Bluemix Blockchain service Hyperledger Fabric v0.6 will ...READ MORE

answered Apr 11, 2018 in Blockchain by Perry
964 views
0 votes
1 answer

Php code to generate Ethereum wallets.

You can use web3.eth.accounts in web3js web3.eth.accounts.create(); With Php, ...READ MORE

answered Jul 27, 2018 in Blockchain by slayer
• 29,370 points
3,366 views
0 votes
1 answer

How do I change default service names in Corda Demobench?

Each Corda node individually advertises the services ...READ MORE

answered Aug 14, 2018 in Blockchain by Perry
• 17,100 points
755 views
0 votes
1 answer

How to use bitcoin price as place holder in php?

You can do it by providing an ...READ MORE

answered Aug 21, 2018 in Blockchain by digger
• 26,740 points
913 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,417 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,916 views
0 votes
1 answer

Converting 5e-08 to decimal in PHP

Use printf with the appropriate format specifier: printf("%.8f", 5 / ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
3,261 views
0 votes
2 answers

Does Ethereum Solidity support Associative Arrays?

Here's a little example that passes values ...READ MORE

answered Sep 17, 2018 in Blockchain by Bobin
1,099 views
+2 votes
5 answers

How do I parse this JSON array in PHP?

/** * Firstly collect the ...READ MORE

answered Sep 3, 2018 in Blockchain by slayer
• 29,370 points
6,327 views
0 votes
1 answer

PHP IPC with geth Ethereum: How to communicate with client?

You have to use PHP Sockets $sock = socket_create(AF_UNIX, ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 69,220 points
1,763 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP