Add Position Sync feature for recovering tracking after partial fills

- New /api/trading/sync-positions endpoint (no auth)
- Fetches actual Drift positions and compares with Position Manager
- Removes stale tracking, adds missing positions with calculated TP/SL
- Settings UI: Orange 'Sync Positions' button added
- CLI script: scripts/sync-positions.sh for terminal access
- Full documentation in docs/guides/POSITION_SYNC_GUIDE.md
- Quick reference: POSITION_SYNC_QUICK_REF.md
- Updated AI instructions with pitfall #23

Problem solved: Manual Telegram trades with partial fills can cause
Position Manager to lose tracking, leaving positions without software-
based stop loss protection. This feature restores dual-layer protection.

Note: Docker build not picking up route yet (cache issue), needs investigation
This commit is contained in:
mindesbunister
2025-11-10 17:05:32 +01:00
parent 2e47731e8e
commit 089308a07e
6 changed files with 440 additions and 0 deletions

12
scripts/sync-positions.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
#
# Sync Position Manager with actual Drift positions
# Useful when things get out of sync (partial fills, restarts, manual trades)
#
source /home/icke/traderv4/.env
curl -X POST http://localhost:3001/api/trading/sync-positions \
-H "Authorization: Bearer ${API_SECRET_KEY}" \
-H "Content-Type: application/json" \
| jq '.'