Persist daily P&L beyond 28-day Tradovate window
Adds a daily_pnl SQLite table that accumulates trade history indefinitely. On each hourly fetch, fresh API data is upserted (not replaced) so entries older than Tradovate's 28-day limit are preserved. Cache is loaded at startup and used as fallback when both report requests fail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
131c9bca9f
commit
6b299f5359
@@ -201,6 +201,32 @@ export function setInstrumentEnabled(symbol: string, enabled: boolean): boolean
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
||||
// ── Daily P&L Cache ──────────────────────────────────────────────────────────
|
||||
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS daily_pnl (
|
||||
account_id INTEGER NOT NULL,
|
||||
account_name TEXT NOT NULL,
|
||||
date TEXT NOT NULL,
|
||||
pnl REAL NOT NULL,
|
||||
PRIMARY KEY (account_id, date)
|
||||
);
|
||||
`);
|
||||
|
||||
export function saveDailyPnL(accountId: number, accountName: string, entries: { date: string; pnl: number }[]): void {
|
||||
const ins = db.prepare('INSERT OR REPLACE INTO daily_pnl (account_id, account_name, date, pnl) VALUES (?, ?, ?, ?)');
|
||||
const txn = db.transaction(() => {
|
||||
for (const e of entries) {
|
||||
ins.run(accountId, accountName, e.date, e.pnl);
|
||||
}
|
||||
});
|
||||
txn();
|
||||
}
|
||||
|
||||
export function loadDailyPnL(accountId: number): { date: string; pnl: number }[] {
|
||||
return (db.prepare('SELECT date, pnl FROM daily_pnl WHERE account_id = ? ORDER BY date').all(accountId) as { date: string; pnl: number }[]);
|
||||
}
|
||||
|
||||
// ── Firm banned symbols ───────────────────────────────────────────────────────
|
||||
|
||||
db.exec(`
|
||||
|
||||
Reference in New Issue
Block a user