[insert_php]
$myCoins = array(
‘BTC’ => array ( ‘balance’ => 0.00000169),
‘ETH’ => array ( ‘balance’ => 2 ),
‘BCH’ => array ( ‘balance’ => 1.6228 ),
‘OMG’ => array ( ‘balance’ => 433.52064613208 ),
‘XRP’ => array ( ‘balance’ => 3200 ),
‘ZRX’ => array ( ‘balance’ => 16774.558936502 ),
‘FUN’ => array ( ‘balance’ => 29162.29529845 ),
‘XLM’ => array ( ‘balance’ => 28999 ),
‘DTR’ => array ( ‘balance’ => 95744 ),
‘DNT’ => array ( ‘balance’ => 16483.59689007 ),
‘COB’ => array ( ‘balance’ => 574.71 ),
‘BNT’ => array ( ‘balance’ => 527.28344482 ),
‘ICN’ => array ( ‘balance’ => 2958.20814 ),
‘ETN’ => array ( ‘balance’ => 79200 ),
‘UTNP’ => array ( ‘balance’ => 100000 ),
‘RDN’ => array ( ‘balance’ => 3394.7 ),
);
// ok now hit the api…
$coinbasePublicAPI = ‘https://api.coinmarketcap.com/v1/ticker/?convert=$curr&limit=0’;
$coinData = file_get_contents($coinbasePublicAPI);
$coinData = json_decode($coinData, true);
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
$numCoinbaseCoins = sizeof ($coinData);
$portfolioValue = 0;
for ( $xx=0; $xx<$numCoinbaseCoins; $xx++) { // this part compares your coins to the data… $thisCoinSymbol = $coinData[$xx][‘symbol’]; // if you have it, this var is true… $coinHeld = array_key_exists($thisCoinSymbol, $myCoins); // comment the next line out & you will see ALL of the coins // returned (not just the ones you own): if ( !$coinHeld ) { continue; } echo ‘
‘;
// name:
echo ‘
‘;
// symbol:
echo ‘
‘;
echo ‘
‘;
// price:
$thisCoinPrice = $coinData[$xx][‘price_usd’];
echo ‘
‘;
// holdings:
echo ‘
‘;
// track running total value of coins:
if ($coinHeld) {
$myBalance_USD = $myBalance_units * $thisCoinPrice;
$portfolioValue += $myBalance_USD;
}
// value:
echo ‘
‘;
// 1h market change:
echo ‘
‘;
// 24h market change:
echo ‘
‘;
// 7d market change:
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
}
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
NAME | SYMBOL | RANK | PRICE | HOLDINGS | VALUE | 1hr | 24hr | 7day | Market Cap |
‘ . $coinData[$xx][‘name’] .’ | ‘ . $thisCoinSymbol .’ | ‘ . $coinData[$xx][‘rank’] .’ | $’ . number_format($thisCoinPrice,2) .’ | ‘; if ($coinHeld) { $myBalance_units = $myCoins[$thisCoinSymbol][‘balance’]; echo number_format($myBalance_units,10); } echo ‘ |
$’. number_format($myBalance_USD,2) .’ | ‘ . $coinData[$xx][‘percent_change_1h’] .’% | ‘ . $coinData[$xx][‘percent_change_24h’] .’% | ‘ . $coinData[$xx][‘percent_change_7d’] .’% | $’. $coinData[$xx][‘market_cap_usd’] .’ |
TOTAL | $’ . number_format($portfolioValue,2) . ‘ |
‘;
[/insert_php]