import { NextRequest, NextResponse } from 'next/server'; import { fireManualLeg } from '@/lib/auto-trade'; import { errorMessage } from '@/lib/platform-client'; type Params = { params: Promise<{ id: string }> }; /** Fire one leg on this account now, through the scheduler's own path (see * fireManualLeg). Body: { action?: 'Buy' | 'Sell' | 'Auto' } (default Auto). */ export async function POST(req: NextRequest, { params }: Params) { const { id } = await params; const accountId = Number(id); if (!Number.isSafeInteger(accountId)) return NextResponse.json({ error: 'bad account id' }, { status: 400 }); const body = (await req.json().catch(() => ({}))) as { action?: unknown }; const action = body.action === 'Buy' || body.action === 'Sell' ? body.action : 'Auto'; try { return NextResponse.json(await fireManualLeg(accountId, action)); } catch (err) { return NextResponse.json({ error: errorMessage(err) }, { status: 409 }); } }