From 737890005021aa7b657f47dce93174bfda392671 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 18 Apr 2023 20:31:33 +0200 Subject: [PATCH] Bugfix/fix currency inconsistency with GBX and GBp in eod historical data service (#1869) * Fix currency inconsistency (GBX vs. GBp) * Update changelog --- CHANGELOG.md | 4 +++ .../eod-historical-data.service.ts | 29 ++++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbbf6e608..e02ae4874 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 - Introduced the allocations by ETF provider chart on the allocations page +### Fixed + +- Fixed an issue with the currency inconsistency in the _EOD Historical Data_ service (convert from `GBX` to `GBp`) + ## 1.256.0 - 2023-04-17 ### Added diff --git a/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts b/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts index b0ef5735b..4f1113d3f 100644 --- a/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts +++ b/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts @@ -40,7 +40,7 @@ export class EodHistoricalDataService implements DataProviderInterface { return { assetClass: searchResult?.assetClass, assetSubClass: searchResult?.assetSubClass, - currency: searchResult?.currency, + currency: this.convertCurrency(searchResult?.currency), dataSource: this.getName(), isin: searchResult?.isin, name: searchResult?.name, @@ -147,7 +147,7 @@ export class EodHistoricalDataService implements DataProviderInterface { { close, code, timestamp } ) => { result[code] = { - currency: searchResponse?.items[0]?.currency, + currency: this.convertCurrency(searchResponse?.items[0]?.currency), dataSource: DataSource.EOD_HISTORICAL_DATA, marketPrice: close, marketState: isToday(new Date(timestamp * 1000)) ? 'open' : 'closed' @@ -184,16 +184,26 @@ export class EodHistoricalDataService implements DataProviderInterface { return { assetClass, assetSubClass, - currency, dataSource, name, - symbol + symbol, + currency: this.convertCurrency(currency) }; } ) }; } + private convertCurrency(aCurrency: string) { + let currency = aCurrency; + + if (currency === 'GBX') { + currency = 'GBp'; + } + + return currency; + } + private async getSearchResult(aQuery: string): Promise< (LookupItem & { assetClass: AssetClass; @@ -213,14 +223,7 @@ export class EodHistoricalDataService implements DataProviderInterface { const response = await get(); searchResult = response.map( - ({ - Code, - Currency: currency, - Exchange, - ISIN: isin, - Name: name, - Type - }) => { + ({ Code, Currency, Exchange, ISIN: isin, Name: name, Type }) => { const { assetClass, assetSubClass } = this.parseAssetClass({ Exchange, Type @@ -229,9 +232,9 @@ export class EodHistoricalDataService implements DataProviderInterface { return { assetClass, assetSubClass, - currency, isin, name, + currency: this.convertCurrency(Currency), dataSource: this.getName(), symbol: `${Code}.${Exchange}` };