Add a wipe & recalculate button to the account detail page
Cached daily P&L rows outlive what the Cash History report still produces (stale pre-roll dates being the recent example), and nothing deletes them any more. POST /api/accounts/[id]/wipe drops the account's cached P&L, fund transactions and meta, clears the in-memory view, and rebuilds from a fresh report — fetchDaysTraded now takes an optional account filter so one account doesn't cost a report round-trip on every other. The button confirms inline first: rows older than the report's 28-day window cannot be refetched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
bd72c4b1f6
commit
5a69ea2f64
@@ -282,6 +282,19 @@ export function loadAccountMeta(accountId: number, key: string): string | null {
|
||||
return row?.value ?? 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
|
||||
* pre-roll dates), but it is why callers confirm first. */
|
||||
export function wipeAccountData(accountId: number): void {
|
||||
const txn = db.transaction(() => {
|
||||
db.prepare('DELETE FROM daily_pnl WHERE account_id = ?').run(accountId);
|
||||
db.prepare('DELETE FROM fund_transactions WHERE account_id = ?').run(accountId);
|
||||
db.prepare('DELETE FROM account_meta WHERE account_id = ?').run(accountId);
|
||||
});
|
||||
txn();
|
||||
}
|
||||
|
||||
// ── AutoBuyer captures ───────────────────────────────────────────────────────
|
||||
|
||||
db.exec(`
|
||||
|
||||
@@ -437,7 +437,9 @@ export class TradovateClient {
|
||||
return { active, prior };
|
||||
}
|
||||
|
||||
public async fetchDaysTraded(): Promise<{ failedAccounts: number }> {
|
||||
/** Pass onlyAccountIds to refresh a subset (e.g. one wiped account) without
|
||||
* paying for a report round-trip on every other account of the firm. */
|
||||
public async fetchDaysTraded(onlyAccountIds?: number[]): Promise<{ failedAccounts: number }> {
|
||||
if (!this.accessInfo?.accessToken) return { failedAccounts: 0 };
|
||||
this.fetchDaysComplete = false;
|
||||
let failedAccounts = 0;
|
||||
@@ -524,6 +526,7 @@ export class TradovateClient {
|
||||
};
|
||||
|
||||
for (const account of this.accountList) {
|
||||
if (onlyAccountIds && !onlyAccountIds.includes(account.id)) continue;
|
||||
// Load last known fund date and fund transactions from DB
|
||||
const storedFundDate = loadAccountMeta(account.id, 'last_fund_date');
|
||||
this.lastFundDates[account.id] = storedFundDate;
|
||||
|
||||
Reference in New Issue
Block a user