Fix: Initialize Drift service before cancelling orders
- cancelAllOrders() now calls initializeDriftService() if service not initialized - Prevents 'Drift service not initialized' error when Position Manager tries to cancel orphaned orders - Ensures order cleanup works correctly after external position closures
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user