Bugfix/improve validation for non numeric results in eod service (#2916)
* Improve validation of non-numeric numbers * Update changelog
This commit is contained in:
parent
1dd5e9c787
commit
b39c97ab9f
@ -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
|
||||
|
@ -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;
|
||||
|
||||
if (isNumber(close)) {
|
||||
result[this.convertFromEodSymbol(code)] = {
|
||||
currency:
|
||||
currency ??
|
||||
this.convertFromEodSymbol(code)?.replace(DEFAULT_CURRENCY, ''),
|
||||
dataSource: DataSource.EOD_HISTORICAL_DATA,
|
||||
dataSource: this.getName(),
|
||||
marketPrice: close,
|
||||
marketState: isToday(new Date(timestamp * 1000)) ? 'open' : 'closed'
|
||||
marketState: isToday(new Date(timestamp * 1000))
|
||||
? 'open'
|
||||
: 'closed'
|
||||
};
|
||||
} else {
|
||||
Logger.error(
|
||||
`Could not get quote for ${this.convertFromEodSymbol(code)} (${this.getName()})`,
|
||||
'EodHistoricalDataService'
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user