phase-8f: persistant cache locally

This commit is contained in:
Sai Kiran Vella
2026-06-05 22:52:30 -04:00
parent 1e2aac7164
commit 8c98693901
7 changed files with 551 additions and 24 deletions
+10 -2
View File
@@ -11,10 +11,16 @@ export class YahooFinanceClient {
});
}
/** Normalise ticker before hitting Yahoo: BRK.B → BRK-B */
private static normalise(ticker: string): string {
return ticker.toUpperCase().replace(/\./g, '-');
}
async fetchSummary(ticker: string, retries = 3, backoff = 1000): Promise<any> {
const normalised = YahooFinanceClient.normalise(ticker);
for (let attempt = 0; attempt < retries; attempt++) {
try {
return await this.lib.quoteSummary(ticker, { modules: YAHOO_MODULES });
return await this.lib.quoteSummary(normalised, { modules: YAHOO_MODULES });
} catch (error) {
if (attempt === retries - 1) throw error;
await new Promise<void>((resolve) => setTimeout(resolve, backoff * (attempt + 1)));
@@ -24,7 +30,9 @@ export class YahooFinanceClient {
async fetchCalendarEvents(ticker: string): Promise<any | null> {
try {
const result = await this.lib.quoteSummary(ticker, { modules: ['calendarEvents'] });
const result = await this.lib.quoteSummary(YahooFinanceClient.normalise(ticker), {
modules: ['calendarEvents'],
});
return result.calendarEvents ?? null;
} catch {
return null;