fix: Correct order filtering to prevent false '32 orders' count
Problem: Bot reported '32 open orders' when Drift UI showed 0 orders Root Cause: Filter checked orderId > 0 but didn't verify baseAssetAmount Impact: Misleading logs suggesting ghost order accumulation Fix: Enhanced filter with proper empty slot detection: - Check orderId exists and is non-zero - Check baseAssetAmount exists and is non-zero (BN comparison) - Added logging to show: 'Found X orders (checked 32 total slots)' Result: Bot now correctly reports 0 orders when none exist Verification: Container restart shows no false positives Files: lib/drift/orders.ts (cancelAllOrders function)
This commit is contained in:
@@ -807,12 +807,23 @@ export async function cancelAllOrders(
|
||||
throw new Error('User account not found')
|
||||
}
|
||||
|
||||
// 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
|
||||
// Filter orders for this market (check for TRULY active orders)
|
||||
// CRITICAL: Empty slots have orderId=0 OR baseAssetAmount=0
|
||||
// Only count orders that actually exist and are open
|
||||
const ordersToCancel = userAccount.orders.filter(
|
||||
(order: any) =>
|
||||
order.marketIndex === marketConfig.driftMarketIndex &&
|
||||
order.orderId > 0 // Active orders have orderId > 0
|
||||
(order: any) => {
|
||||
// Skip if not our market
|
||||
if (order.marketIndex !== marketConfig.driftMarketIndex) return false
|
||||
|
||||
// Skip if orderId is 0 (empty slot)
|
||||
if (!order.orderId || order.orderId === 0) return false
|
||||
|
||||
// Skip if baseAssetAmount is 0 (no actual order size)
|
||||
if (!order.baseAssetAmount || order.baseAssetAmount.eq(new BN(0))) return false
|
||||
|
||||
// This is a real active order
|
||||
return true
|
||||
}
|
||||
)
|
||||
|
||||
if (ordersToCancel.length === 0) {
|
||||
@@ -821,6 +832,7 @@ export async function cancelAllOrders(
|
||||
}
|
||||
|
||||
console.log(`📋 Found ${ordersToCancel.length} open orders to cancel (including trigger orders)`)
|
||||
console.log(` (checked ${userAccount.orders.length} total order slots)`)
|
||||
|
||||
// Cancel all orders with retry logic for rate limits
|
||||
const txSig = await retryWithBackoff(async () => {
|
||||
|
||||
Reference in New Issue
Block a user