critical: Fix breakeven SL using wrong entry price after TP1
- CRITICAL BUG: Drift SDK's position.entryPrice RECALCULATES after partial closes - After TP1, Drift returns COST BASIS of remaining position, NOT original entry - Example: SHORT @ 38.52 → TP1 @ 70% → Drift shows entry 40.01 (runner's basis) - Result: Breakeven SL set .50 ABOVE actual entry = guaranteed loss if triggered Fix: - Always use database trade.entryPrice for breakeven calculations - Drift's position.entryPrice = current state (runner cost basis) - Database entryPrice = original entry (authoritative for breakeven) - Added logging to show both values for verification Impact: - Every TP1 → breakeven transition was using WRONG price - Locking in losses instead of true breakeven protection - Financial loss bug affecting every trade with TP1 Files: - lib/trading/position-manager.ts: Line 513 - use trade.entryPrice not position.entryPrice - .github/copilot-instructions.md: Added Common Pitfall #43, deprecated old #44 Incident: Nov 16, 02:47 CET - SHORT entry 38.52, breakeven SL set at 40.01 Position closed by ghost detection before SL could trigger (lucky)
This commit is contained in:
Reference in New Issue
Block a user