You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

const fetch = require('isomorphic-fetch');
const getData = async endpoint => fetch(
`https://whattomine.com/${endpoint}.json`
).then(res => res.json());
const getCoinData = async () => {
const [gpu, asic] = await Promise.all([
getData('coins'),
getData('asic')
]);
const coins = Object.entries({...gpu.coins, ...asic.coins})
.filter(([_, coin]) => coin.tag !== 'NICEHASH')
.map(([name, coin]) => {
return {
symbol: String(coin.tag),
name: String(name),
marketCap: parseFloat(coin.market_cap.replace(/[$,]/g, ''), 10),
price: parseFloat(coin.exchange_rate),
priceCurrency: String(coin.tag === 'BTC' ? 'USD' : coin.exchange_rate_curr),
algorithm: String(coin.algorithm),
hashrate: parseFloat(coin.nethash, 10),
blockTimeInSeconds: parseFloat(coin.block_time, 10),
blockReward: parseFloat(coin.block_reward, 10)
};
})
.sort((a, b) => b.marketCap - a.marketCap);
return coins;
};
module.exports = async (request, response) => response.json(await getCoinData());
2 years ago
module.exports.getCoinData = getCoinData;