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:
21
src/index.ts
21
src/index.ts
@@ -11,20 +11,17 @@ logger.info('bot initialized');
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
while(true) {
|
while(true) {
|
||||||
logger.info('starting trading cycle');
|
try {
|
||||||
await bot.runDay();
|
logger.info('starting trading cycle');
|
||||||
logger.info('trading cycle complete, sleeping 1h');
|
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
|
await wait(1000 * 60 * 60);//wait an hour before going and getting the next open
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//run main
|
//run main
|
||||||
main().then(
|
main();
|
||||||
() => {
|
|
||||||
logger.info("done")
|
|
||||||
}
|
|
||||||
).catch(
|
|
||||||
(e) => logger.error('Error: ', e)
|
|
||||||
).finally(
|
|
||||||
() => process.exit(0)
|
|
||||||
);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user