Price change fix up
This commit is contained in:
parent
adcae1cbc8
commit
43fbf39b89
13
main.js
13
main.js
|
@ -107,16 +107,21 @@ function createStatsEmbed(tokenData = {}) {
|
||||||
|
|
||||||
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);
|
||||||
|
if (dollarChange < 0) {
|
||||||
|
return `-$${Math.abs(parseFloat(dollarChange)).toFixed(8)}`;
|
||||||
|
} else {
|
||||||
return `$${parseFloat(dollarChange).toFixed(8)}`;
|
return `$${parseFloat(dollarChange).toFixed(8)}`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 'N/A';
|
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
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue