Created
January 30, 2018 13:18
-
-
Save lele85/a5c9154986c37780985b313b3b71e1b8 to your computer and use it in GitHub Desktop.
CryptoCheck.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v8.9.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cardano": 400, | |
"siacoin": 1245, | |
"zencash": 95, | |
"bitcoin": 0.03 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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