From 4865aa1665ce4cba159875423a43d5f6cbe509fa Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 17 Sep 2024 20:15:16 +0200 Subject: [PATCH] Feature/add fallback in get quotes of eod historical data service (#3776) * Add fallback to previousClose in getQuotes() * Update changelog --- CHANGELOG.md | 1 + .../eod-historical-data.service.ts | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd2ec27a0..a3c1f6c4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the usability of the toggle component - Switched to the accounts endpoint in the holding detail dialog +- Added a fallback in the get quotes functionality of the _EOD Historical Data_ service ## 2.107.1 - 2024-09-12 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 cf2fd42de..8b2a1828b 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 @@ -18,6 +18,7 @@ import { } from '@ghostfolio/common/config'; import { DATE_FORMAT, isCurrency } from '@ghostfolio/common/helper'; import { DataProviderInfo } from '@ghostfolio/common/interfaces'; +import { MarketState } from '@ghostfolio/common/types'; import { Injectable, Logger } from '@nestjs/common'; import { @@ -229,7 +230,12 @@ export class EodHistoricalDataService implements DataProviderInterface { } ).json(); - const quotes = + const quotes: { + close: number; + code: string; + previousClose: number; + timestamp: number; + }[] = eodHistoricalDataSymbols.length === 1 ? [realTimeResponse] : realTimeResponse; @@ -243,7 +249,7 @@ export class EodHistoricalDataService implements DataProviderInterface { }) ); - for (const { close, code, timestamp } of quotes) { + for (const { close, code, previousClose, timestamp } of quotes) { let currency: string; if (this.isForex(code)) { @@ -267,15 +273,21 @@ export class EodHistoricalDataService implements DataProviderInterface { } } - if (isNumber(close)) { + if (isNumber(close) || isNumber(previousClose)) { + const marketPrice: number = isNumber(close) ? close : previousClose; + let marketState: MarketState = 'closed'; + + if (this.isForex(code) || isToday(new Date(timestamp * 1000))) { + marketState = 'open'; + } else if (!isNumber(close)) { + marketState = 'delayed'; + } + response[this.convertFromEodSymbol(code)] = { currency, - dataSource: this.getName(), - marketPrice: close, - marketState: - this.isForex(code) || isToday(new Date(timestamp * 1000)) - ? 'open' - : 'closed' + marketPrice, + marketState, + dataSource: this.getName() }; } else { Logger.error(