Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript π€
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/support activities import by isin for yahoo finance (#2597)
Thomas Kaul1b7e3a1e4731
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2269513132..16535e46f3 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### Added+- Added support to import activities by `isin` in the _Yahoo Finance_ service- Added a new tag with the major version to the docker image on _Docker Hub_### Changeddiff --git a/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.ts b/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.tsindex 8731e709c0..d46af66a7e 100644--- a/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.ts+++ b/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.ts@@ -10,6 +10,7 @@ import {Prisma,SymbolProfile} from '@prisma/client';+import { isISIN } from 'class-validator';import { countries } from 'countries-list';import yahooFinance from 'yahoo-finance2';import type { Price } from 'yahoo-finance2/dist/esm/src/modules/quoteSummary-iface';@@ -156,7 +157,20 @@ export class YahooFinanceDataEnhancerService implements DataEnhancerInterface {const response: Partial<SymbolProfile> = {};try {- const symbol = this.convertToYahooFinanceSymbol(aSymbol);+ let symbol = aSymbol;++ if (isISIN(symbol)) {+ try {+ const { quotes } = await yahooFinance.search(symbol);++ if (quotes.length === 1) {+ symbol = quotes[0].symbol;+ }+ } catch {}+ } else {+ symbol = this.convertToYahooFinanceSymbol(symbol);+ }+const assetProfile = await yahooFinance.quoteSummary(symbol, {modules: ['price', 'summaryProfile', 'topHoldings']});@@ -176,7 +190,7 @@ export class YahooFinanceDataEnhancerService implements DataEnhancerInterface {shortName: assetProfile.price.shortName,symbol: assetProfile.price.symbol});- response.symbol = aSymbol;+ response.symbol = assetProfile.price.symbol;if (assetSubClass === AssetSubClass.MUTUALFUND) {response.sectors = [];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.tsindex 16d48be8ed..2f69448f91 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@@ -30,7 +30,7 @@ export class YahooFinanceService implements DataProviderInterface {public async getAssetProfile(aSymbol: string): Promise<Partial<SymbolProfile>> {- const { assetClass, assetSubClass, currency, name } =+ const { assetClass, assetSubClass, currency, name, symbol } =await this.yahooFinanceDataEnhancerService.getAssetProfile(aSymbol);return {@@ -38,8 +38,8 @@ export class YahooFinanceService implements DataProviderInterface {assetSubClass,currency,name,- dataSource: this.getName(),- symbol: aSymbol+ symbol,+ dataSource: this.getName()};}diff --git a/test/import/ok.csv b/test/import/ok.csvindex 6f47c707a7..9f334da156 100644--- a/test/import/ok.csv+++ b/test/import/ok.csv@@ -3,4 +3,4 @@ Date,Code,DataSource,Currency,Price,Quantity,Action,Fee,Note16-09-2021,MSFT,YAHOO,USD,298.580,5,buy,19.00,My first order π€17/11/2021,MSFT,YAHOO,USD,0.62,5,dividend,0.00,01.01.2022,Penthouse Apartment,MANUAL,USD,500000.0,1,item,0.00,-20500606,MSFT,YAHOO,USD,0.00,0,buy,0.00,+20500606,US5949181045,YAHOO,USD,0.00,0,buy,0.00,diff --git a/test/import/ok.json b/test/import/ok.jsonindex 8803c9d08d..0af285500c 100644--- a/test/import/ok.json+++ b/test/import/ok.json@@ -24,7 +24,7 @@"currency": "USD","dataSource": "YAHOO","date": "2050-06-05T22:00:00.000Z",- "symbol": "MSFT"+ "symbol": "US5949181045"},{"accountId": null,