Co-authored-by: mindesbunister <32161838+mindesbunister@users.noreply.github.com>
This commit is contained in:
@@ -934,12 +934,54 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
|
||||
|
||||
if (!exitRes.success) {
|
||||
console.error('❌ Failed to place on-chain exit orders:', exitRes.error)
|
||||
|
||||
// BUG #76 FIX: Log critical error for missing exit orders
|
||||
logCriticalError('EXIT_ORDERS_PLACEMENT_FAILED', {
|
||||
symbol: driftSymbol,
|
||||
direction: body.direction,
|
||||
entryPrice,
|
||||
positionSize: positionSizeUSD,
|
||||
transactionSignature: openResult.transactionSignature,
|
||||
error: exitRes.error,
|
||||
partialSignatures: exitRes.signatures || []
|
||||
})
|
||||
} else {
|
||||
console.log('📨 Exit orders placed on-chain:', exitRes.signatures)
|
||||
exitOrderSignatures = exitRes.signatures || []
|
||||
|
||||
// BUG #76 FIX: Validate expected signature count
|
||||
const expectedCount = config.useDualStops ? 4 : 3 // TP1 + TP2 + (soft+hard OR single SL)
|
||||
if (exitOrderSignatures.length < expectedCount) {
|
||||
console.error(`❌ CRITICAL: Missing exit orders!`)
|
||||
console.error(` Expected: ${expectedCount} signatures (TP1 + TP2 + ${config.useDualStops ? 'Soft SL + Hard SL' : 'SL'})`)
|
||||
console.error(` Got: ${exitOrderSignatures.length} signatures`)
|
||||
console.error(` Position is UNPROTECTED! Missing stop loss!`)
|
||||
|
||||
// Log to persistent file for post-mortem
|
||||
logCriticalError('MISSING_EXIT_ORDERS', {
|
||||
symbol: driftSymbol,
|
||||
direction: body.direction,
|
||||
entryPrice,
|
||||
positionSize: positionSizeUSD,
|
||||
transactionSignature: openResult.transactionSignature,
|
||||
expectedCount,
|
||||
actualCount: exitOrderSignatures.length,
|
||||
signatures: exitOrderSignatures,
|
||||
useDualStops: config.useDualStops
|
||||
})
|
||||
|
||||
// Continue with trade creation but flag as needing verification
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('❌ Unexpected error placing exit orders:', err)
|
||||
|
||||
// Log unexpected error
|
||||
logCriticalError('EXIT_ORDERS_UNEXPECTED_ERROR', {
|
||||
symbol: driftSymbol,
|
||||
direction: body.direction,
|
||||
error: err instanceof Error ? err.message : String(err)
|
||||
})
|
||||
}
|
||||
|
||||
console.log('🔍 DEBUG: Exit orders section complete, about to calculate quality score...')
|
||||
|
||||
Reference in New Issue
Block a user