Files
autofirmer-expanded/app/api/accounts/[id]/daily-pnl/route.ts
T
Brandon LiandClaude Fable 5 f07721019b Count CME holiday sessions as one combined trading day when the type opts in
Account types with the catalog's new combineCmeHolidays flag are read
through a combined-day view: holiday-session P&L entries fold into the
next full trading day (computed from the federal-holiday rules, so any
year works), the day count matches how the firm records it (Apex: Sun/
Mon/Tue around a Monday holiday is ONE day), and on the later sessions
of the stretch the earlier sessions' booked P&L carries into realized —
so day targets, already-traded gates, target-hit status and the panel's
day P&L all treat the stretch as a single day. Off by default; older
masters that don't send the flag behave exactly as before.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-08 21:12:37 -05:00

23 lines
970 B
TypeScript

import { NextResponse } from 'next/server';
import { getClients } from '@/lib/clients';
import { getAccountConfig } from '@/lib/account-type-resolver';
import { combineCmeSessions, currentTradeDateCT } from '@/lib/trading-logic';
export async function GET(_req: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const accountId = Number(id);
const clients = getClients();
for (const client of clients.values()) {
const daily = client.dailyPnL?.[accountId];
if (daily !== undefined) {
// Serve the same combined-day view the rest of the app computes
// with, so a combining firm's holiday stretch shows as one row.
const combine = getAccountConfig(accountId).accountType?.combineCmeHolidays === true;
return NextResponse.json(combineCmeSessions(combine, daily, currentTradeDateCT(), 0).dailyPnL);
}
}
return NextResponse.json([]);
}