From 59bc267206152926e5ac8cadf584be4f723ff6d8 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Sat, 15 Nov 2025 22:10:41 +0100 Subject: [PATCH] fix: Add runner stop loss protection (CRITICAL) - CRITICAL BUG: Position Manager only checked SL before TP1 - After TP1 hit, runner had NO stop loss protection - Added separate SL check for runner (after TP1, before TP2) - Runner now protected by profit-lock SL on Position Manager Bug discovered: Runner position with no on-chain orders (below min size) AND no software protection (SL check skipped after TP1). Impact: 2.79 runner exposed to unlimited loss for 10+ minutes. Fix: Added line 881-886 runner SL check in monitoring loop. --- lib/trading/position-manager.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/trading/position-manager.ts b/lib/trading/position-manager.ts index adb9bfe..a4077b4 100644 --- a/lib/trading/position-manager.ts +++ b/lib/trading/position-manager.ts @@ -869,13 +869,21 @@ export class PositionManager { return } - // 2. Stop loss + // 2. Stop loss (BEFORE TP1) if (!trade.tp1Hit && this.shouldStopLoss(currentPrice, trade)) { console.log(`🔴 STOP LOSS: ${trade.symbol} at ${profitPercent.toFixed(2)}%`) await this.executeExit(trade, 100, 'SL', currentPrice) return } + // 2b. CRITICAL: Runner stop loss (AFTER TP1, BEFORE TP2) + // This protects the runner position after TP1 closes main position + if (trade.tp1Hit && !trade.tp2Hit && this.shouldStopLoss(currentPrice, trade)) { + console.log(`🔴 RUNNER STOP LOSS: ${trade.symbol} at ${profitPercent.toFixed(2)}% (profit lock triggered)`) + await this.executeExit(trade, 100, 'SL', currentPrice) + return + } + // 3. Take profit 1 (closes configured %) if (!trade.tp1Hit && this.shouldTakeProfit1(currentPrice, trade)) { console.log(`🎉 TP1 HIT: ${trade.symbol} at ${profitPercent.toFixed(2)}%`)