- Part 1: Position Manager fractional remnant detection after close attempts
* Check if position < 1.5× minOrderSize after close transaction
* Log to persistent logger with FRACTIONAL_REMNANT_DETECTED
* Track closeAttempts, limit to 3 maximum
* Mark exitReason='FRACTIONAL_REMNANT' in database
* Remove from monitoring after 3 failed attempts
- Part 2: Pre-close validation in closePosition()
* Check if position viable before attempting close
* Reject positions < 1.5× minOrderSize with specific error
* Prevent wasted transaction attempts on too-small positions
* Return POSITION_TOO_SMALL_TO_CLOSE error with manual instructions
- Part 3: Health monitor detection for fractional remnants
* Query Trade table for FRACTIONAL_REMNANT exits in last 24h
* Alert operators with position details and manual cleanup instructions
* Provide trade IDs, symbols, and Drift UI link
- Database schema: Added closeAttempts Int? field to Track attempts
Root cause: Drift protocol exchange constraints can leave fractional positions
Evidence: 3 close transactions confirmed but 0.15 SOL remnant persisted
Financial impact: ,000+ risk from unprotected fractional positions
Status: Fix implemented, awaiting deployment verification
See: docs/COMMON_PITFALLS.md Bug #89 for complete incident details
Implementation of 1-minute data enhancements Phase 2:
- Queue signals when price not at favorable pullback level
- Monitor every 15s for 0.15-0.5% pullback (LONG=dip, SHORT=bounce)
- Validate ADX hasn't dropped >2 points (trend still strong)
- Timeout at 2 minutes → execute at current price
- Expected improvement: 0.2-0.5% per trade = ,600-4,000 over 100 trades
Files:
- lib/trading/smart-entry-timer.ts (616 lines, zero TS errors)
- app/api/trading/execute/route.ts (integrated smart entry check)
- .env (SMART_ENTRY_* configuration, disabled by default)
Next steps:
- Test with SMART_ENTRY_ENABLED=true in development
- Monitor first 5-10 trades for improvement verification
- Enable in production after successful testing