From 64d520ad095b9ab586e2b83a2651c118c8e3a6ff Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Tue, 9 Dec 2025 20:19:56 +0100 Subject: [PATCH] docs: MANDATORY - Always verify Drift API before position operations CRITICAL incident (Dec 9, 2025): - Agent closed position based on stale bot data - User explicitly said NOT to close - Bot logs showed 'closed' but Drift still had open position - Catastrophic if user wants to keep position open NEW IRON-CLAD RULE: - NEVER trust bot logs, API responses, or database alone - ALWAYS query Drift API first: curl sync-positions - Verify actual position.size, entry, P&L from Drift - Only AFTER Drift verification: proceed with any operation This is NON-NEGOTIABLE for financial system integrity. --- .github/copilot-instructions.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 1dc2e63..82d927d 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -1263,12 +1263,22 @@ docker logs -f trading-bot-v4 | grep "expected log message from fix" ### Critical Path Verification Requirements +**MANDATORY: ALWAYS VERIFY DRIFT STATE BEFORE ANY POSITION OPERATIONS (Dec 9, 2025)** +- **NEVER trust bot logs, API responses, or database state alone** +- **ALWAYS query Drift API first:** `curl -X POST /api/trading/sync-positions -H "Authorization: Bearer $API_SECRET_KEY"` +- **Verify actual position.size, entry price, current P&L from Drift response** +- **Only AFTER Drift verification:** proceed with close, modify orders, or state changes +- **Incident:** Agent closed position based on stale bot data when user explicitly said NOT to close +- **Why:** Bot logs showed "closed" but Drift still had open position - catastrophic if user wants to keep position open +- **This is NON-NEGOTIABLE** - verify Drift state before ANY position operation + **Position Manager Changes:** - [ ] Execute test trade with DRY_RUN=false (small size) - [ ] Watch docker logs for full TP1 → TP2 → exit cycle - [ ] SQL query: verify `tp1Hit`, `slMovedToBreakeven`, `currentSize` match Position Manager logs - [ ] Compare Position Manager tracked size to actual Drift position size - [ ] Check exit reason matches actual trigger (TP1/TP2/SL/trailing) +- [ ] **VERIFY VIA DRIFT API** before declaring anything "working" or "closed" **Exit Logic Changes (TP/SL/Trailing):** - [ ] Log EXPECTED values (TP1 price, SL price after breakeven, trailing stop distance)