initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// src/api/YahooClient.js
|
||||
import YahooFinance from 'yahoo-finance2';
|
||||
|
||||
export class YahooClient {
|
||||
constructor() {
|
||||
// Instantiate the client as required by v3
|
||||
this.yf = new YahooFinance();
|
||||
}
|
||||
|
||||
async fetchSummary(ticker, retries = 3, backoff = 1000) {
|
||||
for (let i = 0; i < retries; i++) {
|
||||
try {
|
||||
// Use the instance (this.yf) instead of the static import
|
||||
return await this.yf.quoteSummary(ticker, {
|
||||
modules: [
|
||||
'assetProfile',
|
||||
'financialData',
|
||||
'defaultKeyStatistics',
|
||||
'price',
|
||||
'summaryDetail',
|
||||
],
|
||||
});
|
||||
} catch (error) {
|
||||
if (i === retries - 1) throw error;
|
||||
await new Promise((res) => setTimeout(res, backoff * (i + 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user