From 90efc2ac51ecd79f08bc31df6335bee78256f042 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Mon, 18 Apr 2022 11:57:57 +0200 Subject: [PATCH] Feature/beautify etf names in asset profile (#842) * Beautify ETF names * Update changelog --- CHANGELOG.md | 4 +++ .../yahoo-finance/yahoo-finance.service.ts | 27 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67bb0e886..0fcba5e49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added the total amount to the tooltip in the chart of the _FIRE_ calculator +### Changed + +- Beautified the ETF names in the symbol profile + ### Fixed - Fixed an issue with changing the investment horizon in the chart of the _FIRE_ calculator 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 b5a0932fb..b5d8e1ebd 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 @@ -20,7 +20,10 @@ import Big from 'big.js'; import { countries } from 'countries-list'; import { addDays, format, isSameDay } from 'date-fns'; import yahooFinance from 'yahoo-finance2'; -import type { Price } from 'yahoo-finance2/dist/esm/src/modules/quoteSummary-iface'; +import type { + Price, + QuoteSummaryResult +} from 'yahoo-finance2/dist/esm/src/modules/quoteSummary-iface'; @Injectable() export class YahooFinanceService implements DataProviderInterface { @@ -89,8 +92,7 @@ export class YahooFinanceService implements DataProviderInterface { response.assetSubClass = assetSubClass; response.currency = assetProfile.price.currency; response.dataSource = this.getName(); - response.name = - assetProfile.price.longName || assetProfile.price.shortName || symbol; + response.name = this.formatName(assetProfile); response.symbol = aSymbol; if ( @@ -296,6 +298,25 @@ export class YahooFinanceService implements DataProviderInterface { return { items }; } + private formatName(aAssetProfile: QuoteSummaryResult) { + let name = aAssetProfile.price.longName; + + if (name) { + name = name.replace('iShares ETF (CH) - ', ''); + name = name.replace('iShares III Public Limited Company - ', ''); + name = name.replace('iShares VI Public Limited Company - ', ''); + name = name.replace('iShares VII PLC - ', ''); + name = name.replace('Multi Units Luxembourg - ', ''); + name = name.replace('VanEck ETFs N.V. - ', ''); + name = name.replace('Vaneck Vectors Ucits Etfs Plc - ', ''); + name = name.replace('Vanguard Funds Public Limited Company - ', ''); + name = name.replace('Vanguard Index Funds - ', ''); + name = name.replace('Xtrackers (IE) Plc - ', ''); + } + + return name || aAssetProfile.price.shortName || aAssetProfile.price.symbol; + } + private parseAssetClass(aPrice: Price): { assetClass: AssetClass; assetSubClass: AssetSubClass;