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,040 points
29 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 10, 2018 in Blockchain by Perry
59 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,040 points
250 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
• 16,450 points
65 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
• 27,620 points
24 views
0 votes
1 answer

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

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
42 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
61 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
• 27,620 points
49 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,040 points
752 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
• 65,820 points
67 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.