Skip to content

Instantly share code, notes, and snippets.

@lele85
Created January 30, 2018 13:18
Show Gist options
  • Save lele85/a5c9154986c37780985b313b3b71e1b8 to your computer and use it in GitHub Desktop.
Save lele85/a5c9154986c37780985b313b3b71e1b8 to your computer and use it in GitHub Desktop.
CryptoCheck.js
const request = require("request-promise-native");
const coins = require("./coins");
const logBalance = (results) => {
let total = 0;
console.log("########################");
console.log("### CRYPTOCURRENCIES ###");
console.log("########################")
console.log();
results.forEach(([result]) => {
const currency = result.id;
const balance = coins[currency] * result.price_usd;
console.log(`${currency.toUpperCase()} : $ ${balance.toFixed(2)}`);
total += balance;
});
console.log("---");
console.log(`TOTAL : $ ${total.toFixed(2)}`);
console.log();
}
async function getTicker(currency) {
return request({uri: `https://api.coinmarketcap.com/v1/ticker/${currency}`,json: true});
};
(async function() {
const currencies = Promise.all(Object.keys(coins).map((currency) => getTicker(currency)));
try {
const results = await currencies;
logBalance(results);
} catch (e) {
console.log(e);
}
})();
{
"cardano": 400,
"siacoin": 1245,
"zencash": 95,
"bitcoin": 0.03
}
{
"name": "check",
"version": "1.0.0",
"description": "",
"main": "check.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"request": "^2.83.0",
"request-promise-native": "^1.0.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment