docs: Add Bug #81 to TOP 10 CRITICAL PITFALLS - root cause of $1,000+ losses

Bug #81 (usdToBase wrong price) deserves TOP 10 status because:
- ROOT CAUSE of ,000+ user losses
- Broke working implementation (4cc294b: 100% success rate)
- Positions repeatedly created without stop loss protection
- Database showed NULL signatures despite orders supposedly placed
- User had to manually close multiple positions

This was THE bug that made user say: "we had this working perfectly in the past"

Fix: Reverted usdToBase() to use SPECIFIC price for each order (TP1/TP2/SL)
Status:  DEPLOYED Dec 10, 2025 14:31 CET (commit 55d780c)
This commit is contained in:
mindesbunister
2025-12-10 10:54:15 +01:00
parent 5950b13fdf
commit 43bf97d48b

View File

@@ -3091,25 +3091,27 @@ This section contains the **TOP 10 MOST CRITICAL** pitfalls that every AI agent
- **Why:** JavaScript Map.delete() returns true only for first caller
- **Status:** Fixed Dec 2, 2025
**9. Smart Entry Wrong Price (#66, #68)** - Use Pyth price, not webhook
**9. Wrong Price in usdToBase() (#81 - ROOT CAUSE - Dec 10, 2025)** - CAUSED $1,000+ LOSSES
- **Bug:** Changed from `usdToBase(usd, price)` to `usdToBase(usd)` using entryPrice for ALL orders
- **Impact:** Wrong token quantities = Drift rejects orders = NULL database signatures = NO risk management
- **Example:** $8,000 at TP1 $141.20 needs 56.66 SOL, but code calculated 57.14 SOL (used $140 entry price)
- **Fix:** Reverted to original: `usdToBase(tp1USD, options.tp1Price)` - use SPECIFIC price for each order
- **Original commit:** 4cc294b (Oct 26, 2025) - "All 3 exit orders placed successfully on-chain" (100% success)
- **Status:** ✅ FIXED Dec 10, 2025 14:31 CET (commit 55d780c)
**10. Smart Entry Wrong Price (#66, #68)** - Use Pyth price, not webhook
- **Bug #66:** Symbol format mismatch ("SOLUSDT" vs "SOL-PERP") caused cache miss
- **Bug #68:** Webhook `signal.price` contained percentage (70.80) not market price ($142)
- **Fix:** Always use `pythClient.getPrice(symbol)` for calculations
- **Status:** Fixed Dec 1-3, 2025
**10. MFE/MAE Wrong Units (#54)** - Store percentages, not dollars
- **Bug:** Storing $64.08 when should store 0.48% (133× inflation)
- **Fix:** `trade.maxFavorableExcursion = profitPercent` not `currentPnLDollars`
- **Impact:** Analytics completely wrong for all trades
- **Status:** Fixed Nov 23, 2025
---
### Quick Links by Category
**P&L Calculation Errors:** #11, #41, #48, #49, #54, #57, #61
**Race Conditions:** #27, #28, #59, #60, #67
**SDK/API Issues:** #1, #2, #12, #24, #36, #45
**SDK/API Issues:** #1, #2, #12, #24, #36, #45, #81
**Database Operations:** #29, #35, #37, #50, #58
**Configuration:** #55, #62
**Smart Entry:** #63, #66, #68, #70