(function() {
function exchangeDataShow() {
fetch('https://api.coinmarketcap.com/v1/ticker/?limit=20')
.then( (responce) => {
return responce.json();
})
.then( (data) => {
let output = ' ';
data.forEach(coin => {
output += `
<tr>
<td>${coin.rank}</td>
<td>${coin.name}</td>
<td>${coin.price_usd}</td>
<td>${coin.24h_volume_usd}</td>
<td>${coin.market_cap_usd}</td>
<td>${coin.total_supply}</td>
<td>${coin.max_supply}</td>
<td>${coin.percent_change_1h}%</td>
<td>${coin.percent_change_24h}%</td>
<td>${coin.percent_change_7d}%</td>
</tr>
`;
});
document.getElementById('market-data').innerHTML = output;
})
.catch( (err) => {
console.log(err);
});
}
window.onload = exchangeDataShow();
setInterval(() => {
console.log('reload');
exchangeDataShow();
}, 5000);
})();