Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/refactor data gathering items (#4032)
Thomas Kaul190bb4b6fbaa
diff --git a/apps/api/src/app/portfolio/current-rate.service.ts b/apps/api/src/app/portfolio/current-rate.service.tsindex cd19948269..ab7bf2ebfd 100644--- a/apps/api/src/app/portfolio/current-rate.service.ts+++ b/apps/api/src/app/portfolio/current-rate.service.ts@@ -52,27 +52,24 @@ export class CurrentRateService {.then((dataResultProvider) => {const result: GetValueObject[] = [];- for (const dataGatheringItem of dataGatheringItems) {- if (- dataResultProvider?.[dataGatheringItem.symbol]?.dataProviderInfo- ) {+ for (const { dataSource, symbol } of dataGatheringItems) {+ if (dataResultProvider?.[symbol]?.dataProviderInfo) {dataProviderInfos.push(- dataResultProvider[dataGatheringItem.symbol].dataProviderInfo+ dataResultProvider[symbol].dataProviderInfo);}- if (dataResultProvider?.[dataGatheringItem.symbol]?.marketPrice) {+ if (dataResultProvider?.[symbol]?.marketPrice) {result.push({- dataSource: dataGatheringItem.dataSource,+ dataSource,+ symbol,date: today,- marketPrice:- dataResultProvider?.[dataGatheringItem.symbol]?.marketPrice,- symbol: dataGatheringItem.symbol+ marketPrice: dataResultProvider?.[symbol]?.marketPrice});} else {quoteErrors.push({- dataSource: dataGatheringItem.dataSource,- symbol: dataGatheringItem.symbol+ dataSource,+ symbol});}}diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.tsindex d4018686c9..15ca227e93 100644--- a/apps/api/src/app/portfolio/portfolio.service.ts+++ b/apps/api/src/app/portfolio/portfolio.service.ts@@ -413,15 +413,16 @@ export class PortfolioService {);}- const dataGatheringItems = positions.map(({ dataSource, symbol }) => {+ const assetProfileIdentifiers = positions.map(({ dataSource, symbol }) => {return {dataSource,symbol};});- const symbolProfiles =- await this.symbolProfileService.getSymbolProfiles(dataGatheringItems);+ const symbolProfiles = await this.symbolProfileService.getSymbolProfiles(+ assetProfileIdentifiers+ );const symbolProfileMap: { [symbol: string]: EnhancedSymbolProfile } = {};for (const symbolProfile of symbolProfiles) {@@ -848,7 +849,7 @@ export class PortfolioService {if (isEmpty(historicalData)) {try {historicalData = await this.dataProviderService.getHistoricalRaw({- dataGatheringItems: [+ assetProfileIdentifiers: [{ dataSource: DataSource.YAHOO, symbol: aSymbol }],from: portfolioStart,@@ -953,7 +954,7 @@ export class PortfolioService {return !quantity.eq(0);});- const dataGatheringItems = positions.map(({ dataSource, symbol }) => {+ const assetProfileIdentifiers = positions.map(({ dataSource, symbol }) => {return {dataSource,symbol@@ -961,7 +962,10 @@ export class PortfolioService {});const [dataProviderResponses, symbolProfiles] = await Promise.all([- this.dataProviderService.getQuotes({ user, items: dataGatheringItems }),+ this.dataProviderService.getQuotes({+ user,+ items: assetProfileIdentifiers+ }),this.symbolProfileService.getSymbolProfiles(positions.map(({ dataSource, symbol }) => {return { dataSource, symbol };diff --git a/apps/api/src/app/symbol/symbol.service.ts b/apps/api/src/app/symbol/symbol.service.tsindex ae864e2fcc..56befb9b66 100644--- a/apps/api/src/app/symbol/symbol.service.ts+++ b/apps/api/src/app/symbol/symbol.service.ts@@ -86,7 +86,7 @@ export class SymbolService {try {historicalData = await this.dataProviderService.getHistoricalRaw({- dataGatheringItems: [{ dataSource, symbol }],+ assetProfileIdentifiers: [{ dataSource, symbol }],from: date,to: date});diff --git a/apps/api/src/services/data-provider/data-provider.service.ts b/apps/api/src/services/data-provider/data-provider.service.tsindex bf23f96c1e..c8a7422d0e 100644--- a/apps/api/src/services/data-provider/data-provider.service.ts+++ b/apps/api/src/services/data-provider/data-provider.service.ts@@ -91,11 +91,11 @@ export class DataProviderService {const promises = [];- for (const [dataSource, dataGatheringItems] of Object.entries(+ for (const [dataSource, assetProfileIdentifiers] of Object.entries(itemsGroupedByDataSource)) {- const symbols = dataGatheringItems.map((dataGatheringItem) => {- return dataGatheringItem.symbol;+ const symbols = assetProfileIdentifiers.map(({ symbol }) => {+ return symbol;});for (const symbol of symbols) {@@ -242,11 +242,11 @@ export class DataProviderService {}public async getHistoricalRaw({- dataGatheringItems,+ assetProfileIdentifiers,from,to}: {- dataGatheringItems: AssetProfileIdentifier[];+ assetProfileIdentifiers: AssetProfileIdentifier[];from: Date;to: Date;}): Promise<{@@ -255,25 +255,32 @@ export class DataProviderService {for (const { currency, rootCurrency } of DERIVED_CURRENCIES) {if (this.hasCurrency({- dataGatheringItems,+ assetProfileIdentifiers,currency: `${DEFAULT_CURRENCY}${currency}`})) {// Skip derived currency- dataGatheringItems = dataGatheringItems.filter(({ symbol }) => {- return symbol !== `${DEFAULT_CURRENCY}${currency}`;- });+ assetProfileIdentifiers = assetProfileIdentifiers.filter(+ ({ symbol }) => {+ return symbol !== `${DEFAULT_CURRENCY}${currency}`;+ }+ );// Add root currency- dataGatheringItems.push({+ assetProfileIdentifiers.push({dataSource: this.getDataSourceForExchangeRates(),symbol: `${DEFAULT_CURRENCY}${rootCurrency}`});}}- dataGatheringItems = uniqWith(dataGatheringItems, (obj1, obj2) => {- return obj1.dataSource === obj2.dataSource && obj1.symbol === obj2.symbol;- });+ assetProfileIdentifiers = uniqWith(+ assetProfileIdentifiers,+ (obj1, obj2) => {+ return (+ obj1.dataSource === obj2.dataSource && obj1.symbol === obj2.symbol+ );+ }+ );const result: {[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };@@ -283,7 +290,7 @@ export class DataProviderService {data: { [date: string]: IDataProviderHistoricalResponse };symbol: string;}>[] = [];- for (const { dataSource, symbol } of dataGatheringItems) {+ for (const { dataSource, symbol } of assetProfileIdentifiers) {const dataProvider = this.getDataProvider(dataSource);if (dataProvider.canHandle(symbol)) {if (symbol === `${DEFAULT_CURRENCY}USX`) {@@ -418,7 +425,7 @@ export class DataProviderService {const promises: Promise<any>[] = [];- for (const [dataSource, dataGatheringItems] of Object.entries(+ for (const [dataSource, assetProfileIdentifiers] of Object.entries(itemsGroupedByDataSource)) {const dataProvider = this.getDataProvider(DataSource[dataSource]);@@ -431,7 +438,7 @@ export class DataProviderService {continue;}- const symbols = dataGatheringItems+ const symbols = assetProfileIdentifiers.filter(({ symbol }) => {return !isDerivedCurrency(getCurrencyFromSymbol(symbol));})@@ -634,13 +641,13 @@ export class DataProviderService {}private hasCurrency({- currency,- dataGatheringItems+ assetProfileIdentifiers,+ currency}: {+ assetProfileIdentifiers: AssetProfileIdentifier[];currency: string;- dataGatheringItems: AssetProfileIdentifier[];}) {- return dataGatheringItems.some(({ dataSource, symbol }) => {+ return assetProfileIdentifiers.some(({ dataSource, symbol }) => {return (dataSource === this.getDataSourceForExchangeRates() &&symbol === currencydiff --git a/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts b/apps/api/src/services/queues/data-gathering/data-gathering.processor.tsindex dc8cc5996f..eedad7475e 100644--- a/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts+++ b/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts@@ -89,7 +89,7 @@ export class DataGatheringProcessor {);const historicalData = await this.dataProviderService.getHistoricalRaw({- dataGatheringItems: [{ dataSource, symbol }],+ assetProfileIdentifiers: [{ dataSource, symbol }],from: currentDate,to: new Date()});diff --git a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts b/apps/api/src/services/queues/data-gathering/data-gathering.service.tsindex 72b8ac7167..b79b2a0985 100644--- a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts+++ b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts@@ -122,7 +122,7 @@ export class DataGatheringService {}) {try {const historicalData = await this.dataProviderService.getHistoricalRaw({- dataGatheringItems: [{ dataSource, symbol }],+ assetProfileIdentifiers: [{ dataSource, symbol }],from: date,to: date});