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:
15
src/index.ts
15
src/index.ts
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user