'How do I access response information from COINGECKO API for coins with more than one word id?
I have 6 crypto coins I'm getting current price from CoinGecko's API
I have spans inside of divs set up on my html page, where the price span html updates after the ajax call.
The call is working for 4/6 coins. I'm using the ID's to call the information. I can call perfectly the price of the coins if they're one word like "metagods", "affyn" but the call fails for multiple worded ID's like "thetan-arena", "dragon-kart-token".
I'm using the ID's CoinGecko provided, is there a proper way to access info for ID's with more than one word? JS code below
let metagodsPrice = document.getElementById("metagodsPrice");
let sidusPrice = document.getElementById("sidusPrice");
let thetanArenaPrice = document.getElementById("thetanArenaPrice");
let affynPrice = document.getElementById("affynPrice");
let splinterlandsPrice = document.getElementById("splinterlandsPrice");
let dragonkartPrice = document.getElementById("dragonkartPrice");
const livePrice = {
"async": true,
"scroosDomain": true,
"url": "https://api.coingecko.com/api/v3/simple/price?ids=metagods%2Csidus%2Cthetan-arena%2Caffyn%2Csplinterlands%2Cdragon-kart-token&vs_currencies=USD&include_market_cap=true&include_24hr_change=true",
"method": "GET",
"headers": {}
}
$.ajax(livePrice).done(function (response) {
console.log(response);
metagodsPrice.innerHTML = response.metagods.usd;
sidusPrice.innerHTML = response.sidus.usd;
affynPrice.innerHTML = response.affyn.usd;
splinterlandsPrice.innerHTML = response.splinterlands.usd;
thetanArenaPrice.innerHTML = response.thetan-arena.usd;
dragonkartPrice.innerHTML = response.dragon-kart-token.usd;
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
