fix: harden drift verifier and validation flow
This commit is contained in:
@@ -285,12 +285,14 @@ export async function placeExitOrders(options: PlaceExitOrdersOptions): Promise<
|
||||
// CRITICAL FIX: TP2 must be percentage of REMAINING size after TP1, not original size
|
||||
const tp1USD = (options.positionSizeUSD * options.tp1SizePercent) / 100
|
||||
const remainingAfterTP1 = options.positionSizeUSD - tp1USD
|
||||
const tp2USD = (remainingAfterTP1 * options.tp2SizePercent) / 100
|
||||
const requestedTp2Percent = options.tp2SizePercent ?? 100
|
||||
const normalizedTp2Percent = requestedTp2Percent > 0 ? requestedTp2Percent : 100
|
||||
const tp2USD = (remainingAfterTP1 * normalizedTp2Percent) / 100
|
||||
|
||||
logger.log(`📊 Exit order sizes:`)
|
||||
logger.log(` TP1: ${options.tp1SizePercent}% of $${options.positionSizeUSD.toFixed(2)} = $${tp1USD.toFixed(2)}`)
|
||||
logger.log(` Remaining after TP1: $${remainingAfterTP1.toFixed(2)}`)
|
||||
logger.log(` TP2: ${options.tp2SizePercent}% of remaining = $${tp2USD.toFixed(2)}`)
|
||||
logger.log(` TP2: ${normalizedTp2Percent}% of remaining = $${tp2USD.toFixed(2)}`)
|
||||
logger.log(` Runner (if any): $${(remainingAfterTP1 - tp2USD).toFixed(2)}`)
|
||||
|
||||
// For orders that close a long, the order direction should be SHORT (sell)
|
||||
|
||||
Reference in New Issue
Block a user