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