Skip to content

Instantly share code, notes, and snippets.

@jashmenn
Created January 15, 2021 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jashmenn/2fe6db05d8617e98ae590dac28e68732 to your computer and use it in GitHub Desktop.
Save jashmenn/2fe6db05d8617e98ae590dac28e68732 to your computer and use it in GitHub Desktop.
const fs = require("fs");
const CoinGecko = require("coingecko-api");
const { table } = require("table");
const chalk = require("chalk");
const cg = new CoinGecko();
const coins = [
{ "id": "ethereum", "symbol": "ETH" },
{ "id": "bitcoin", "symbol": "BTC" },
{ "id": "chainlink", "symbol": "LINK" },
{ "id": "havven", "symbol": "SNX" },
{ "id": "aave", "symbol": "AAVE" },
{ "id": "uniswap", "symbol": "UNI" },
{ "id": "maker", "symbol": "MKR" },
{ "id": "yearn-finance", "symbol": "YFI" },
{ "id": "compound-governance-token", "symbol": "COMP" },
{ "id": "sushi", "symbol": "SUSHI" },
{ "id": "uma", "symbol": "UMA" },
{ "id": "loopring", "symbol": "LRC" },
{ "id": "republic-protocol", "symbol": "REN" },
{ "id": "thorchain", "symbol": "RUNE" },
{ "id": "the-graph", "symbol": "GRT" },
{ "id": "terra-luna", "symbol": "LUNA" },
{ "id": "0x", "symbol": "ZRX" },
{ "id": "reserve-rights-token", "symbol": "RSR" },
{ "id": "nxm", "symbol": "NXM" },
{ "id": "kyber-network", "symbol": "KNC" },
{ "id": "band-protocol", "symbol": "BAND" },
{ "id": "balancer", "symbol": "BAL" },
{ "id": "gnosis", "symbol": "GNO" },
{ "id": "bancor", "symbol": "BNT" },
{ "id": "curve-dao-token", "symbol": "CRV" },
{ "id": "1inch", "symbol": "1INCH" },
{ "id": "augur", "symbol": "REP" },
{ "id": "hegic", "symbol": "HEGIC" },
{ "id": "serum", "symbol": "SRM" },
{ "id": "kava", "symbol": "KAVA" },
{ "id": "alpha-finance", "symbol": "ALPHA" },
{ "id": "harvest-finance", "symbol": "FARM" },
{ "id": "badger-dao", "symbol": "BADGER" },
{ "id": "keep-network", "symbol": "KEEP" },
{ "id": "meta", "symbol": "MTA" },
{ "id": "dmm-governance", "symbol": "DMG" },
{ "id": "pickle-finance", "symbol": "PICKLE" },
{ "id": "dodo", "symbol": "DODO" },
{ "id": "synlev", "symbol": "SYN" },
{ "id": "cream-2", "symbol": "CREAM" },
{ "id": "dhedge-dao", "symbol": "DPI" }
];
const main = async (coins) => {
var prices = [];
var total = 0;
for ( var i = 0; i < coins.length; i++ ) {
// These ones are not yet 90 days old
if ( [ "GRT", "REP", "1INCH", "ALPHA", "BADGER", "SYN" ].indexOf(coins[i].symbol) > -1 ) continue;
else total += 1;
prices[i] = {
"symbol": coins[i].symbol,
"price-today": parseFloat((await cg.coins.fetch(coins[i].id, {}))["data"]["market_data"]["current_price"]["usd"]),
"price-90d": parseFloat((await cg.coins.fetchHistory(coins[i].id, { date: '16-10-2020' }))["data"]["market_data"]["current_price"]["usd"])
};
prices[i]["multiple"] = (prices[i]["price-today"] / prices[i]["price-90d"]);
}
var ethMultiple = prices[0].multiple;
prices.sort((a, b) => {
if (a.multiple > b.multiple) return -1;
else if (a.multiple < b.multiple) return 1;
else {
if (a.symbol == "ETH") return 1;
else return -1;
}
});
var pricesFormatted = [
[ chalk.bold("symbol"), chalk.bold("price-90d"), chalk.bold("price-today"), chalk.bold("multiple") ]
];
for ( var i = 0; i < total; i++ ) {
if ( prices[i].symbol == "ETH" ) color = chalk.blue;
else if ( prices[i].symbol == "BTC" ) color = chalk.keyword("orange")
else if (prices[i].multiple > 1.5 * ethMultiple) color = chalk.green;
else if (prices[i].multiple < 0.5 * ethMultiple) color = chalk.bgRed;
else color = chalk.white;
pricesFormatted[i+1] = [
color(prices[i].symbol),
color("$" + prices[i]["price-90d"].toFixed(prices[i]["price-90d"] >= 1 ? 2 : 4)),
color("$" + prices[i]["price-today"].toFixed(prices[i]["price-today"] >= 1 ? 2 : 4)),
color(prices[i].multiple.toFixed(1) + "x")
]
}
return table(pricesFormatted, {
drawHorizontalLine: (index, size) => {
return index === 0 || index === 1 || index === size;
}
});
};
main().then(result => {
console.log("\n" + result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment