Add six hour tracker and fix one day tracker

This commit is contained in:
Wizzard 2024-03-14 12:21:25 -04:00
parent faff35fa90
commit 3d21de9bf1
1 changed files with 10 additions and 4 deletions

14
main.js
View File

@ -76,6 +76,7 @@ function immediatePriceCheckAndAnnounce() {
let oneMinChange = { percent: 0, dollar: 0 }; let oneMinChange = { percent: 0, dollar: 0 };
let fiveMinChange = { percent: 0, dollar: 0 }; let fiveMinChange = { percent: 0, dollar: 0 };
let oneHourChange = { percent: 0, dollar: 0 }; let oneHourChange = { percent: 0, dollar: 0 };
let sixHourChange = { percent: 0, dollar: 0 }
let oneDayChange = { percent: 0, dollar: 0 }; let oneDayChange = { percent: 0, dollar: 0 };
const now = Date.now(); const now = Date.now();
@ -111,10 +112,14 @@ function immediatePriceCheckAndAnnounce() {
oneDayChange.dollar = latestPrice - oneDayAgoPrice; 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) { async function sendNewPriceMessage(embed) {
const sentMessage = await solanaPriceChannel.send({ embeds: [embed] }); const sentMessage = await solanaPriceChannel.send({ embeds: [embed] });
@ -132,7 +137,7 @@ async function sendNewPriceMessage(solanaPriceChannel, embed) {
async function checkPriceContinuously() { async function checkPriceContinuously() {
await fetchSolanaPriceAndUpdateHistory(); await fetchSolanaPriceAndUpdateHistory();
const { oneMinChange, fiveMinChange, oneHourChange } = calculateChanges(); const { oneMinChange, fiveMinChange, oneHourChange, sixHourChange, oneDayChange } = calculateChanges();
console.log(`Current Price: ${priceHistory.currentPrice}`); 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: '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: '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: '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 } { name: '1 Day Change', value: `${oneDayChange.percent.toFixed(2)}% (${oneDayChange.dollar.toFixed(2)} USD)`, inline: true }
]) ])
.setTimestamp() .setTimestamp()