Skip to content

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

Bugfix/convert g bp to gbp in yahoo finance service (#301)

Thomas Kaulc71a4c078eaa
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4fb619d471..47ed33d500 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed the node engine version mismatch in `package.json`
- Fixed an issue on the buy date in the position detail dialog
+- Fixed an issue with the currency inconsistency in the _Yahoo Finance_ service (convert from `GBp` to `GBP`)
## 1.39.0 - 16.08.2021
diff --git a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts
index 3d0b8e7e58..9b744468b9 100644
--- a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts
+++ b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts
@@ -10,6 +10,7 @@ import { Granularity } from '@ghostfolio/common/types';
import { Injectable } from '@nestjs/common';
import { AssetClass, Currency, DataSource } from '@prisma/client';
import * as bent from 'bent';
+import Big from 'big.js';
import { format } from 'date-fns';
import * as yahooFinance from 'yahoo-finance';
@@ -72,6 +73,16 @@ export class YahooFinanceService implements DataProviderInterface {
name: value.price?.longName || value.price?.shortName || symbol
};
+ if (value.price?.currency === 'GBp') {
+ // Convert GBp (pence) to GBP
+ response[symbol].currency = Currency.GBP;
+ response[symbol].marketPrice = new Big(
+ value.price?.regularMarketPrice ?? 0
+ )
+ .div(100)
+ .toNumber();
+ }
+
const url = value.summaryProfile?.website;
if (url) {
response[symbol].url = url;
diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.ts
index d99b039c6f..cfbbcd603e 100644
--- a/libs/common/src/lib/helper.ts
+++ b/libs/common/src/lib/helper.ts
@@ -102,18 +102,8 @@ export function isRakutenRapidApiSymbol(aSymbol = '') {
return aSymbol === 'GF.FEAR_AND_GREED_INDEX';
}
-export function parseCurrency(aString: string): Currency {
- if (aString?.toLowerCase() === 'chf') {
- return Currency.CHF;
- } else if (aString?.toLowerCase() === 'eur') {
- return Currency.EUR;
- } else if (aString?.toLowerCase() === 'gbp') {
- return Currency.GBP;
- } else if (aString?.toLowerCase() === 'usd') {
- return Currency.USD;
- }
-
- return undefined;
+export function parseCurrency(aCurrency: string): Currency {
+ return Currency[aCurrency];
}
export function resetHours(aDate: Date) {