Browse Source

Feature/improve search in Yahoo Finance service (#5518)

* Improve search

* Update changelog
pull/4522/merge
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
7857255ca3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 43
      apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts

1
CHANGELOG.md

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Improved the search in the _Yahoo Finance_ service
- Moved the holdings table into the holdings section on the public page - Moved the holdings table into the holdings section on the public page
- Refactored the login with access token dialog component to standalone - Refactored the login with access token dialog component to standalone

43
apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts

@ -24,6 +24,7 @@ import {
import { Injectable, Logger } from '@nestjs/common'; 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 { uniqBy } from 'lodash';
import YahooFinance from 'yahoo-finance2'; import YahooFinance from 'yahoo-finance2';
import { ChartResultArray } from 'yahoo-finance2/esm/src/modules/chart'; import { ChartResultArray } from 'yahoo-finance2/esm/src/modules/chart';
import { import {
@ -290,7 +291,9 @@ export class YahooFinanceService implements DataProviderInterface {
try { try {
marketData = await this.yahooFinance.quote( marketData = await this.yahooFinance.quote(
quotes.map(({ symbol }) => { uniqBy(quotes, ({ symbol }) => {
return symbol;
}).map(({ symbol }) => {
return symbol; return symbol;
}) })
); );
@ -300,35 +303,35 @@ export class YahooFinanceService implements DataProviderInterface {
} }
} }
for (const marketDataItem of marketData) { for (const {
const quote = quotes.find((currentQuote) => { currency,
return currentQuote.symbol === marketDataItem.symbol; longName,
}); quoteType,
shortName,
const symbol = symbol
this.yahooFinanceDataEnhancerService.convertFromYahooFinanceSymbol( } of marketData) {
marketDataItem.symbol
);
const { assetClass, assetSubClass } = const { assetClass, assetSubClass } =
this.yahooFinanceDataEnhancerService.parseAssetClass({ this.yahooFinanceDataEnhancerService.parseAssetClass({
quoteType: quote.quoteType, quoteType,
shortName: quote.shortname shortName
}); });
items.push({ items.push({
assetClass, assetClass,
assetSubClass, assetSubClass,
symbol, currency,
currency: marketDataItem.currency,
dataProviderInfo: this.getDataProviderInfo(), dataProviderInfo: this.getDataProviderInfo(),
dataSource: this.getName(), dataSource: this.getName(),
name: this.yahooFinanceDataEnhancerService.formatName({ name: this.yahooFinanceDataEnhancerService.formatName({
longName: quote.longname, longName,
quoteType: quote.quoteType, quoteType,
shortName: quote.shortname, shortName,
symbol: quote.symbol symbol
}) }),
symbol:
this.yahooFinanceDataEnhancerService.convertFromYahooFinanceSymbol(
symbol
)
}); });
} }
} catch (error) { } catch (error) {

Loading…
Cancel
Save