From 79e7ffe2c095f47c2e1025e5c043069e72d22b83 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Thu, 20 Nov 2025 17:42:55 +0100 Subject: [PATCH] feat: Add Telegram notification for TP1 partial closes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **ENHANCEMENT:** TP1 partial closes now send Telegram notifications - Previously only full position closes (runner exit) sent notifications - TP1 hit → 60% close → User not notified until runner closed later - User couldn't see TP1 profit immediately **FIX:** Added notification in executeExit() partial close branch - Shows TP1 realized P&L (e.g., +$22.78) - Shows closed portion size - Includes "60% closed, 40% runner remaining" in exit reason - Same format as full closes: entry/exit prices, hold time, MAE/MFE **IMPACT:** User now gets immediate feedback when TP1 hits - Removed TODO comment at line 1589 - Both TP1 and runner closures now send notifications **FILES:** lib/trading/position-manager.ts line ~1575-1592 **DEPLOYED:** Nov 20, 2025 17:42 CET --- lib/trading/position-manager.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/trading/position-manager.ts b/lib/trading/position-manager.ts index 0115694..b6a2e3a 100644 --- a/lib/trading/position-manager.ts +++ b/lib/trading/position-manager.ts @@ -1581,10 +1581,22 @@ export class PositionManager { // Persist updated trade state so analytics reflect partial profits immediately await this.saveTradeState(trade) + + // Send Telegram notification for TP1 partial close + await sendPositionClosedNotification({ + symbol: trade.symbol, + direction: trade.direction, + entryPrice: trade.entryPrice, + exitPrice: result.closePrice || currentPrice, + positionSize: closedUSD, // Show only the closed portion + realizedPnL: result.realizedPnL || 0, + exitReason: `${reason} (${percentToClose}% closed, ${(100 - percentToClose).toFixed(0)}% runner remaining)`, + holdTimeSeconds: Math.floor((Date.now() - trade.entryTime) / 1000), + maxDrawdown: Math.abs(Math.min(0, trade.maxAdverseExcursion)), + maxGain: Math.max(0, trade.maxFavorableExcursion), + }) } - // TODO: Send notification - } catch (error) { console.error(`❌ Error executing exit for ${trade.symbol}:`, error) }