Move error handling inside main loop to survive bad cycles

A failed trading cycle (e.g. sell rejected after close) previously
propagated to the top-level .catch() and process.exit(0), killing
the container permanently. Now errors are caught per-iteration so
the bot sleeps and retries on the next cycle.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jon
2026-02-10 19:49:23 -07:00
parent 23e5437402
commit e8b05c7870

View File

@@ -11,20 +11,17 @@ logger.info('bot initialized');
async function main() {
while(true) {
try {
logger.info('starting trading cycle');
await bot.runDay();
logger.info('trading cycle complete, sleeping 1h');
} catch (e) {
logger.error('trading cycle failed: ', e);
logger.info('sleeping 1h before retrying');
}
await wait(1000 * 60 * 60);//wait an hour before going and getting the next open
}
}
//run main
main().then(
() => {
logger.info("done")
}
).catch(
(e) => logger.error('Error: ', e)
).finally(
() => process.exit(0)
);
main();