fix(stocks): Fix Yahoo provider request handling and bump dependency versions
This commit is contained in:
@@ -20,14 +20,15 @@ export class YahooFinanceProvider implements IStockProvider {
|
||||
public async fetchPrice(request: IStockQuoteRequest): Promise<IStockPrice> {
|
||||
try {
|
||||
const url = `${this.baseUrl}/v8/finance/chart/${request.ticker}`;
|
||||
const response = await plugins.smartrequest.getJson(url, {
|
||||
headers: {
|
||||
const response = await plugins.smartrequest.SmartRequest.create()
|
||||
.url(url)
|
||||
.headers({
|
||||
'User-Agent': this.userAgent
|
||||
},
|
||||
timeout: this.config?.timeout || 10000
|
||||
});
|
||||
})
|
||||
.timeout(this.config?.timeout || 10000)
|
||||
.get();
|
||||
|
||||
const responseData = response.body as any;
|
||||
const responseData = await response.json() as any;
|
||||
|
||||
if (!responseData?.chart?.result?.[0]) {
|
||||
throw new Error(`No data found for ticker ${request.ticker}`);
|
||||
@@ -66,14 +67,15 @@ export class YahooFinanceProvider implements IStockProvider {
|
||||
const symbols = request.tickers.join(',');
|
||||
const url = `${this.baseUrl}/v8/finance/spark?symbols=${symbols}&range=1d&interval=5m`;
|
||||
|
||||
const response = await plugins.smartrequest.getJson(url, {
|
||||
headers: {
|
||||
const response = await plugins.smartrequest.SmartRequest.create()
|
||||
.url(url)
|
||||
.headers({
|
||||
'User-Agent': this.userAgent
|
||||
},
|
||||
timeout: this.config?.timeout || 15000
|
||||
});
|
||||
})
|
||||
.timeout(this.config?.timeout || 15000)
|
||||
.get();
|
||||
|
||||
const responseData = response.body as any;
|
||||
const responseData = await response.json() as any;
|
||||
const prices: IStockPrice[] = [];
|
||||
|
||||
for (const [ticker, data] of Object.entries(responseData)) {
|
||||
|
Reference in New Issue
Block a user