Reporter: catch up completed cycles on reset, report each firm's account list
When a fund transaction starts a new cycle (the days revert to 0), the cycle it ended is checked against the completion rule for a week after and named if it stood complete — its final day may never have been reported. Only for a cycle this instance saw begin: the clients now note where the ended cycle started as they move last_fund_date forward. Completions carry the cycle they belong to, and each firm reports its whole account list so the master can tell erased accounts and spot new funded ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
acb8879575
commit
a7e01b0138
@@ -348,6 +348,31 @@ export function loadAccountMeta(accountId: number, key: string): string | null {
|
||||
return row?.value ?? null;
|
||||
}
|
||||
|
||||
/** Where the cycle the latest fund transaction ended began, saved by the
|
||||
* platform client as it moves last_fund_date forward — and only from a cycle
|
||||
* start this instance saw, so the reporter's catch-up never judges a cycle
|
||||
* whose older rows it lacks. fundDate = that cycle's fund date ('' for the
|
||||
* account's first cycle); includesDay = whether that date's own trades were
|
||||
* the cycle's (a deposit's are; a Tradovate withdrawal's only when it came
|
||||
* before the day's first trade, which the reporter can't work out again). */
|
||||
export function saveEndedCycleStart(accountId: number, start: { fundDate: string; includesDay: boolean }): void {
|
||||
saveAccountMeta(accountId, 'ended_cycle_start', JSON.stringify(start));
|
||||
}
|
||||
|
||||
/** null when this instance never saw the ended cycle start: a new instance
|
||||
* or a wipe (which clears it with the rest of the meta), or TopstepX's
|
||||
* first-check lump. */
|
||||
export function loadEndedCycleStart(accountId: number): { fundDate: string; includesDay: boolean } | null {
|
||||
const raw = loadAccountMeta(accountId, 'ended_cycle_start');
|
||||
if (raw === null) return null;
|
||||
try {
|
||||
const { fundDate, includesDay } = JSON.parse(raw) as { fundDate?: unknown; includesDay?: unknown };
|
||||
return typeof fundDate === 'string' && typeof includesDay === 'boolean' ? { fundDate, includesDay } : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Deletes every cached row for an account — daily P&L, fund transactions and
|
||||
* meta — so the next report fetch rebuilds it from scratch. Rows older than
|
||||
* the report's 28-day window are gone for good; that is the point (stale
|
||||
|
||||
Reference in New Issue
Block a user