PROBLEM (User identified): - Analytics showed 3 open trades when Drift UI showed only 1 position - Database had 3 separate trade records all marked as 'open' - Root cause: Drift has 1 POSITION + 3 ORDERS (TP/SL exit orders) - Validator was incorrectly treating each as separate position SOLUTION: - Group database trades by symbol before validation - If multiple DB trades exist for one Drift position, keep only MOST RECENT - Close older duplicate trades with exitReason='DUPLICATE_CLEANUP' - Properly handles: 1 Drift position → 1 DB trade (correct state) RESULT: - Database: 1 open trade (matches Drift reality) - Analytics: Shows accurate position count - Runs automatically every 10 minutes + manual trigger available
8.3 KiB
8.3 KiB