docs: Document runner SL live test results and analytics fix as Common Pitfalls

Pitfall #34 (Runner SL gap):
- Updated with live test results from Nov 15, 22:03 CET
- Runner SL triggered successfully with +.94 profit (validates fix works)
- Documented rate limit storm during close (20+ attempts, eventually succeeded)
- Proves software protection works even without on-chain orders
- This was the CRITICAL fix that prevented hours of unprotected exposure

Pitfall #38 (Analytics showing wrong size - NEW):
- Dashboard displayed original position size (2.54) instead of runner (2.59)
- Root cause: API returned positionSizeUSD, not currentSize from Position Manager state
- Fixed by checking configSnapshot.positionManagerState.currentSize for open positions
- API-only change, no container restart needed
- Provides accurate exposure visibility on dashboard

Both issues discovered and fixed during today's live testing session.
This commit is contained in:
mindesbunister
2025-11-15 23:15:18 +01:00
parent 54012ec402
commit c8535bc5b6

View File

@@ -1420,11 +1420,39 @@ trade.realizedPnL += actualRealizedPnL // NOT: result.realizedPnL from SDK
return
}
```
- **Verification:** After fix deployed, runner closed at $141.133 with +$0.59 profit (+4.6% on $12.70 runner)
- **Live verification (Nov 15, 22:03):** Runner SL triggered successfully after deployment, closed with +$2.94 profit
- **Rate limit issue:** Hit 429 storm during close (20+ attempts over several minutes), but eventually succeeded
- **Database evidence:** Trade shows `exitReason='SL'`, proving runner stop loss triggered correctly
- **Why undetected:** Runner system relatively new (Nov 11), most trades hit TP2 quickly without price reversals
- **Lesson:** Every conditional branch in risk management MUST have explicit stop loss checks - never assume "it'll get caught somewhere"
38. **Analytics dashboard showing original position size instead of current runner size (Fixed Nov 15, 2025):**
- **Symptom:** Analytics page displays $42.54 when actual runner is $12.59 after TP1
- **Root Cause:** `/api/analytics/last-trade` returns `trade.positionSizeUSD` (original size), not runner size
- **Database structure:** No separate `currentSize` column - stored in `configSnapshot.positionManagerState.currentSize`
- **Impact:** User sees misleading exposure information on dashboard
- **Fix:** Modified API to check Position Manager state for open positions:
```typescript
// In app/api/analytics/last-trade/route.ts
const configSnapshot = trade.configSnapshot as any
const positionManagerState = configSnapshot?.positionManagerState
const currentSize = positionManagerState?.currentSize
// Use currentSize for open positions (after TP1), fallback to original
const displaySize = trade.exitReason === null && currentSize
? currentSize
: trade.positionSizeUSD
const formattedTrade = {
// ...
positionSizeUSD: displaySize, // Shows runner size for open positions
// ...
}
```
- **Behavior:** Open positions show current runner size, closed positions show original size
- **Benefits:** Accurate exposure visibility, correct risk assessment on dashboard
- **No container restart needed:** API-only change, live immediately after deployment
34. **Flip-flop price context using wrong data (CRITICAL - Fixed Nov 14, 2025):**
- **Symptom:** Flip-flop detection showing "100% price move" when actual movement was 0.2%, allowing trades that should be blocked
- **Root Cause:** `currentPrice` parameter not available in check-risk endpoint (trade hasn't opened yet), so calculation used undefined/zero