Coingecko Cache Update
Coin cache update for Coingecko API Google Spreadsheet Script https://gist.github.com/hesido/c04bab6b8dc9d802e14e53aeb996d4b2
by Emrah BASHER
HTML
<!DOCTYPE html>
<html>
<body>
<h1>CoinGecko API Coin Cache</h1>
<form>
<label for="coinlist">Coin Cache List for script</label>
<textarea id="coinlist" name="coinlist" rows="4" cols="50">
Here will be the javascript code to replace the cache.
</textarea>
<br />
<label for="coinlist">Coin Cache List CSV</label>
<textarea id="coinlistcsv" name="coinlistcsv" rows="4" cols="50">
Here will be the CSV to import into Spreadsheet apps.
</textarea>
<br />
<label for="conflictlist">Conflicting Coins List CSV</label>
<textarea id="conflictlist" name="conflictlist" rows="4" cols="50">Here is the list of coins with conflicting shorthand
</textarea>
<br/>
<p>
<span id="conflictcount"></span>
<br />
<span id="coincount"></span>
<br />
<span id="cachecount"></span>
</p>
</form>
<p>You can copy over the cache line in the <a href="https://gist.github.com/hesido/c04bab6b8dc9d802e14e53aeb996d4b2">Coingecko API script</a>.</p>
<p>
If your coin is in the conflicting coin list, you may have to use the Coingecko id for the pairs instead of shorhand ones. The last coin with the same shorthand currently overwrites the previous.
</p>
</body>
</html>
CSS
label {
display: inline-block;
min-width: 25ch;
}
JavaScript
const data = null;
const xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
let coinList = JSON.parse(this.responseText);
let adaptedList = {};
let conflictCoins = [];
coinList.forEach(coin=>
{
if(adaptedList[coin.symbol.toLowerCase()] != undefined) {
conflictCoins.push([coin.symbol, adaptedList[coin.symbol.toLowerCase()], coin.id]);
}
adaptedList[coin.symbol.toLowerCase()] = coin.id;
}
);
coinlist.textContent = JSON.stringify(adaptedList);
//let textAreaCSV = document.getElementById('coinlistcsv');
let csvText = "Shorthand,Coingecko id\n";
coinList.forEach(coin=>csvText += coin.symbol+","+coin.id+"\n");
coinlistcsv.textContent = csvText;
let conflictText = "Shorthand,Coingecko Id 1,Coingecko Id 2\n";
conflictCoins.forEach(coinflict => conflictText += coinflict[0]+","+coinflict[1]+","+coinflict[2]+"\n");
conflictlist.textContent = conflictText;
conflictcount.textContent = "Number of conflicting entries: " + conflictCoins.length;
coincount.textContent = "Number of total entries from Coingecko: " + coinList.length;
cachecount.textContent = "Number of total entries in cache: " + Object.keys(adaptedList).length;
}
});
xhr.open("GET", "https://api.coingecko.com/api/v3/coins/list");
xhr.send(data);