Files
autofirmer-expanded/app/api/accounts/[id]/fire-leg/route.ts
T
Brandon LiandClaude Opus 5.5 b5ed423145 Manual one-leg trigger: POST /api/accounts/[id]/fire-leg
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>
2026-09-26 17:43:51 -05:00

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 });
}
}