diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 4f96d2716..01f1edefa 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -42,7 +42,6 @@ import type { AccountWithValue, DateRange, GroupBy, - Market, OrderWithAccount, RequestWithUser, UserWithSettings @@ -84,7 +83,9 @@ import { import { PortfolioCalculator } from './portfolio-calculator'; import { RulesService } from './rules.service'; +const asiaPacificMarkets = require('../../assets/countries/asia-pacific-markets.json'); const developedMarkets = require('../../assets/countries/developed-markets.json'); +const europeMarkets = require('../../assets/countries/europe-markets.json'); const emergingMarkets = require('../../assets/countries/emerging-markets.json'); @Injectable() @@ -538,11 +539,19 @@ export class PortfolioService { const symbolProfile = symbolProfileMap[item.symbol]; const dataProviderResponse = dataProviderResponses[item.symbol]; - const markets: { [key in Market]: number } = { + const markets: PortfolioPosition['markets'] = { developedMarkets: 0, emergingMarkets: 0, otherMarkets: 0 }; + const marketsAdvanced: PortfolioPosition['marketsAdvanced'] = { + asiaPacific: 0, + emergingMarkets: 0, + europe: 0, + japan: 0, + northAmerica: 0, + otherMarkets: 0 + }; for (const country of symbolProfile.countries) { if (developedMarkets.includes(country.code)) { @@ -558,10 +567,39 @@ export class PortfolioService { .plus(country.weight) .toNumber(); } + + if (country.code === 'JP') { + marketsAdvanced.japan = new Big(marketsAdvanced.japan) + .plus(country.weight) + .toNumber(); + } else if (country.code === 'CA' || country.code === 'US') { + marketsAdvanced.northAmerica = new Big(marketsAdvanced.northAmerica) + .plus(country.weight) + .toNumber(); + } else if (asiaPacificMarkets.includes(country.code)) { + marketsAdvanced.asiaPacific = new Big(marketsAdvanced.asiaPacific) + .plus(country.weight) + .toNumber(); + } else if (emergingMarkets.includes(country.code)) { + marketsAdvanced.emergingMarkets = new Big( + marketsAdvanced.emergingMarkets + ) + .plus(country.weight) + .toNumber(); + } else if (europeMarkets.includes(country.code)) { + marketsAdvanced.europe = new Big(marketsAdvanced.europe) + .plus(country.weight) + .toNumber(); + } else { + marketsAdvanced.otherMarkets = new Big(marketsAdvanced.otherMarkets) + .plus(country.weight) + .toNumber(); + } } holdings[item.symbol] = { markets, + marketsAdvanced, allocationInPercentage: filteredValueInBaseCurrency.eq(0) ? 0 : value.div(filteredValueInBaseCurrency).toNumber(), diff --git a/apps/api/src/assets/countries/asia-pacific-markets.json b/apps/api/src/assets/countries/asia-pacific-markets.json new file mode 100644 index 000000000..adbb0750e --- /dev/null +++ b/apps/api/src/assets/countries/asia-pacific-markets.json @@ -0,0 +1 @@ +["AU", "HK", "NZ", "SG"] diff --git a/apps/api/src/assets/countries/europe-markets.json b/apps/api/src/assets/countries/europe-markets.json new file mode 100644 index 000000000..26eb2176c --- /dev/null +++ b/apps/api/src/assets/countries/europe-markets.json @@ -0,0 +1,19 @@ +[ + "AT", + "BE", + "CH", + "DE", + "DK", + "ES", + "FI", + "FR", + "GB", + "IE", + "IL", + "IT", + "LU", + "NL", + "NO", + "PT", + "SE" +] diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts index 8696d6ac2..2d1b0c412 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts @@ -18,7 +18,7 @@ import { User } from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; -import { Market } from '@ghostfolio/common/types'; +import { Market, MarketAdvanced } from '@ghostfolio/common/types'; import { translate } from '@ghostfolio/ui/i18n'; import { Account, AssetClass, DataSource, Platform } from '@prisma/client'; import { isNumber } from 'lodash'; @@ -54,6 +54,13 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { public markets: { [key in Market]: { name: string; value: number }; }; + public marketsAdvanced: { + [key in MarketAdvanced]: { + id: MarketAdvanced; + name: string; + value: number; + }; + }; public placeholder = ''; public platforms: { [id: string]: Pick & { @@ -235,6 +242,38 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { value: undefined } }; + this.marketsAdvanced = { + asiaPacific: { + id: 'asiaPacific', + name: translate('Asia-Pacific'), + value: 0 + }, + emergingMarkets: { + id: 'emergingMarkets', + name: translate('Emerging Markets'), + value: 0 + }, + europe: { + id: 'europe', + name: translate('Europe'), + value: 0 + }, + japan: { + id: 'japan', + name: translate('Japan'), + value: 0 + }, + northAmerica: { + id: 'northAmerica', + name: translate('North America'), + value: 0 + }, + otherMarkets: { + id: 'otherMarkets', + name: translate('Other Markets'), + value: 0 + } + }; this.platforms = {}; this.portfolioDetails = { accounts: {}, @@ -324,6 +363,19 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { this.markets.otherMarkets.value += position.markets.otherMarkets * position.valueInBaseCurrency; + this.marketsAdvanced.asiaPacific.value += + position.marketsAdvanced.asiaPacific * position.valueInBaseCurrency; + this.marketsAdvanced.emergingMarkets.value += + position.marketsAdvanced.emergingMarkets * + position.valueInBaseCurrency; + this.marketsAdvanced.europe.value += + position.marketsAdvanced.europe * position.valueInBaseCurrency; + this.marketsAdvanced.japan.value += + position.marketsAdvanced.japan * position.valueInBaseCurrency; + this.marketsAdvanced.northAmerica.value += + position.marketsAdvanced.northAmerica * + position.valueInBaseCurrency; + for (const country of position.countries) { const { code, continent, name, weight } = country; diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.html b/apps/client/src/app/pages/portfolio/allocations/allocations-page.html index ab78c1930..90a5dd3c9 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.html +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.html @@ -174,7 +174,7 @@ By CountryBy Market @@ -250,6 +248,30 @@
+
+ + + By Country + + + + + +
diff --git a/apps/client/src/locales/messages.de.xlf b/apps/client/src/locales/messages.de.xlf index c3f0c9bb1..1d47fc389 100644 --- a/apps/client/src/locales/messages.de.xlf +++ b/apps/client/src/locales/messages.de.xlf @@ -1954,7 +1954,7 @@ Nach Konto apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 256 + 278 @@ -2002,7 +2002,7 @@ Nach Land apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 177 + 255 @@ -2010,7 +2010,7 @@ Regionen apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 203 + 201 apps/client/src/app/pages/public/public-page.html @@ -2650,7 +2650,7 @@ Entwickelte Länder apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 226 + 224 apps/client/src/app/pages/public/public-page.html @@ -2662,7 +2662,7 @@ Schwellenländer apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 235 + 233 apps/client/src/app/pages/public/public-page.html @@ -2674,7 +2674,7 @@ Andere Länder apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 244 + 242 apps/client/src/app/pages/public/public-page.html @@ -2782,7 +2782,7 @@ Filtern nach Konto oder Tag... apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts - 139 + 141 apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -3078,7 +3078,7 @@ libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 373 + 384 @@ -3086,11 +3086,11 @@ Keine Daten verfügbar libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 375 + 386 libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 388 + 399 @@ -3870,7 +3870,7 @@ Nach ETF-Anbieter apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 276 + 298 @@ -7061,6 +7061,14 @@ 19 + + By Market + Nach Markt + + apps/client/src/app/pages/portfolio/allocations/allocations-page.html + 177 + + diff --git a/apps/client/src/locales/messages.es.xlf b/apps/client/src/locales/messages.es.xlf index f1c7d62e1..e1e5b4efa 100644 --- a/apps/client/src/locales/messages.es.xlf +++ b/apps/client/src/locales/messages.es.xlf @@ -1955,7 +1955,7 @@ Por cuenta apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 256 + 278 @@ -2003,7 +2003,7 @@ Por país apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 177 + 255 @@ -2011,7 +2011,7 @@ Regiones apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 203 + 201 apps/client/src/app/pages/public/public-page.html @@ -2571,7 +2571,7 @@ Mercados desarrollados apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 226 + 224 apps/client/src/app/pages/public/public-page.html @@ -2619,7 +2619,7 @@ Otros mercados apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 244 + 242 apps/client/src/app/pages/public/public-page.html @@ -2631,7 +2631,7 @@ Mercados emergentes apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 235 + 233 apps/client/src/app/pages/public/public-page.html @@ -2775,7 +2775,7 @@ Filtrar por cuenta o etiqueta... apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts - 139 + 141 apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -3079,7 +3079,7 @@ libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 373 + 384 @@ -3087,11 +3087,11 @@ Sin datos disponibles libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 375 + 386 libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 388 + 399 @@ -3871,7 +3871,7 @@ By ETF Provider apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 276 + 298 @@ -7062,6 +7062,14 @@ 19 + + By Market + By Market + + apps/client/src/app/pages/portfolio/allocations/allocations-page.html + 177 + + diff --git a/apps/client/src/locales/messages.fr.xlf b/apps/client/src/locales/messages.fr.xlf index 734ff1835..9590c0b1a 100644 --- a/apps/client/src/locales/messages.fr.xlf +++ b/apps/client/src/locales/messages.fr.xlf @@ -2526,7 +2526,7 @@ Filtrer par compte ou étiquette... apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts - 139 + 141 apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -2558,7 +2558,7 @@ Par Compte apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 256 + 278 @@ -2606,7 +2606,7 @@ Par Pays apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 177 + 255 @@ -2614,7 +2614,7 @@ Régions apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 203 + 201 apps/client/src/app/pages/public/public-page.html @@ -2626,7 +2626,7 @@ Marchés Développés apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 226 + 224 apps/client/src/app/pages/public/public-page.html @@ -2638,7 +2638,7 @@ Marchés Émergents apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 235 + 233 apps/client/src/app/pages/public/public-page.html @@ -2650,7 +2650,7 @@ Autres marchés apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 244 + 242 apps/client/src/app/pages/public/public-page.html @@ -3146,7 +3146,7 @@ libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 373 + 384 @@ -3330,11 +3330,11 @@ Pas de données disponibles libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 375 + 386 libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 388 + 399 @@ -3870,7 +3870,7 @@ Par Émetteur d'ETF apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 276 + 298 @@ -7061,6 +7061,14 @@ 19 + + By Market + By Market + + apps/client/src/app/pages/portfolio/allocations/allocations-page.html + 177 + + diff --git a/apps/client/src/locales/messages.it.xlf b/apps/client/src/locales/messages.it.xlf index 2286a61f9..61cb44694 100644 --- a/apps/client/src/locales/messages.it.xlf +++ b/apps/client/src/locales/messages.it.xlf @@ -1955,7 +1955,7 @@ Per account apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 256 + 278 @@ -2003,7 +2003,7 @@ Per paese apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 177 + 255 @@ -2011,7 +2011,7 @@ Regioni apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 203 + 201 apps/client/src/app/pages/public/public-page.html @@ -2571,7 +2571,7 @@ Mercati sviluppati apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 226 + 224 apps/client/src/app/pages/public/public-page.html @@ -2619,7 +2619,7 @@ Altri mercati apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 244 + 242 apps/client/src/app/pages/public/public-page.html @@ -2631,7 +2631,7 @@ Mercati emergenti apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 235 + 233 apps/client/src/app/pages/public/public-page.html @@ -2775,7 +2775,7 @@ Filtra per account o tag... apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts - 139 + 141 apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -3079,7 +3079,7 @@ libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 373 + 384 @@ -3087,11 +3087,11 @@ No data available libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 375 + 386 libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 388 + 399 @@ -3871,7 +3871,7 @@ By ETF Provider apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 276 + 298 @@ -7062,6 +7062,14 @@ 19 + + By Market + By Market + + apps/client/src/app/pages/portfolio/allocations/allocations-page.html + 177 + + diff --git a/apps/client/src/locales/messages.nl.xlf b/apps/client/src/locales/messages.nl.xlf index b58da7468..bd3cc1332 100644 --- a/apps/client/src/locales/messages.nl.xlf +++ b/apps/client/src/locales/messages.nl.xlf @@ -1954,7 +1954,7 @@ Per rekening apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 256 + 278 @@ -2002,7 +2002,7 @@ Per land apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 177 + 255 @@ -2010,7 +2010,7 @@ Regio's apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 203 + 201 apps/client/src/app/pages/public/public-page.html @@ -2570,7 +2570,7 @@ Ontwikkelde markten apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 226 + 224 apps/client/src/app/pages/public/public-page.html @@ -2618,7 +2618,7 @@ Andere markten apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 244 + 242 apps/client/src/app/pages/public/public-page.html @@ -2630,7 +2630,7 @@ Opkomende markten apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 235 + 233 apps/client/src/app/pages/public/public-page.html @@ -2774,7 +2774,7 @@ Filter op account of tag... apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts - 139 + 141 apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -3078,7 +3078,7 @@ libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 373 + 384 @@ -3086,11 +3086,11 @@ Geen gegevens beschikbaar libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 375 + 386 libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 388 + 399 @@ -3870,7 +3870,7 @@ By ETF Provider apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 276 + 298 @@ -7061,6 +7061,14 @@ 19 + + By Market + By Market + + apps/client/src/app/pages/portfolio/allocations/allocations-page.html + 177 + + diff --git a/apps/client/src/locales/messages.pt.xlf b/apps/client/src/locales/messages.pt.xlf index d61c88809..d5563db9a 100644 --- a/apps/client/src/locales/messages.pt.xlf +++ b/apps/client/src/locales/messages.pt.xlf @@ -2446,7 +2446,7 @@ Filtrar por conta ou marcador... apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts - 139 + 141 apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -2478,7 +2478,7 @@ Por Conta apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 256 + 278 @@ -2526,7 +2526,7 @@ Por País apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 177 + 255 @@ -2534,7 +2534,7 @@ Regiões apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 203 + 201 apps/client/src/app/pages/public/public-page.html @@ -2546,7 +2546,7 @@ Mercados Desenvoldidos apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 226 + 224 apps/client/src/app/pages/public/public-page.html @@ -2558,7 +2558,7 @@ Mercados Emergentes apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 235 + 233 apps/client/src/app/pages/public/public-page.html @@ -2570,7 +2570,7 @@ Outros Mercados apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 244 + 242 apps/client/src/app/pages/public/public-page.html @@ -3010,7 +3010,7 @@ libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 373 + 384 @@ -3186,11 +3186,11 @@ Sem dados disponíveis libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 375 + 386 libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 388 + 399 @@ -3870,7 +3870,7 @@ Por Prestador de ETF apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 276 + 298 @@ -7061,6 +7061,14 @@ 19 + + By Market + By Market + + apps/client/src/app/pages/portfolio/allocations/allocations-page.html + 177 + + diff --git a/apps/client/src/locales/messages.xlf b/apps/client/src/locales/messages.xlf index 0b84474c5..8d8e9816b 100644 --- a/apps/client/src/locales/messages.xlf +++ b/apps/client/src/locales/messages.xlf @@ -1792,7 +1792,7 @@ By Account apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 256 + 278 @@ -1834,14 +1834,14 @@ By Country apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 177 + 255 Regions apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 203 + 201 apps/client/src/app/pages/public/public-page.html @@ -2344,7 +2344,7 @@ Developed Markets apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 226 + 224 apps/client/src/app/pages/public/public-page.html @@ -2388,7 +2388,7 @@ Other Markets apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 244 + 242 apps/client/src/app/pages/public/public-page.html @@ -2399,7 +2399,7 @@ Emerging Markets apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 235 + 233 apps/client/src/app/pages/public/public-page.html @@ -2528,7 +2528,7 @@ Filter by account or tag... apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts - 139 + 141 apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -2785,11 +2785,11 @@ No data available libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 375 + 386 libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 388 + 399 @@ -2807,7 +2807,7 @@ libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts - 373 + 384 @@ -3487,7 +3487,7 @@ By ETF Provider apps/client/src/app/pages/portfolio/allocations/allocations-page.html - 276 + 298 @@ -6623,6 +6623,13 @@ 184 + + By Market + + apps/client/src/app/pages/portfolio/allocations/allocations-page.html + 177 + + diff --git a/libs/common/src/lib/interfaces/portfolio-position.interface.ts b/libs/common/src/lib/interfaces/portfolio-position.interface.ts index a398c8c90..76334ea0b 100644 --- a/libs/common/src/lib/interfaces/portfolio-position.interface.ts +++ b/libs/common/src/lib/interfaces/portfolio-position.interface.ts @@ -1,6 +1,6 @@ import { AssetClass, AssetSubClass, DataSource, Tag } from '@prisma/client'; -import { Market, MarketState } from '../types'; +import { Market, MarketAdvanced, MarketState } from '../types'; import { Country } from './country.interface'; import { Sector } from './sector.interface'; @@ -20,6 +20,7 @@ export interface PortfolioPosition { marketChangePercent?: number; marketPrice: number; markets?: { [key in Market]: number }; + marketsAdvanced?: { [key in MarketAdvanced]: number }; marketState: MarketState; name: string; netPerformance: number; diff --git a/libs/common/src/lib/types/index.ts b/libs/common/src/lib/types/index.ts index 063bea05d..2af65d404 100644 --- a/libs/common/src/lib/types/index.ts +++ b/libs/common/src/lib/types/index.ts @@ -5,6 +5,7 @@ import type { ColorScheme } from './color-scheme.type'; import type { DateRange } from './date-range.type'; import type { Granularity } from './granularity.type'; import type { GroupBy } from './group-by.type'; +import type { MarketAdvanced } from './market-advanced.type'; import type { MarketDataPreset } from './market-data-preset.type'; import type { MarketState } from './market-state.type'; import type { Market } from './market.type'; @@ -24,6 +25,7 @@ export type { Granularity, GroupBy, Market, + MarketAdvanced, MarketDataPreset, MarketState, OrderWithAccount, diff --git a/libs/common/src/lib/types/market-advanced.type.ts b/libs/common/src/lib/types/market-advanced.type.ts new file mode 100644 index 000000000..0d30a8ea1 --- /dev/null +++ b/libs/common/src/lib/types/market-advanced.type.ts @@ -0,0 +1,7 @@ +export type MarketAdvanced = + | 'asiaPacific' + | 'emergingMarkets' + | 'europe' + | 'japan' + | 'northAmerica' + | 'otherMarkets'; diff --git a/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts b/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts index ec0a63eea..dfb2a2c92 100644 --- a/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts +++ b/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts @@ -90,7 +90,7 @@ export class PortfolioProportionChartComponent [symbol: string]: { color?: string; name: string; - subCategory: { [symbol: string]: { value: Big } }; + subCategory?: { [symbol: string]: { value: Big } }; value: Big; }; } = {}; @@ -99,65 +99,76 @@ export class PortfolioProportionChartComponent [UNKNOWN_KEY]: `rgba(${getTextColor(this.colorScheme)}, 0.12)` }; - Object.keys(this.positions).forEach((symbol) => { - if (this.positions[symbol][this.keys[0]]?.toUpperCase()) { - if (chartData[this.positions[symbol][this.keys[0]].toUpperCase()]) { - chartData[this.positions[symbol][this.keys[0]].toUpperCase()].value = + if (this.keys.length > 0) { + Object.keys(this.positions).forEach((symbol) => { + if (this.positions[symbol][this.keys[0]]?.toUpperCase()) { + if (chartData[this.positions[symbol][this.keys[0]].toUpperCase()]) { chartData[ this.positions[symbol][this.keys[0]].toUpperCase() + ].value = chartData[ + this.positions[symbol][this.keys[0]].toUpperCase() ].value.plus(this.positions[symbol].value); - if ( - chartData[this.positions[symbol][this.keys[0]].toUpperCase()] - .subCategory[this.positions[symbol][this.keys[1]]] - ) { - chartData[ - this.positions[symbol][this.keys[0]].toUpperCase() - ].subCategory[this.positions[symbol][this.keys[1]]].value = + if ( + chartData[this.positions[symbol][this.keys[0]].toUpperCase()] + .subCategory[this.positions[symbol][this.keys[1]]] + ) { + chartData[ + this.positions[symbol][this.keys[0]].toUpperCase() + ].subCategory[this.positions[symbol][this.keys[1]]].value = + chartData[ + this.positions[symbol][this.keys[0]].toUpperCase() + ].subCategory[this.positions[symbol][this.keys[1]]].value.plus( + this.positions[symbol].value + ); + } else { chartData[ this.positions[symbol][this.keys[0]].toUpperCase() - ].subCategory[this.positions[symbol][this.keys[1]]].value.plus( - this.positions[symbol].value - ); + ].subCategory[ + this.positions[symbol][this.keys[1]] ?? UNKNOWN_KEY + ] = { value: new Big(this.positions[symbol].value) }; + } } else { - chartData[ - this.positions[symbol][this.keys[0]].toUpperCase() - ].subCategory[this.positions[symbol][this.keys[1]] ?? UNKNOWN_KEY] = - { value: new Big(this.positions[symbol].value) }; + chartData[this.positions[symbol][this.keys[0]].toUpperCase()] = { + name: this.positions[symbol][this.keys[0]], + subCategory: {}, + value: new Big(this.positions[symbol].value ?? 0) + }; + + if (this.positions[symbol][this.keys[1]]) { + chartData[ + this.positions[symbol][this.keys[0]].toUpperCase() + ].subCategory = { + [this.positions[symbol][this.keys[1]]]: { + value: new Big(this.positions[symbol].value) + } + }; + } } } else { - chartData[this.positions[symbol][this.keys[0]].toUpperCase()] = { - name: this.positions[symbol][this.keys[0]], - subCategory: {}, - value: new Big(this.positions[symbol].value ?? 0) - }; - - if (this.positions[symbol][this.keys[1]]) { - chartData[ - this.positions[symbol][this.keys[0]].toUpperCase() - ].subCategory = { - [this.positions[symbol][this.keys[1]]]: { - value: new Big(this.positions[symbol].value) - } + if (chartData[UNKNOWN_KEY]) { + chartData[UNKNOWN_KEY].value = chartData[UNKNOWN_KEY].value.plus( + this.positions[symbol].value + ); + } else { + chartData[UNKNOWN_KEY] = { + name: this.positions[symbol].name, + subCategory: this.keys[1] + ? { [this.keys[1]]: { value: new Big(0) } } + : undefined, + value: new Big(this.positions[symbol].value) }; } } - } else { - if (chartData[UNKNOWN_KEY]) { - chartData[UNKNOWN_KEY].value = chartData[UNKNOWN_KEY].value.plus( - this.positions[symbol].value - ); - } else { - chartData[UNKNOWN_KEY] = { - name: this.positions[symbol].name, - subCategory: this.keys[1] - ? { [this.keys[1]]: { value: new Big(0) } } - : undefined, - value: new Big(this.positions[symbol].value) - }; - } - } - }); + }); + } else { + Object.keys(this.positions).forEach((symbol) => { + chartData[symbol] = { + name: this.positions[symbol].name, + value: new Big(this.positions[symbol].value) + }; + }); + } let chartDataSorted = Object.entries(chartData) .sort((a, b) => {