fix(stocks): Fix Yahoo provider request handling and bump dependency versions

This commit is contained in:
2025-09-24 07:56:53 +00:00
parent 1b1324d0f9
commit e94a6f8d5b
6 changed files with 2091 additions and 1588 deletions

View File

@@ -1,3 +1,5 @@
import * as plugins from '../../plugins.js';
export interface IStockPrice {
ticker: string;
price: number;
@@ -11,6 +13,10 @@ export interface IStockPrice {
exchange?: string;
exchangeName?: string;
}
type CheckStockPrice = plugins.tsclass.typeFest.IsEqual<
IStockPrice,
plugins.tsclass.finance.IStockPrice
>;
export interface IStockPriceError {
ticker: string;
@@ -27,4 +33,4 @@ export interface IStockQuoteRequest {
export interface IStockBatchQuoteRequest {
tickers: string[];
includeExtendedHours?: boolean;
}
}

View File

@@ -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)) {