Bugfix/convert g bp to gbp in yahoo finance service (#301)
* Fix currency inconsistency in the yahoo finance service (GBp to GBP) * Update changelog
This commit is contained in:
parent
e17b217032
commit
c71a4c078e
@ -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 the node engine version mismatch in `package.json`
|
||||||
- Fixed an issue on the buy date in the position detail dialog
|
- 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
|
## 1.39.0 - 16.08.2021
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import { Granularity } from '@ghostfolio/common/types';
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { AssetClass, Currency, DataSource } from '@prisma/client';
|
import { AssetClass, Currency, DataSource } from '@prisma/client';
|
||||||
import * as bent from 'bent';
|
import * as bent from 'bent';
|
||||||
|
import Big from 'big.js';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import * as yahooFinance from 'yahoo-finance';
|
import * as yahooFinance from 'yahoo-finance';
|
||||||
|
|
||||||
@ -72,6 +73,16 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
name: value.price?.longName || value.price?.shortName || symbol
|
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;
|
const url = value.summaryProfile?.website;
|
||||||
if (url) {
|
if (url) {
|
||||||
response[symbol].url = url;
|
response[symbol].url = url;
|
||||||
|
@ -102,18 +102,8 @@ export function isRakutenRapidApiSymbol(aSymbol = '') {
|
|||||||
return aSymbol === 'GF.FEAR_AND_GREED_INDEX';
|
return aSymbol === 'GF.FEAR_AND_GREED_INDEX';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseCurrency(aString: string): Currency {
|
export function parseCurrency(aCurrency: string): Currency {
|
||||||
if (aString?.toLowerCase() === 'chf') {
|
return Currency[aCurrency];
|
||||||
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 resetHours(aDate: Date) {
|
export function resetHours(aDate: Date) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user