File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments