From 3d21de9bf1f892f9dd79a2a39489aba32f0846ec Mon Sep 17 00:00:00 2001 From: Wizzard Date: Thu, 14 Mar 2024 12:21:25 -0400 Subject: [PATCH] Add six hour tracker and fix one day tracker --- main.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 280f64c..f59cf52 100644 --- a/main.js +++ b/main.js @@ -76,6 +76,7 @@ function immediatePriceCheckAndAnnounce() { let oneMinChange = { percent: 0, dollar: 0 }; let fiveMinChange = { percent: 0, dollar: 0 }; let oneHourChange = { percent: 0, dollar: 0 }; + let sixHourChange = { percent: 0, dollar: 0 } let oneDayChange = { percent: 0, dollar: 0 }; const now = Date.now(); @@ -111,10 +112,14 @@ function immediatePriceCheckAndAnnounce() { oneDayChange.dollar = latestPrice - oneDayAgoPrice; } - return { oneMinChange, fiveMinChange, oneHourChange, oneDayChange }; -} + if (priceHistory.prices.length >= 360) { + const sixHourAgoPrice = parseFloat(findPriceAgo(360).price); + sixHourChange.percent = ((latestPrice - sixHourAgoPrice) / sixHourAgoPrice) * 100; + sixHourChange.dollar = latestPrice - sixHourAgoPrice; + } -const { oneMinChange, fiveMinChange, oneHourChange, oneDayChange } = calculateChanges(); + return { oneMinChange, fiveMinChange, oneHourChange, sixHourChange, oneDayChange }; +} async function sendNewPriceMessage(embed) { const sentMessage = await solanaPriceChannel.send({ embeds: [embed] }); @@ -132,7 +137,7 @@ async function sendNewPriceMessage(solanaPriceChannel, embed) { async function checkPriceContinuously() { await fetchSolanaPriceAndUpdateHistory(); - const { oneMinChange, fiveMinChange, oneHourChange } = calculateChanges(); + const { oneMinChange, fiveMinChange, oneHourChange, sixHourChange, oneDayChange } = calculateChanges(); console.log(`Current Price: ${priceHistory.currentPrice}`); @@ -148,6 +153,7 @@ async function checkPriceContinuously() { { name: '1 Minute Change', value: `${oneMinChange.percent.toFixed(2)}% (${oneMinChange.dollar.toFixed(2)} USD)`, inline: true }, { name: '5 Minute Change', value: `${fiveMinChange.percent.toFixed(2)}% (${fiveMinChange.dollar.toFixed(2)} USD)`, inline: true }, { name: '1 Hour Change', value: `${oneHourChange.percent.toFixed(2)}% (${oneHourChange.dollar.toFixed(2)} USD)`, inline: true }, + { name: '6 Hour Change', value: `${sixHourChange.percent.toFixed(2)}% (${sixHourChange.dollar.toFixed(2)} USD)`, inline: true }, { name: '1 Day Change', value: `${oneDayChange.percent.toFixed(2)}% (${oneDayChange.dollar.toFixed(2)} USD)`, inline: true } ]) .setTimestamp()