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
- 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

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

Loading…
Cancel
Save