From 7ec033577f493df40a7f5748a419d261a34bb7c8 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 18 Mar 2023 10:34:50 +0100 Subject: [PATCH] Feature/extend trackinsight data enhancer by isin (#1793) * Extend data enhancer by isin * Update changelog --- CHANGELOG.md | 1 + .../trackinsight/trackinsight.service.ts | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5c8890c6..fc037328d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Extended the _Trackinsight_ data enhancer for asset profile data by `isin` - Improved the language localization for _Gather Data_ ### Fixed diff --git a/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts b/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts index 8ebdb1dba..4e76d7ed4 100644 --- a/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts +++ b/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts @@ -7,7 +7,7 @@ import bent from 'bent'; const getJSON = bent('json'); export class TrackinsightDataEnhancerService implements DataEnhancerInterface { - private static baseUrl = 'https://data.trackinsight.com/holdings'; + private static baseUrl = 'https://data.trackinsight.com'; private static countries = require('countries-list/dist/countries.json'); private static countriesMapping = { 'Russian Federation': 'Russia' @@ -32,17 +32,29 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface { return response; } - const result = await getJSON( - `${TrackinsightDataEnhancerService.baseUrl}/${symbol}.json` + const profile = await getJSON( + `${TrackinsightDataEnhancerService.baseUrl}/data-api/funds/${symbol}.json` + ).catch(() => { + return {}; + }); + + const isin = profile.isin?.split(';')?.[0]; + + if (isin) { + response.isin = isin; + } + + const holdings = await getJSON( + `${TrackinsightDataEnhancerService.baseUrl}/holdings/${symbol}.json` ).catch(() => { return getJSON( - `${TrackinsightDataEnhancerService.baseUrl}/${ - symbol.split('.')[0] + `${TrackinsightDataEnhancerService.baseUrl}/holdings/${ + symbol.split('.')?.[0] }.json` ); }); - if (result.weight < 0.95) { + if (holdings?.weight < 0.95) { // Skip if data is inaccurate return response; } @@ -52,7 +64,9 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface { (response.countries as unknown as Country[]).length === 0 ) { response.countries = []; - for (const [name, value] of Object.entries(result.countries)) { + for (const [name, value] of Object.entries( + holdings?.countries ?? {} + )) { let countryCode: string; for (const [key, country] of Object.entries( @@ -80,7 +94,9 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface { (response.sectors as unknown as Sector[]).length === 0 ) { response.sectors = []; - for (const [name, value] of Object.entries(result.sectors)) { + for (const [name, value] of Object.entries( + holdings?.sectors ?? {} + )) { response.sectors.push({ name: TrackinsightDataEnhancerService.sectorsMapping[name] ?? name, weight: value.weight