0

I am trying to get data from Binance Exchange API (https://api.etherdelta.com/returnTicker). I able to get the data and convert the data into an array. But the whole data is in the key of the first data of the array.

$uri  = "https://api.etherdelta.com/returnTicker";
$data = array();
$ch = curl_init ($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
parse_str(curl_exec($ch), $data);

Sample data:

Array ( [{"ETH_VIBE":{"tokenAddr":"0xe8ff5c9c75deb346acac493c463c8950be03dfba","quoteVolume":2022554_248,"baseVolume":3212_187,"last":0_001659444,"percentChange":3_2991,"bid":5,"ask":0_00163},"ETH_0xc27a":{"tokenAddr":"0xc27a2f05fa577a83ba0fdb4c38443c0718356501","quoteVolume":1379508_983,"baseVolume":1262_329,"last":0_000911962,"percentChange":-0_0685,"bid":0_0009785,"ask":0_00093}])

I wish to access last price of each token(ETH_VIBE).

Thanks in advance!

1 Answers1

0

I think all you need to do is parse it as a json string. Also, you should probably check that curl_exec($ch) actually returned a string and not something unexpected. http://php.net/manual/en/function.json-decode.php http://php.net/manual/en/function.curl-exec.php

<?php
...
// Set 2nd param to TRUE to return an array
$data = json_decode(curl_exec($ch), true);
waterloomatt
  • 3,662
  • 1
  • 19
  • 25