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:
@@ -251,6 +251,7 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
|
||||
const exitRes = await placeExitOrders({
|
||||
symbol: driftSymbol,
|
||||
positionSizeUSD: positionSizeUSD,
|
||||
entryPrice: entryPrice,
|
||||
tp1Price,
|
||||
tp2Price,
|
||||
stopLossPrice,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -168,6 +168,7 @@ export async function POST(request: NextRequest): Promise<NextResponse<ScalePosi
|
||||
symbol: trade.symbol,
|
||||
direction: trade.direction,
|
||||
positionSizeUSD: newTotalValue,
|
||||
entryPrice: newAvgEntry,
|
||||
tp1Price: newTP1,
|
||||
tp2Price: newTP2,
|
||||
stopLossPrice: newSL,
|
||||
|
||||
@@ -134,6 +134,7 @@ export async function POST(request: NextRequest): Promise<NextResponse<TestTrade
|
||||
const exitRes = await placeExitOrders({
|
||||
symbol,
|
||||
positionSizeUSD,
|
||||
entryPrice,
|
||||
tp1Price,
|
||||
tp2Price,
|
||||
stopLossPrice,
|
||||
|
||||
@@ -211,6 +211,7 @@ export async function POST(request: NextRequest): Promise<NextResponse<TestTrade
|
||||
const exitRes = await placeExitOrders({
|
||||
symbol: driftSymbol,
|
||||
positionSizeUSD: positionSizeUSD,
|
||||
entryPrice: entryPrice,
|
||||
tp1Price,
|
||||
tp2Price,
|
||||
stopLossPrice,
|
||||
|
||||
Reference in New Issue
Block a user