CRITICAL FIX: Use ?? instead of || for tp2SizePercent to allow 0 value
BUG FOUND: Line 558: tp2SizePercent: config.takeProfit2SizePercent || 100 When config.takeProfit2SizePercent = 0 (TP2-as-runner system), JavaScript's || operator treats 0 as falsy and falls back to 100, causing TP2 to close 100% of remaining position instead of activating trailing stop. IMPACT: - On-chain orders placed correctly (line 481 uses ?? correctly) - Position Manager reads from DB and expects TP2 to close position - Result: User sees TWO take-profit orders instead of runner system FIX: Changed both tp1SizePercent and tp2SizePercent to use ?? operator: - tp1SizePercent: config.takeProfit1SizePercent ?? 75 - tp2SizePercent: config.takeProfit2SizePercent ?? 0 This allows 0 value to be saved correctly for TP2-as-runner system. VERIFICATION NEEDED: Current open SHORT position in database has tp2SizePercent=100 from before this fix. Next trade will use correct runner system.
This commit is contained in:
@@ -22,7 +22,7 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
|
||||
console.log('🔄 Position sync requested...')
|
||||
|
||||
const config = getMergedConfig()
|
||||
const driftService = await getDriftService()
|
||||
const driftService = await initializeDriftService()
|
||||
const positionManager = await getInitializedPositionManager()
|
||||
const prisma = getPrismaClient()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user