From e8b05c7870440748c3944f33a9aea91c05a91bc1 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 10 Feb 2026 19:49:23 -0700 Subject: [PATCH] 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 --- src/index.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 21438ec..895c04a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,20 +11,17 @@ logger.info('bot initialized'); async function main() { while(true) { - logger.info('starting trading cycle'); - await bot.runDay(); - logger.info('trading cycle complete, sleeping 1h'); + 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();