-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpriceScript.js
32 lines (30 loc) · 1.01 KB
/
priceScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { ContextMenuCommandBuilder } = require('@discordjs/builders');
const fetch = require('node-fetch');
async function getPrice(coin) {
const response = await fetch(
`https://api.coingecko.com/api/v3/simple/price?ids=${coin}&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true
`
);
const data = await response.json();
// console.log(data);
const formatterCurrency = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
maximumFractionDigits: 2,
});
data[coin].usd = formatterCurrency.format(Math.round(data[coin].usd));
data[coin].usd_market_cap = formatterCurrency.format(
Math.round(parseFloat(data[coin].usd_market_cap))
);
data[coin].usd_24h_vol = formatterCurrency.format(
Math.round(parseFloat(data[coin].usd_24h_vol))
);
data[coin].usd_24h_change = `${Math.round(
parseFloat(data[coin].usd_24h_change)
)}%`;
return data;
}
// getPrice('binancecoin').then((res) => console.log(res));
module.exports = {
getPrice,
};