Bugfix/fix historical market data gathering in yahoo finance service (#3737)

* Switch from historical() to chart()

* Update changelog
pull/3738/head
Thomas Kaul 3 months ago committed by GitHub
parent 1204240ed0
commit 8c322b4e81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed an issue in the view mode toggle of the holdings tab on the home page (experimental) - Fixed an issue in the view mode toggle of the holdings tab on the home page (experimental)
- Fixed an issue on the portfolio activities page by loading the data only once - Fixed an issue on the portfolio activities page by loading the data only once
- Fixed an issue in the carousel component for the testimonial section on the landing page - Fixed an issue in the carousel component for the testimonial section on the landing page
- Fixed the historical market data gathering in the _Yahoo Finance_ service by switching from `historical()` to `chart()`
- Handled an exception in the historical market data component of the asset profile details dialog in the admin control panel - Handled an exception in the historical market data component of the asset profile details dialog in the admin control panel
## 2.105.0 - 2024-08-21 ## 2.105.0 - 2024-08-21

@ -20,6 +20,11 @@ import { Injectable, Logger } from '@nestjs/common';
import { DataSource, SymbolProfile } from '@prisma/client'; import { DataSource, SymbolProfile } from '@prisma/client';
import { addDays, format, isSameDay } from 'date-fns'; import { addDays, format, isSameDay } from 'date-fns';
import yahooFinance from 'yahoo-finance2'; import yahooFinance from 'yahoo-finance2';
import { ChartResultArray } from 'yahoo-finance2/dist/esm/src/modules/chart';
import {
HistoricalDividendsResult,
HistoricalHistoryResult
} from 'yahoo-finance2/dist/esm/src/modules/historical';
import { Quote } from 'yahoo-finance2/dist/esm/src/modules/quote'; import { Quote } from 'yahoo-finance2/dist/esm/src/modules/quote';
@Injectable() @Injectable()
@ -60,18 +65,19 @@ export class YahooFinanceService implements DataProviderInterface {
} }
try { try {
const historicalResult = await yahooFinance.historical( const historicalResult = this.convertToDividendResult(
this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol( await yahooFinance.chart(
symbol this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol(
), symbol
{ ),
events: 'dividends', {
interval: granularity === 'month' ? '1mo' : '1d', events: 'dividends',
period1: format(from, DATE_FORMAT), interval: granularity === 'month' ? '1mo' : '1d',
period2: format(to, DATE_FORMAT) period1: format(from, DATE_FORMAT),
} period2: format(to, DATE_FORMAT)
}
)
); );
const response: { const response: {
[date: string]: IDataProviderHistoricalResponse; [date: string]: IDataProviderHistoricalResponse;
} = {}; } = {};
@ -108,15 +114,17 @@ export class YahooFinanceService implements DataProviderInterface {
} }
try { try {
const historicalResult = await yahooFinance.historical( const historicalResult = this.convertToHistoricalResult(
this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol( await yahooFinance.chart(
symbol this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol(
), symbol
{ ),
interval: '1d', {
period1: format(from, DATE_FORMAT), interval: '1d',
period2: format(to, DATE_FORMAT) period1: format(from, DATE_FORMAT),
} period2: format(to, DATE_FORMAT)
}
)
); );
const response: { const response: {
@ -302,6 +310,20 @@ export class YahooFinanceService implements DataProviderInterface {
return { items }; return { items };
} }
private convertToDividendResult(
result: ChartResultArray
): HistoricalDividendsResult {
return result.events.dividends.map(({ amount: dividends, date }) => {
return { date, dividends };
});
}
private convertToHistoricalResult(
result: ChartResultArray
): HistoricalHistoryResult {
return result.quotes;
}
private async getQuotesWithQuoteSummary(aYahooFinanceSymbols: string[]) { private async getQuotesWithQuoteSummary(aYahooFinanceSymbols: string[]) {
const quoteSummaryPromises = aYahooFinanceSymbols.map((symbol) => { const quoteSummaryPromises = aYahooFinanceSymbols.map((symbol) => {
return yahooFinance.quoteSummary(symbol).catch(() => { return yahooFinance.quoteSummary(symbol).catch(() => {

Loading…
Cancel
Save