From adcae1cbc8b2ddcebeab7fc9624ec66d694f4c53 Mon Sep 17 00:00:00 2001 From: Wizzard Date: Thu, 14 Mar 2024 01:24:32 -0400 Subject: [PATCH] Add more stats to embed --- main.js | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 366e7cd..a4266ce 100644 --- a/main.js +++ b/main.js @@ -96,22 +96,41 @@ function updateEnvValue(key, value) { function createStatsEmbed(tokenData = {}) { const formatNumber = (num) => new Intl.NumberFormat().format(num); + const formatPercentage = (num) => `${num.toFixed(2)}%`; const marketCapFormatted = tokenData.marketCap ? `$${formatNumber(tokenData.marketCap)}` : 'N/A'; const priceFormatted = tokenData.price ? `$${formatNumber(tokenData.price)}` : '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() .setTitle(`${tokenData.name} $${tokenData.symbol} Token Stats`) .setURL(`https://dexscreener.com/solana/${currentToken}`) - .setColor('#0099ff') + .setColor(`#${randomColor}`) + .setThumbnail(tokenData.imageUrl) .addFields( { 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: '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; } @@ -255,19 +274,25 @@ const checkStatusAndUpdateOBS = async () => { const tokenData = { name: pair.baseToken.name, + imageUrl: pair.info.imageUrl, symbol: pair.baseToken.symbol, marketCap: pair.fdv, price: pair.priceUsd, liquidity: pair.liquidity.usd, 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; 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 24 Hours): ${pair.priceChange.h24}%`); + console.log('Making Money:', tokenData.profitStatus); setSourceVisibility("TextGreen", tokenData.profitStatus);