fix: Emergency position close when exit orders missing (Bug #76 enforcement)
- Changed execute endpoint from warning-only to active enforcement - When placeExitOrders() returns < expected signatures, immediately: 1. Close the position 100% (emergency safety) 2. Return HTTP 500 error (prevent DB record creation) 3. Log critical error for post-mortem - Prevents unprotected positions from being created in database - Root cause: Previous fix validated but continued execution - Result: No more positions without stop loss protection Deployed: Dec 10, 2025 11:42 CET Container: trading-bot-v4 Build: sha256:d576e7c5d421
This commit is contained in:
@@ -973,9 +973,12 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
|
|||||||
|
|
||||||
// CRITICAL: Close the unprotected position immediately
|
// CRITICAL: Close the unprotected position immediately
|
||||||
try {
|
try {
|
||||||
const driftService = getDriftService()
|
const closeResult = await closePosition({
|
||||||
const closeResult = await driftService.closePosition(driftMarketIndex, 100)
|
symbol: driftSymbol,
|
||||||
console.log(`✅ Emergency closed unprotected position: ${closeResult}`)
|
percentToClose: 100,
|
||||||
|
slippageTolerance: config.slippageTolerance || 0.01
|
||||||
|
})
|
||||||
|
console.log(`✅ Emergency closed unprotected position:`, closeResult)
|
||||||
} catch (closeError) {
|
} catch (closeError) {
|
||||||
console.error(`❌ Failed to emergency close unprotected position:`, closeError)
|
console.error(`❌ Failed to emergency close unprotected position:`, closeError)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user