Fix runner activation and order cancellation
- Change takeProfit2SizePercent from 100% to 80% to leave 5% runner - Fix cancelAllOrders() to detect trigger orders using orderId > 0 - Trigger orders (TRIGGER_MARKET, TRIGGER_LIMIT) now properly canceled - Trailing stop will now activate on 5% runner position
This commit is contained in:
@@ -563,21 +563,22 @@ export async function cancelAllOrders(
|
||||
throw new Error('User account not found')
|
||||
}
|
||||
|
||||
// Filter orders for this market
|
||||
// Filter orders for this market (check for active orders, not just status)
|
||||
// Note: Trigger orders may have different status values, so we check for non-zero orderId
|
||||
const ordersToCancel = userAccount.orders.filter(
|
||||
(order: any) =>
|
||||
order.marketIndex === marketConfig.driftMarketIndex &&
|
||||
order.status === 0 // 0 = Open status
|
||||
order.orderId > 0 // Active orders have orderId > 0
|
||||
)
|
||||
|
||||
|
||||
if (ordersToCancel.length === 0) {
|
||||
console.log('✅ No open orders to cancel')
|
||||
return { success: true, cancelledCount: 0 }
|
||||
}
|
||||
|
||||
console.log(`📋 Found ${ordersToCancel.length} open orders to cancel (including trigger orders)`)
|
||||
|
||||
console.log(`📋 Found ${ordersToCancel.length} open orders to cancel`)
|
||||
|
||||
// Cancel all orders for this market
|
||||
// Cancel all orders for this market (cancels all types: LIMIT, TRIGGER_MARKET, TRIGGER_LIMIT)
|
||||
const txSig = await driftClient.cancelOrders(
|
||||
undefined, // Cancel by market type
|
||||
marketConfig.driftMarketIndex,
|
||||
|
||||
Reference in New Issue
Block a user