CoinMarketCap en utilisant l'API de CoinGecko

dev_blockchain
a répondu

document.addEventListener("DOMContentLoaded", () => { const tableBody = document.querySelector("tbody");

1// Replace with your CoinGecko API endpoint to get the top 500 cryptocurrencies
3
4fetch(apiUrl)
5 .then((response) => response.json())
6 .then((data) => {
7 data.forEach((crypto, index) => {
8 const row = document.createElement("tr");
9 row.innerHTML = `
10 <td>${crypto.market_cap_rank}</td>
11 <td><img src="${crypto.image}" alt="${crypto.name}" width="30" height="30"></td>
12 <td>${crypto.name}</td>
13 <td>${crypto.symbol.toUpperCase()}</td>
14 <td>${crypto.current_price.toFixed(2)}</td>
15 <td>${crypto.market_cap.toLocaleString()}</td>
16 <td class="${crypto.price_change_percentage_24h >= 0 ? 'positive' : 'negative'}">${crypto.price_change_percentage_24h.toFixed(2)}</td>
17 `;
18 tableBody.appendChild(row);
19 });
20 })
21 .catch((error) => {
22 console.error("Error fetching data:", error);
23 });
1// Replace with your CoinGecko API endpoint to get the top 500 cryptocurrencies
3
4fetch(apiUrl)
5 .then((response) => response.json())
6 .then((data) => {
7 data.forEach((crypto, index) => {
8 const row = document.createElement("tr");
9 row.innerHTML = `
10 <td>${crypto.market_cap_rank}</td>
11 <td><img src="${crypto.image}" alt="${crypto.name}" width="30" height="30"></td>
12 <td>${crypto.name}</td>
13 <td>${crypto.symbol.toUpperCase()}</td>
14 <td>${crypto.current_price.toFixed(2)}</td>
15 <td>${crypto.market_cap.toLocaleString()}</td>
16 <td class="${crypto.price_change_percentage_24h >= 0 ? 'positive' : 'negative'}">${crypto.price_change_percentage_24h.toFixed(2)}</td>
17 `;
18 tableBody.appendChild(row);
19 });
20 })
21 .catch((error) => {
22 console.error("Error fetching data:", error);
23 });

});

Confirmer la suppression

Êtes-vous sûr de vouloir supprimer cette réponse ? Cette action est irréversible.

Jery123MU
a répondu

Salut Avez-vous déjà résolut cette erreur ?

Confirmer la suppression

Êtes-vous sûr de vouloir supprimer cette réponse ? Cette action est irréversible.

Il faut Se connecter ou Créer un compte pour participer à cette conversation.

Confirmer la suppression

Êtes-vous sûr de vouloir supprimer ce sujet ? Cette action est irréversible.