Attempt to fix 6 & 1 day timers
This commit is contained in:
parent
7cc8d7b16a
commit
3b794d89ef
25
main.js
25
main.js
|
@ -46,18 +46,29 @@ async function fetchSolanaPrice() {
|
|||
}
|
||||
}
|
||||
|
||||
function pruneOldData() {
|
||||
|
||||
const sixHoursInMilliseconds = 6 * 60 * 60 * 1000;
|
||||
const oneDayInMilliseconds = 24 * 60 * 60 * 1000;
|
||||
const cutoffTime6Hours = Date.now() - sixHoursInMilliseconds;
|
||||
const cutoffTime1Day = Date.now() - oneDayInMilliseconds;
|
||||
|
||||
priceHistory.prices = priceHistory.prices.filter(pricePoint => pricePoint.time > cutoffTime1Day);
|
||||
|
||||
if (priceHistory.prices.length < 360) {
|
||||
console.warn("Warning: Not enough data points for accurate 6-hour calculations.");
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchSolanaPriceAndUpdateHistory() {
|
||||
const currentPrice = await fetchSolanaPrice();
|
||||
if (currentPrice) {
|
||||
pruneOldData();
|
||||
|
||||
priceHistory.prices.push({ time: Date.now(), price: currentPrice });
|
||||
priceHistory.currentPrice = currentPrice;
|
||||
priceHistory.prices.push({ time: Date.now(), price: currentPrice });
|
||||
priceHistory.currentPrice = currentPrice;
|
||||
|
||||
if (priceHistory.prices.length > 61) {
|
||||
priceHistory.prices.shift();
|
||||
}
|
||||
|
||||
saveSolanaData(priceHistory);
|
||||
saveSolanaData(priceHistory);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue