docs: Document Nov 19 critical findings - database/Drift mismatch and P&L inflation
- Database shows only 3 v8 trades when Drift UI shows 6 trades - One trade has 10x inflated P&L (81 vs 9 expected) - Bot receiving ZERO API requests after 06:51 restart despite n8n executions succeeding - Real v8 performance: ~2 LOSS (from Drift), database shows 20 profit (WRONG) - Two issues: P&L compounding bug still active + n8n→bot connection broken - Need to verify n8n workflow endpoints and fix external closure P&L calculation - Common Pitfall #50 added to copilot-instructions.md
This commit is contained in:
33
.github/copilot-instructions.md
vendored
33
.github/copilot-instructions.md
vendored
@@ -2317,6 +2317,39 @@ trade.realizedPnL += actualRealizedPnL // NOT: result.realizedPnL from SDK
|
||||
* This bug (#49): P&L compounding in external closure detection (fixed by not mutating trade.realizedPnL)
|
||||
- **Lesson:** In monitoring loops that run repeatedly, NEVER mutate shared state during calculation phases. Calculate locally, update shared state ONCE at the end. Immutability prevents compounding bugs in retry/race scenarios.
|
||||
|
||||
50. **Database not tracking trades despite successful Drift executions (CRITICAL - Nov 19, 2025):**
|
||||
- **Symptom:** Drift UI shows 6 trades executed in last 6 hours, database shows only 1 trade, bot logs show NO API requests
|
||||
- **Root Cause:** Bot container restarted at 06:51 UTC, but trades executed BEFORE restart (00:20-05:56) weren't fully saved
|
||||
- **Evidence:**
|
||||
* n8n executions: 08:15, 06:45, 05:35, 01:45, 01:20 (all succeeded)
|
||||
* Drift trades: 6 trades showing P&L from $18.42 to -$99.93 (total ~-$52 loss)
|
||||
* Database: Only 3 v8 trades, with one showing $581 profit (10× inflated)
|
||||
* Bot logs: ZERO API requests after 06:51 restart
|
||||
- **Two Separate Issues:**
|
||||
1. **Historical trades (before restart):** Database P&L values are inflated due to P&L compounding bug (Common Pitfall #49)
|
||||
- One SHORT trade shows $581 profit in DB
|
||||
- Actual: $138.88 → $137.74 = 0.82% move × $7232 position = **$59 expected**
|
||||
- Inflated by ~10× due to P&L accumulation during external closure detection
|
||||
2. **Recent trades (after restart):** Bot NOT receiving signals from n8n at all
|
||||
- n8n shows successful executions at 08:15, 06:45
|
||||
- Bot logs show ZERO incoming requests
|
||||
- API is accessible (returns 401 on auth test)
|
||||
- **Conclusion:** n8n is calling a DIFFERENT endpoint or the workflow changed
|
||||
- **Impact:**
|
||||
* Cannot trust database P&L values for v8 trades
|
||||
* System appears to be "working" in n8n but bot isn't actually trading
|
||||
* Analytics dashboard showing completely wrong performance metrics
|
||||
- **Temporary Status:**
|
||||
* Real v8 performance: ~$52 LOSS (from Drift UI)
|
||||
* Database shows: $420 profit (WRONG - includes inflated $581 trade)
|
||||
* Need to fix: P&L compounding bug + n8n→bot connection
|
||||
- **Next Steps:**
|
||||
1. Verify n8n workflow URLs point to correct bot endpoint
|
||||
2. Fix P&L compounding in external closure detection (Common Pitfall #49 fix didn't work)
|
||||
3. Correct historical database records with actual Drift transaction data
|
||||
4. Add API request logging to catch silent failures
|
||||
- **Lesson:** Always cross-reference database records with exchange UI after system changes. Container restarts can expose silent failures in the execution pipeline.
|
||||
|
||||
46. **100% position sizing causes InsufficientCollateral (Fixed Nov 16, 2025):**
|
||||
- **Symptom:** Bot configured for 100% position size gets InsufficientCollateral errors, but Drift UI can open same size position
|
||||
- **Root Cause:** Drift's margin calculation includes fees, slippage buffers, and rounding - exact 100% leaves no room
|
||||
|
||||
Reference in New Issue
Block a user