CRITICAL BUG: Position Manager was using current price to determine exit reason, but on-chain orders filled at a DIFFERENT price in the past! Example: LONG entry $184.55, TP1 filled at $184.66, but when Position Manager checked later (price dropped), it saw currentPrice < TP1 and defaulted to 'SL' Result: Profitable trades incorrectly labeled as SL exits in database Fix: - Use trade.tp1Hit and trade.tp2Hit flags to determine exit reason - If no TP flags set, use realized P&L to distinguish: - Profit >0.5% = TP1 filled - Negative P&L = SL filled - Remove duplicate P&L calculation This ensures exit reasons match actual on-chain order fills
33 KiB
33 KiB