import { NextRequest, NextResponse } from 'next/server' import { cancelAllOrders } from '@/lib/drift/orders' import { initializeDriftService } from '@/lib/drift/client' /** * Cancel all orders for a symbol * POST /api/trading/cancel-orders */ export async function POST(request: NextRequest) { try { const body = await request.json() const { symbol } = body if (!symbol) { return NextResponse.json( { success: false, error: 'Symbol required' }, { status: 400 } ) } console.log(`🗑️ Manual order cancellation requested for ${symbol}`) // Initialize Drift service await initializeDriftService() // Cancel all orders const result = await cancelAllOrders(symbol) if (result.success) { return NextResponse.json({ success: true, message: `Cancelled ${result.cancelledCount || 0} orders for ${symbol}`, cancelledCount: result.cancelledCount, }) } else { return NextResponse.json( { success: false, error: result.error }, { status: 500 } ) } } catch (error) { console.error('❌ Error cancelling orders:', error) return NextResponse.json( { success: false, error: error instanceof Error ? error.message : 'Failed to cancel orders', }, { status: 500 } ) } }