diff --git a/lib/trading/sync-helper.ts b/lib/trading/sync-helper.ts index e4f83de..d4ce1cb 100644 --- a/lib/trading/sync-helper.ts +++ b/lib/trading/sync-helper.ts @@ -29,13 +29,18 @@ async function discoverExistingOrders(symbol: string, marketIndex: number): Prom const driftService = getDriftService() const driftClient = driftService.getClient() - // Get all open orders for this user - const orders = driftClient.getOpenOrders() + // Get user account and extract orders + const userAccount = driftClient.getUserAccount() + if (!userAccount) { + console.log('⚠️ No user account found, cannot discover orders') + return {} + } // Filter for orders on this market that are reduce-only - const marketOrders = orders.filter(order => + const marketOrders = userAccount.orders.filter((order: any) => order.marketIndex === marketIndex && - order.reduceOnly === true + order.reduceOnly === true && + order.orderId && order.orderId !== 0 ) const signatures: any = {}