🚨 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:
@@ -98,9 +98,13 @@ export async function GET() {
|
||||
if (activeOrders.length > 0) {
|
||||
console.log('📋 No active positions detected - checking for truly orphaned orders...');
|
||||
|
||||
// Filter for truly orphaned orders (non-reduce-only orders without positions)
|
||||
// Do NOT clean up reduce-only orders as these could be legitimate SL/TP from recently closed positions
|
||||
const trulyOrphanedOrders = activeOrders.filter(order => !order.reduceOnly);
|
||||
// Filter for truly orphaned orders (ONLY non-reduce-only orders without positions)
|
||||
// 🛡️ CRITICAL: NEVER clean up reduce-only orders as these are SL/TP protecting positions
|
||||
const trulyOrphanedOrders = activeOrders.filter(order => {
|
||||
// Only consider non-reduce-only orders for cleanup
|
||||
// Reduce-only orders (SL/TP) should NEVER be automatically canceled
|
||||
return !order.reduceOnly
|
||||
});
|
||||
|
||||
if (trulyOrphanedOrders.length > 0) {
|
||||
console.log(`🎯 Found ${trulyOrphanedOrders.length} truly orphaned orders (non-reduce-only) - triggering cleanup...`);
|
||||
|
||||
Reference in New Issue
Block a user