debug: Add comprehensive logging to Position Manager checkTradeConditions (Bug #77 recurrence)
CRITICAL INVESTIGATION (Dec 15, 2025): - Monitoring loop runs every 2s: "🔍 Price check: SOL-PERP @ $124.47 (1 trades)" ✓ - But NO condition checks execute: No TP1/TP2/SL detection, no executeExit calls ❌ - Impact: ,000+ losses - 96% data loss ($32.98 actual vs $1.23 recorded) Added debug logging: - STARTCHK: Function entry (price, entry, check count) - DRIFT: Position size and existence from Drift API - AGE: Trade age in seconds vs 30s threshold Purpose: Identify WHERE checkTradeConditions() returns early before reaching condition checks at line 1497+ Hypothesis: Either Drift returns size=0 OR trade age check fails, causing early return at line 711
This commit is contained in:
@@ -688,6 +688,9 @@ export class PositionManager {
|
||||
trade.lastUpdateTime = Date.now()
|
||||
trade.priceCheckCount++
|
||||
|
||||
// BUG #77 RECURRENCE FIX (Dec 15, 2025): CRITICAL debugging to find why condition checks never execute
|
||||
console.log(`🔍 STARTCHK: ${trade.symbol} @ $${currentPrice.toFixed(2)} | Entry: $${trade.entryPrice.toFixed(2)} | Checks: ${trade.priceCheckCount}`)
|
||||
|
||||
// CRITICAL: First check if on-chain position still exists
|
||||
// (may have been closed by TP/SL orders without us knowing)
|
||||
try {
|
||||
@@ -700,8 +703,11 @@ export class PositionManager {
|
||||
const marketConfig = getMarketConfig(trade.symbol)
|
||||
const position = await driftService.getPosition(marketConfig.driftMarketIndex)
|
||||
|
||||
console.log(`🔍 DRIFT: Position ${trade.symbol} | size=${position?.size || 'null'} | exists=${position !== null}`)
|
||||
|
||||
// Calculate trade age in seconds
|
||||
const tradeAgeSeconds = (Date.now() - trade.entryTime) / 1000
|
||||
console.log(`🔍 AGE: ${trade.symbol} age=${tradeAgeSeconds.toFixed(1)}s | threshold=30s`)
|
||||
|
||||
if (position === null || position.size === 0) {
|
||||
// IMPORTANT: Skip "external closure" detection for NEW trades (<30 seconds old)
|
||||
|
||||
Reference in New Issue
Block a user