CRITICAL FIX: TP/SL orders using wrong size calculation

**ROOT CAUSE:** placeExitOrders() calculated position size using TP/SL prices instead of entry price

**Problem:**
- TP1 order size: 85 / TP1_price (00.746) = 2.914 SOL
- Actual position: 80 / entry_price (99.946) = 3.901 SOL
- TP1 should close: 3.901 * 75% = 2.926 SOL
- But it only closed: 2.914 SOL = 74.7%  WRONG!

**Result:** TP1 closed ~25% instead of 75%, no runner left

**Fix:**
- Changed usdToBase() to use entryPrice for ALL size calculations
- Added entryPrice param to PlaceExitOrdersOptions interface
- Updated all API routes to pass entryPrice

**Testing:** Next trade will have correctly sized TP/SL orders
This commit is contained in:
mindesbunister
2025-10-29 17:34:10 +01:00
parent f7cf9ec63b
commit 797e80b56a
7 changed files with 14 additions and 6 deletions

View File

@@ -201,6 +201,7 @@ export async function POST(request: NextRequest): Promise<NextResponse<ReducePos
symbol: trade.symbol,
direction: trade.direction,
positionSizeUSD: remainingSizeUSD,
entryPrice: trade.entryPrice,
tp1Price: newTP1,
tp2Price: newTP2,
stopLossPrice: newSL,