Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Bugfix/improve validation for non numeric results in eod service (#2916)

Thomas Kaulb39c97ab9f0a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 60a8c7af1a..fe67a3d2c0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Fixed
+
+- Improved the validation for non-numeric results in the _EOD Historical Data_ service
+
## 2.43.1 - 2024-01-23
### 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 38b2e8a424..39457320fc 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
@@ -22,6 +22,7 @@ import {
} from '@prisma/client';
import { addDays, format, isSameDay, isToday } from 'date-fns';
import got from 'got';
+import { isNumber } from 'lodash';
@Injectable()
export class EodHistoricalDataService implements DataProviderInterface {
@@ -144,10 +145,17 @@ export class EodHistoricalDataService implements DataProviderInterface {
).json<any>();
return response.reduce(
- (result, historicalItem, index, array) => {
- result[this.convertFromEodSymbol(symbol)][historicalItem.date] = {
- marketPrice: historicalItem.close
- };
+ (result, { close, date }, index, array) => {
+ if (isNumber(close)) {
+ result[this.convertFromEodSymbol(symbol)][date] = {
+ marketPrice: close
+ };
+ } else {
+ Logger.error(
+ `Could not get historical market data for ${symbol} (${this.getName()}) at ${date}`,
+ 'EodHistoricalDataService'
+ );
+ }
return result;
},
@@ -232,14 +240,23 @@ export class EodHistoricalDataService implements DataProviderInterface {
return lookupItem.symbol === code;
})?.currency;
- result[this.convertFromEodSymbol(code)] = {
- currency:
- currency ??
- this.convertFromEodSymbol(code)?.replace(DEFAULT_CURRENCY, ''),
- dataSource: DataSource.EOD_HISTORICAL_DATA,
- marketPrice: close,
- marketState: isToday(new Date(timestamp * 1000)) ? 'open' : 'closed'
- };
+ if (isNumber(close)) {
+ result[this.convertFromEodSymbol(code)] = {
+ currency:
+ currency ??
+ this.convertFromEodSymbol(code)?.replace(DEFAULT_CURRENCY, ''),
+ dataSource: this.getName(),
+ marketPrice: close,
+ marketState: isToday(new Date(timestamp * 1000))
+ ? 'open'
+ : 'closed'
+ };
+ } else {
+ Logger.error(
+ `Could not get quote for ${this.convertFromEodSymbol(code)} (${this.getName()})`,
+ 'EodHistoricalDataService'
+ );
+ }
return result;
},