diff --git a/CHANGELOG.md b/CHANGELOG.md index ca0d45fb9..c824e35c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Improved the search in the _Yahoo Finance_ service - Moved the holdings table into the holdings section on the public page - Refactored the login with access token dialog component to standalone diff --git a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts index eb6f85d73..40298de15 100644 --- a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts +++ b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts @@ -24,6 +24,7 @@ import { import { Injectable, Logger } from '@nestjs/common'; import { DataSource, SymbolProfile } from '@prisma/client'; import { addDays, format, isSameDay } from 'date-fns'; +import { uniqBy } from 'lodash'; import YahooFinance from 'yahoo-finance2'; import { ChartResultArray } from 'yahoo-finance2/esm/src/modules/chart'; import { @@ -290,7 +291,9 @@ export class YahooFinanceService implements DataProviderInterface { try { marketData = await this.yahooFinance.quote( - quotes.map(({ symbol }) => { + uniqBy(quotes, ({ symbol }) => { + return symbol; + }).map(({ symbol }) => { return symbol; }) ); @@ -300,35 +303,35 @@ export class YahooFinanceService implements DataProviderInterface { } } - for (const marketDataItem of marketData) { - const quote = quotes.find((currentQuote) => { - return currentQuote.symbol === marketDataItem.symbol; - }); - - const symbol = - this.yahooFinanceDataEnhancerService.convertFromYahooFinanceSymbol( - marketDataItem.symbol - ); - + for (const { + currency, + longName, + quoteType, + shortName, + symbol + } of marketData) { const { assetClass, assetSubClass } = this.yahooFinanceDataEnhancerService.parseAssetClass({ - quoteType: quote.quoteType, - shortName: quote.shortname + quoteType, + shortName }); items.push({ assetClass, assetSubClass, - symbol, - currency: marketDataItem.currency, + currency, dataProviderInfo: this.getDataProviderInfo(), dataSource: this.getName(), name: this.yahooFinanceDataEnhancerService.formatName({ - longName: quote.longname, - quoteType: quote.quoteType, - shortName: quote.shortname, - symbol: quote.symbol - }) + longName, + quoteType, + shortName, + symbol + }), + symbol: + this.yahooFinanceDataEnhancerService.convertFromYahooFinanceSymbol( + symbol + ) }); } } catch (error) {