diff --git a/CHANGELOG.md b/CHANGELOG.md index 226951313..16535e46f 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_ ### Changed diff --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.ts index 8731e709c..d46af66a7 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 = {}; 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.ts index 16d48be8e..2f69448f9 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> { - 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.csv index 6f47c707a..9f334da15 100644 --- a/test/import/ok.csv +++ b/test/import/ok.csv @@ -3,4 +3,4 @@ Date,Code,DataSource,Currency,Price,Quantity,Action,Fee,Note 16-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.json index 8803c9d08..0af285500 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,