How to list EXC exchange information via API in PHP?

Asked

Viewed 33 times

0

Using PHP, like listing information from the EXC API, I’m having some difficulties and who can help,

Details: LINK API:

Here’s an example of how I tried to do:

<?php
    $json = file_get_contents("https://trade.exccripto.com/api/v3/public/getticker?market=DCR_BTC");
    $coins = json_decode($json);
?>

<table style="width:100%">
 <tbody>
  <tr>                                                          
   <th>Market</th>
   <th>Bid</th>
   <th>Ask</th>
   <th>Last</th>                                                            
  </tr>                                                       
 <?php foreach ($coins as $coin) { ?>
 <tr>                                                           
  <td><?php echo $coin->Market; ?></td>
  <td><?php echo $coin->Bid; ?></td>
  <td><?php echo $coin->Ask; ?></td>
  <td><?php echo $coin->Last; ?></td>    
 </tr>
<?php } ?>
</tbody>

1 answer

0

In this part of the code you forgot to specify the result where I believe the collection of information:

JSON:

{"success":true,
 "message":"",
 "result":[{
     "Market":"DCR_BTC",
     "Bid":0.00452230,
     "Ask":0.00489226,
     "Last":0.00479230
    }]
}

Example with the change:

<?php foreach ($coins->result as $coin) { ?>
<tr> 
    <td><?php echo $coin->Market; ?></td>
    <td><?php echo $coin->Bid; ?></td>
    <td><?php echo $coin->Ask; ?></td>
    <td><?php echo $coin->Last; ?></td>
</tr>
<?php } ?>

I mean, you weren’t putting the proposed key in the and so could not find the items of his table.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.