Fires one leg on one account through the scheduler's own fire path (sizing, take-profit, daily-loss stop, exit bracket), overriding only the one-trade- per-day rule for unsplit accounts. Flat, history, daily-loss room, trading hours, a flat lane and the lane mutex still apply. The daily-loss check is factored out so both paths share it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
21 lines
983 B
TypeScript
21 lines
983 B
TypeScript
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 });
|
|
}
|
|
}
|