From a2498a54a6ac213637bfb08c2ac0df4fbdd2aa6a Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 30 Nov 2025 09:18:55 +0100 Subject: [PATCH] Bugfix/countries in FMP service (#6005) * Introduce countries mapping * Update changelog --- CHANGELOG.md | 4 ++++ .../financial-modeling-prep.service.ts | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb145bb14..f60d2434c 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 - Extended the _Storybook_ stories of the portfolio proportion chart component by a story using percentage values +### Fixed + +- Improved the country weightings in the _Financial Modeling Prep_ service + ## 2.220.0 - 2025-11-29 ### Changed diff --git a/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts b/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts index 6fe928d7a..fe8c4ecd6 100644 --- a/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts +++ b/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts @@ -44,6 +44,12 @@ import { @Injectable() export class FinancialModelingPrepService implements DataProviderInterface { + private static countriesMapping = { + 'Korea (the Republic of)': 'South Korea', + 'Russian Federation': 'Russia', + 'Taiwan (Province of China)': 'Taiwan' + }; + private apiKey: string; public constructor( @@ -121,12 +127,19 @@ export class FinancialModelingPrepService implements DataProviderInterface { } ).then((res) => res.json()); - response.countries = etfCountryWeightings.map( - ({ country: countryName, weightPercentage }) => { + response.countries = etfCountryWeightings + .filter(({ country: countryName }) => { + return countryName.toLowerCase() !== 'other'; + }) + .map(({ country: countryName, weightPercentage }) => { let countryCode: string; for (const [code, country] of Object.entries(countries)) { - if (country.name === countryName) { + if ( + country.name === countryName || + country.name === + FinancialModelingPrepService.countriesMapping[countryName] + ) { countryCode = code; break; } @@ -136,8 +149,7 @@ export class FinancialModelingPrepService implements DataProviderInterface { code: countryCode, weight: parseFloat(weightPercentage.slice(0, -1)) / 100 }; - } - ); + }); const etfHoldings = await fetch( `${this.getUrl({ version: 'stable' })}/etf/holdings?symbol=${symbol}&apikey=${this.apiKey}`,