🚨 CRITICAL FIX: Stop cleanup from canceling SL/TP orders
- Fixed cleanup-orders logic to NEVER cancel reduce-only orders (SL/TP) - Updated position monitor to be more conservative with cleanup - This was causing SL/TP orders to be canceled after position creation - Positions were left unprotected due to aggressive cleanup logic
This commit is contained in:
@@ -99,9 +99,14 @@ export async function POST() {
|
||||
// Check if this order is for a market where we have no position
|
||||
const hasPosition = positionMarkets.has(order.marketIndex)
|
||||
|
||||
// CORRECTED LOGIC: Cancel ALL orders when no position exists
|
||||
// If we have no position, then ALL orders (including SL/TP) are orphaned
|
||||
return !hasPosition
|
||||
// 🛡️ CRITICAL FIX: Only cancel non-reduce-only orders when no position exists
|
||||
// NEVER cancel reduce-only orders (SL/TP) as they protect existing positions
|
||||
if (!hasPosition) {
|
||||
// Only cancel orders that are NOT reduce-only (market makers, limit orders)
|
||||
return !order.reduceOnly
|
||||
}
|
||||
|
||||
return false // Don't cancel any orders when position exists
|
||||
})
|
||||
|
||||
// Additionally, find lingering SL/TP orders when position has changed significantly
|
||||
|
||||
Reference in New Issue
Block a user