From 35b4aef06fd045d0d77d94e0f9fa70c1085f75f2 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 7 Jul 2024 18:23:51 +0200 Subject: [PATCH] Feature/improve market state logic for forex in eod historical data service (#3550) --- .../eod-historical-data.service.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 e16986cbb..1fe9e0ad1 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 @@ -246,7 +246,7 @@ export class EodHistoricalDataService implements DataProviderInterface { for (const { close, code, timestamp } of quotes) { let currency: string; - if (code.endsWith('.FOREX')) { + if (this.isForex(code)) { currency = this.convertFromEodSymbol(code)?.replace( DEFAULT_CURRENCY, '' @@ -272,7 +272,10 @@ export class EodHistoricalDataService implements DataProviderInterface { currency, dataSource: this.getName(), marketPrice: close, - marketState: isToday(new Date(timestamp * 1000)) ? 'open' : 'closed' + marketState: + this.isForex(code) || isToday(new Date(timestamp * 1000)) + ? 'open' + : 'closed' }; } else { Logger.error( @@ -311,7 +314,7 @@ export class EodHistoricalDataService implements DataProviderInterface { items: searchResult .filter(({ currency, symbol }) => { // Remove 'NA' currency and exchange rates - return currency?.length === 3 && !symbol.endsWith('.FOREX'); + return currency?.length === 3 && !this.isForex(symbol); }) .map( ({ @@ -349,7 +352,7 @@ export class EodHistoricalDataService implements DataProviderInterface { private convertFromEodSymbol(aEodSymbol: string) { let symbol = aEodSymbol; - if (symbol.endsWith('.FOREX')) { + if (this.isForex(symbol)) { symbol = symbol.replace('GBX', 'GBp'); symbol = symbol.replace('.FOREX', ''); } @@ -451,6 +454,10 @@ export class EodHistoricalDataService implements DataProviderInterface { return searchResult; } + private isForex(aCode: string) { + return aCode?.endsWith('.FOREX') || false; + } + private parseAssetClass({ Exchange, Type