Add more stats to embed

This commit is contained in:
Wizzard 2024-03-14 01:24:32 -04:00
parent 64bdd47aed
commit adcae1cbc8
1 changed files with 30 additions and 5 deletions

35
main.js
View File

@ -96,22 +96,41 @@ function updateEnvValue(key, value) {
function createStatsEmbed(tokenData = {}) { function createStatsEmbed(tokenData = {}) {
const formatNumber = (num) => new Intl.NumberFormat().format(num); const formatNumber = (num) => new Intl.NumberFormat().format(num);
const formatPercentage = (num) => `${num.toFixed(2)}%`;
const marketCapFormatted = tokenData.marketCap ? `$${formatNumber(tokenData.marketCap)}` : 'N/A'; const marketCapFormatted = tokenData.marketCap ? `$${formatNumber(tokenData.marketCap)}` : 'N/A';
const priceFormatted = tokenData.price ? `$${formatNumber(tokenData.price)}` : 'N/A'; const priceFormatted = tokenData.price ? `$${formatNumber(tokenData.price)}` : 'N/A';
const liquidityFormatted = tokenData.liquidity ? `$${formatNumber(tokenData.liquidity)}` : 'N/A'; const liquidityFormatted = tokenData.liquidity ? `$${formatNumber(tokenData.liquidity)}` : 'N/A';
const priceChangeFormatted = tokenData.priceChange ? `${formatNumber(tokenData.priceChange)}%` : 'N/A'; const priceChange5mFormatted = tokenData.priceChange5m ? formatPercentage(tokenData.priceChange5m) : 'N/A';
const priceChange1hrFormatted = tokenData.priceChange1hr ? formatPercentage(tokenData.priceChange1hr) : 'N/A';
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';
};
const dollarChange1hr = calculateDollarChange(tokenData.price, tokenData.priceChange1hr);
const dollarChange24hr = calculateDollarChange(tokenData.price, tokenData.priceChange24hr);
const randomColor = Math.floor(Math.random() * 16777215).toString(16);
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle(`${tokenData.name} $${tokenData.symbol} Token Stats`) .setTitle(`${tokenData.name} $${tokenData.symbol} Token Stats`)
.setURL(`https://dexscreener.com/solana/${currentToken}`) .setURL(`https://dexscreener.com/solana/${currentToken}`)
.setColor('#0099ff') .setColor(`#${randomColor}`)
.setThumbnail(tokenData.imageUrl)
.addFields( .addFields(
{ name: 'Market Cap', value: marketCapFormatted, inline: true }, { name: 'Market Cap', value: marketCapFormatted, inline: true },
{ name: 'Price (USD)', value: `$${tokenData.price || 'N/A'}`, 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 Min)', value: priceChangeFormatted, inline: true } { name: 'Price Change (5 M)', value: `${priceChange5mFormatted} (${calculateDollarChange(tokenData.price, tokenData.priceChange)})`, inline: true },
{ name: 'Price Change (1 H)', value: `${priceChange1hrFormatted} (${dollarChange1hr})`, inline: true },
{ name: 'Price Change (24 H)', value: `${priceChange24hrFormatted} (${dollarChange24hr})`, inline: true }
); );
return embed; return embed;
} }
@ -255,19 +274,25 @@ const checkStatusAndUpdateOBS = async () => {
const tokenData = { const tokenData = {
name: pair.baseToken.name, name: pair.baseToken.name,
imageUrl: pair.info.imageUrl,
symbol: pair.baseToken.symbol, symbol: pair.baseToken.symbol,
marketCap: pair.fdv, marketCap: pair.fdv,
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 priceChange: pair.priceChange.m5,
priceChange1hr: pair.priceChange.h1,
priceChange24hr: pair.priceChange.h24
}; };
obsVisibilityState.makingMoney = tokenData.profitStatus; obsVisibilityState.makingMoney = tokenData.profitStatus;
const priceFormatted = tokenData.price ? `$${parseFloat(tokenData.price).toFixed(8)}` : 'N/A'; const priceFormatted = tokenData.price ? `$${parseFloat(tokenData.price).toFixed(8)}` : 'N/A';
console.log(`Price Change (Last 1 Hour): ${pair.priceChange.h1}%`);
console.log(`Price Change (Last 5 Minutes): ${pair.priceChange.m5}%`); console.log(`Price Change (Last 5 Minutes): ${pair.priceChange.m5}%`);
console.log(`Price Change (Last 24 Hours): ${pair.priceChange.h24}%`);
console.log('Making Money:', tokenData.profitStatus); console.log('Making Money:', tokenData.profitStatus);
setSourceVisibility("TextGreen", tokenData.profitStatus); setSourceVisibility("TextGreen", tokenData.profitStatus);