Fix not saving ath correctly
This commit is contained in:
parent
97527e461c
commit
ecdc61460a
32
main.js
32
main.js
|
@ -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 (?, ?)',
|
||||
['lastAnnouncedPrice', '195'],
|
||||
(err) => {
|
||||
if (err) console.error('Error setting initial price:', err);
|
||||
else console.log('Initial price set successfully');
|
||||
}
|
||||
);
|
||||
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 lastAnnouncedPrice:', err);
|
||||
else console.log('Initial lastAnnouncedPrice set to 195');
|
||||
}
|
||||
);
|
||||
} else {
|
||||
console.log('lastAnnouncedPrice already initialized to', row.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchSolanaPrice() {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue