Fix not saving ath correctly

This commit is contained in:
Wizzard 2024-11-25 07:40:52 -05:00
parent 97527e461c
commit ecdc61460a
1 changed files with 24 additions and 8 deletions

24
main.js
View File

@ -29,17 +29,33 @@ function initializeDatabase() {
value TEXT NOT NULL
)`);
db.run('CREATE INDEX IF NOT EXISTS idx_timestamp ON price_history(timestamp)');
db.run('CREATE INDEX IF NOT EXISTS idx_timestamp ON price_history(timestamp)', [], (err) => {
if (err) {
console.error('Error creating index:', err);
} else {
initializeBotState();
}
});
});
}
db.run('INSERT OR REPLACE INTO bot_state (key, value) VALUES (?, ?)',
function initializeBotState() {
db.get('SELECT value FROM bot_state WHERE key = ?', ['lastAnnouncedPrice'], (err, row) => {
if (err) {
console.error('Error checking lastAnnouncedPrice:', err);
} else if (!row) {
db.run('INSERT INTO bot_state (key, value) VALUES (?, ?)',
['lastAnnouncedPrice', '195'],
(err) => {
if (err) console.error('Error setting initial price:', err);
else console.log('Initial price set successfully');
if (err) console.error('Error setting initial lastAnnouncedPrice:', err);
else console.log('Initial lastAnnouncedPrice set to 195');
}
);
} else {
console.log('lastAnnouncedPrice already initialized to', row.value);
}
});
}
async function fetchSolanaPrice() {
try {