phase-8f: persistant cache locally
This commit is contained in:
committed by
saikiranvella
parent
ff1b99910b
commit
5af9ded35e
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user