Files
trading_bot_v4/lib
mindesbunister 9e78761648 critical: Bug #82 LONG-TERM FIX - Comprehensive position verification
REPLACES emergency disable with intelligent verification:

1. Position Identity Verification:
   - Compares DB exitTime vs active trade timestamps
   - Verifies size matches within 15% tolerance
   - Verifies direction matches (long/short)
   - Checks entry price matches within 2%

2. Grace Period Enforcement:
   - 10-minute wait after DB exit before attempting close
   - Allows Drift state propagation

3. Safety Checks:
   - Cooldown (5 min) prevents retry loops
   - Protection logging when position skipped
   - Fail-open bias: when uncertain, do nothing

4. Test Coverage:
   - 8 test scenarios covering active position protection
   - Verified ghost closure tests
   - Edge case handling tests
   - Fail-open bias validation

Files:
- lib/monitoring/drift-state-verifier.ts (276 lines added)
- tests/integration/drift-state-verifier/position-verification.test.ts (420 lines)

User can now rely on automatic orphan cleanup without risk of
accidentally closing active positions. System protects newer trades
when old database records exist for same symbol.

Deployed: Dec 10, 2025 ~11:25 CET
2025-12-10 11:58:27 +01:00
..