Price change fix up
This commit is contained in:
parent
adcae1cbc8
commit
43fbf39b89
21
main.js
21
main.js
|
@ -106,17 +106,22 @@ function createStatsEmbed(tokenData = {}) {
|
|||
const priceChange24hrFormatted = tokenData.priceChange24hr ? formatPercentage(tokenData.priceChange24hr) : 'N/A';
|
||||
|
||||
const calculateDollarChange = (price, percentageChange) => {
|
||||
if (price && percentageChange) {
|
||||
const dollarChange = (parseFloat(percentageChange) / 100) * parseFloat(price);
|
||||
return `$${parseFloat(dollarChange).toFixed(8)}`;
|
||||
}
|
||||
return 'N/A';
|
||||
if (price && percentageChange) {
|
||||
let dollarChange = (parseFloat(percentageChange) / 100) * parseFloat(price);
|
||||
if (dollarChange < 0) {
|
||||
return `-$${Math.abs(parseFloat(dollarChange)).toFixed(8)}`;
|
||||
} else {
|
||||
return `$${parseFloat(dollarChange).toFixed(8)}`;
|
||||
}
|
||||
}
|
||||
return 'N/A';
|
||||
};
|
||||
|
||||
const dollarChange1hr = calculateDollarChange(tokenData.price, tokenData.priceChange1hr);
|
||||
const dollarChange24hr = calculateDollarChange(tokenData.price, tokenData.priceChange24hr);
|
||||
const dollarChange5m = calculateDollarChange(tokenData.price, tokenData.priceChange5m);
|
||||
|
||||
const randomColor = Math.floor(Math.random() * 16777215).toString(16);
|
||||
const randomColor = Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0');
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`${tokenData.name} $${tokenData.symbol} Token Stats`)
|
||||
|
@ -128,7 +133,7 @@ function createStatsEmbed(tokenData = {}) {
|
|||
{ name: 'Price (USD)', value: priceFormatted, inline: true },
|
||||
{ name: 'Liquidity (USD)', value: liquidityFormatted, inline: true },
|
||||
{ name: 'Status', value: tokenData.profitStatus ? 'Making Money 📈💰' : 'Losing Money 📉😡', inline: false },
|
||||
{ name: 'Price Change (5 M)', value: `${priceChange5mFormatted} (${calculateDollarChange(tokenData.price, tokenData.priceChange)})`, inline: true },
|
||||
{ name: 'Price Change (5 M)', value: `${priceChange5mFormatted} (${dollarChange5m})`, inline: true },
|
||||
{ name: 'Price Change (1 H)', value: `${priceChange1hrFormatted} (${dollarChange1hr})`, inline: true },
|
||||
{ name: 'Price Change (24 H)', value: `${priceChange24hrFormatted} (${dollarChange24hr})`, inline: true }
|
||||
);
|
||||
|
@ -280,7 +285,7 @@ const checkStatusAndUpdateOBS = async () => {
|
|||
price: pair.priceUsd,
|
||||
liquidity: pair.liquidity.usd,
|
||||
profitStatus: pair.priceChange.m5 > 0,
|
||||
priceChange: pair.priceChange.m5,
|
||||
priceChange5m: pair.priceChange.m5,
|
||||
priceChange1hr: pair.priceChange.h1,
|
||||
priceChange24hr: pair.priceChange.h24
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue