diff --git a/lib/drift/orders.ts b/lib/drift/orders.ts index 29ec2de..794eb12 100644 --- a/lib/drift/orders.ts +++ b/lib/drift/orders.ts @@ -4,7 +4,7 @@ * Handles opening and closing positions with market orders */ -import { getDriftService } from './client' +import { getDriftService, initializeDriftService } from './client' import { getMarketConfig } from '../../config/trading' import BN from 'bn.js' import { @@ -541,7 +541,13 @@ export async function cancelAllOrders( try { console.log(`🗑️ Cancelling all orders for ${symbol}...`) - const driftService = getDriftService() + // Ensure Drift service is initialized + let driftService = getDriftService() + if (!driftService) { + console.log('⚠️ Drift service not initialized, initializing now...') + driftService = await initializeDriftService() + } + const driftClient = driftService.getClient() const marketConfig = getMarketConfig(symbol)