Skip to content

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

Feature/improve market state logic for forex in eod historical data service (#3550)

Thomas Kaul35b4aef06fd0
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 e16986cbbe..1fe9e0ad10 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