fix(stocks): Fix Yahoo provider request handling and bump dependency versions
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@fin.cx/opendata',
|
||||
version: '1.6.0',
|
||||
version: '1.6.1',
|
||||
description: 'A comprehensive TypeScript library for accessing business data and real-time financial information. Features include German company data management with MongoDB integration, JSONL bulk processing, automated Handelsregister interactions, and real-time stock market data from multiple providers.'
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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