- 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
62 lines
1.7 KiB
Markdown
62 lines
1.7 KiB
Markdown
# Position Sync - Quick Reference
|
|
|
|
## 🚨 When to Use
|
|
- Position open on Drift but Position Manager shows 0 trades
|
|
- Database says "closed" but Drift shows position still open
|
|
- After manual Telegram trades with partial fills
|
|
- Bot restart lost in-memory tracking
|
|
- Rate limiting (429 errors) disrupted monitoring
|
|
|
|
## ✅ Three Ways to Sync
|
|
|
|
### 1. Settings UI (Easiest)
|
|
1. Go to http://localhost:3001/settings
|
|
2. Click the orange **"🔄 Sync Positions"** button (next to Restart Bot)
|
|
3. View results in green success message
|
|
|
|
### 2. Terminal Script
|
|
```bash
|
|
cd /home/icke/traderv4
|
|
bash scripts/sync-positions.sh
|
|
```
|
|
|
|
### 3. Direct API Call
|
|
```bash
|
|
source /home/icke/traderv4/.env
|
|
curl -X POST http://localhost:3001/api/trading/sync-positions \
|
|
-H "Authorization: Bearer ${API_SECRET_KEY}"
|
|
```
|
|
|
|
## 📊 What It Does
|
|
|
|
**Fetches** all open positions from Drift (SOL-PERP, BTC-PERP, ETH-PERP)
|
|
|
|
**Compares** against Position Manager's tracked trades
|
|
|
|
**Removes** tracking for positions closed externally
|
|
|
|
**Adds** tracking for unmonitored positions with:
|
|
- Stop loss at configured %
|
|
- TP1/TP2 at configured %
|
|
- Emergency stop protection
|
|
- Trailing stop (if TP2 hit)
|
|
- MAE/MFE tracking
|
|
|
|
**Result**: Dual-layer protection restored ✅
|
|
|
|
## 🎯 Your Current Situation
|
|
|
|
- **Before Sync:** 4.93 SOL SHORT open, NO software protection
|
|
- **After Sync:** Position Manager monitors it every 2s with full TP/SL system
|
|
|
|
## ⚠️ Limitations
|
|
|
|
- Entry time unknown (assumes 1 hour ago - doesn't affect TP/SL)
|
|
- Signal quality metrics missing (only matters for scaling feature)
|
|
- Uses current config (not original config from when trade opened)
|
|
- Synthetic position ID (manual-{timestamp} instead of real TX)
|
|
|
|
## 📖 Full Documentation
|
|
|
|
See: `docs/guides/POSITION_SYNC_GUIDE.md`
|