Skip to content

Commit a54eb3b

Browse files
committed
fix: prevent duplicate liquidation events by cleaning up old listeners on bot restart
1 parent 6411dca commit a54eb3b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/bot/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,14 @@ logErrorWithTimestamp('⚠️ Position Manager failed to start:', error.message
461461
logWithTimestamp('ℹ️ Tranche Management disabled for all symbols');
462462
}
463463

464-
// Initialize Hunter
465-
this.hunter = new Hunter(this.config, this.isHedgeMode);
464+
// Initialize Hunter (or reuse existing instance to prevent duplicate listeners)
465+
if (!this.hunter) {
466+
this.hunter = new Hunter(this.config, this.isHedgeMode);
467+
} else {
468+
// Remove all old listeners before re-attaching to prevent duplicates
469+
this.hunter.removeAllListeners();
470+
console.log('[Bot] Removed all old hunter event listeners to prevent duplicates');
471+
}
466472

467473
// Inject status broadcaster for order events
468474
this.hunter.setStatusBroadcaster(this.statusBroadcaster);
@@ -492,6 +498,9 @@ logErrorWithTimestamp('⚠️ Position Manager failed to start:', error.message
492498
this.statusBroadcaster.logActivity(`Blocked: ${data.symbol} ${data.side} - ${data.blockType}`);
493499
});
494500

501+
// Remove old threshold monitor listeners to prevent duplicates
502+
thresholdMonitor.removeAllListeners('thresholdUpdate');
503+
495504
// Listen for threshold updates and broadcast to UI
496505
thresholdMonitor.on('thresholdUpdate', (thresholdUpdate: any) => {
497506
this.statusBroadcaster.broadcastThresholdUpdate(thresholdUpdate);

0 commit comments

Comments
 (0)