Price change fix up

This commit is contained in:
Wizzard 2024-03-14 01:37:43 -04:00
parent adcae1cbc8
commit 43fbf39b89
1 changed files with 13 additions and 8 deletions

21
main.js
View File

@ -106,17 +106,22 @@ function createStatsEmbed(tokenData = {}) {
const priceChange24hrFormatted = tokenData.priceChange24hr ? formatPercentage(tokenData.priceChange24hr) : 'N/A'; const priceChange24hrFormatted = tokenData.priceChange24hr ? formatPercentage(tokenData.priceChange24hr) : 'N/A';
const calculateDollarChange = (price, percentageChange) => { const calculateDollarChange = (price, percentageChange) => {
if (price && percentageChange) { if (price && percentageChange) {
const dollarChange = (parseFloat(percentageChange) / 100) * parseFloat(price); let dollarChange = (parseFloat(percentageChange) / 100) * parseFloat(price);
return `$${parseFloat(dollarChange).toFixed(8)}`; if (dollarChange < 0) {
} return `-$${Math.abs(parseFloat(dollarChange)).toFixed(8)}`;
return 'N/A'; } else {
return `$${parseFloat(dollarChange).toFixed(8)}`;
}
}
return 'N/A';
}; };
const dollarChange1hr = calculateDollarChange(tokenData.price, tokenData.priceChange1hr); const dollarChange1hr = calculateDollarChange(tokenData.price, tokenData.priceChange1hr);
const dollarChange24hr = calculateDollarChange(tokenData.price, tokenData.priceChange24hr); 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() const embed = new EmbedBuilder()
.setTitle(`${tokenData.name} $${tokenData.symbol} Token Stats`) .setTitle(`${tokenData.name} $${tokenData.symbol} Token Stats`)
@ -128,7 +133,7 @@ function createStatsEmbed(tokenData = {}) {
{ name: 'Price (USD)', value: priceFormatted, inline: true }, { name: 'Price (USD)', value: priceFormatted, inline: true },
{ name: 'Liquidity (USD)', value: liquidityFormatted, inline: true }, { name: 'Liquidity (USD)', value: liquidityFormatted, inline: true },
{ name: 'Status', value: tokenData.profitStatus ? 'Making Money 📈💰' : 'Losing Money 📉😡', inline: false }, { 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 (1 H)', value: `${priceChange1hrFormatted} (${dollarChange1hr})`, inline: true },
{ name: 'Price Change (24 H)', value: `${priceChange24hrFormatted} (${dollarChange24hr})`, inline: true } { name: 'Price Change (24 H)', value: `${priceChange24hrFormatted} (${dollarChange24hr})`, inline: true }
); );
@ -280,7 +285,7 @@ const checkStatusAndUpdateOBS = async () => {
price: pair.priceUsd, price: pair.priceUsd,
liquidity: pair.liquidity.usd, liquidity: pair.liquidity.usd,
profitStatus: pair.priceChange.m5 > 0, profitStatus: pair.priceChange.m5 > 0,
priceChange: pair.priceChange.m5, priceChange5m: pair.priceChange.m5,
priceChange1hr: pair.priceChange.h1, priceChange1hr: pair.priceChange.h1,
priceChange24hr: pair.priceChange.h24 priceChange24hr: pair.priceChange.h24
}; };