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

* Improve validation of non-numeric numbers

* Update changelog
pull/2917/head
Thomas Kaul 8 months ago committed by GitHub
parent 1dd5e9c787
commit b39c97ab9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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/), 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). 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 ## 2.43.1 - 2024-01-23
### Added ### Added

@ -22,6 +22,7 @@ import {
} from '@prisma/client'; } from '@prisma/client';
import { addDays, format, isSameDay, isToday } from 'date-fns'; import { addDays, format, isSameDay, isToday } from 'date-fns';
import got from 'got'; import got from 'got';
import { isNumber } from 'lodash';
@Injectable() @Injectable()
export class EodHistoricalDataService implements DataProviderInterface { export class EodHistoricalDataService implements DataProviderInterface {
@ -144,10 +145,17 @@ export class EodHistoricalDataService implements DataProviderInterface {
).json<any>(); ).json<any>();
return response.reduce( return response.reduce(
(result, historicalItem, index, array) => { (result, { close, date }, index, array) => {
result[this.convertFromEodSymbol(symbol)][historicalItem.date] = { if (isNumber(close)) {
marketPrice: historicalItem.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; return result;
}, },
@ -232,14 +240,23 @@ export class EodHistoricalDataService implements DataProviderInterface {
return lookupItem.symbol === code; return lookupItem.symbol === code;
})?.currency; })?.currency;
result[this.convertFromEodSymbol(code)] = { if (isNumber(close)) {
currency: result[this.convertFromEodSymbol(code)] = {
currency ?? currency:
this.convertFromEodSymbol(code)?.replace(DEFAULT_CURRENCY, ''), currency ??
dataSource: DataSource.EOD_HISTORICAL_DATA, this.convertFromEodSymbol(code)?.replace(DEFAULT_CURRENCY, ''),
marketPrice: close, dataSource: this.getName(),
marketState: isToday(new Date(timestamp * 1000)) ? 'open' : 'closed' 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; return result;
}, },

Loading…
Cancel
Save