diff --git a/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.module.ts b/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.module.ts index 657e81d17..a6136e395 100644 --- a/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.module.ts +++ b/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.module.ts @@ -26,6 +26,7 @@ import { GhostfolioService } from './ghostfolio.service'; @Module({ controllers: [GhostfolioController], imports: [ + CurrencyModule, CryptocurrencyModule, DataProviderModule, MarketDataModule, diff --git a/apps/api/src/services/cryptocurrency/cryptocurrency.service.ts b/apps/api/src/services/cryptocurrency/cryptocurrency.service.ts index b814fc186..4aa46d15c 100644 --- a/apps/api/src/services/cryptocurrency/cryptocurrency.service.ts +++ b/apps/api/src/services/cryptocurrency/cryptocurrency.service.ts @@ -1,5 +1,3 @@ -import { DEFAULT_CURRENCY } from '@ghostfolio/common/config'; - import { Injectable } from '@nestjs/common'; const cryptocurrencies = require('../../assets/cryptocurrencies/cryptocurrencies.json'); @@ -10,12 +8,10 @@ export class CryptocurrencyService { private combinedCryptocurrencies: string[]; public isCryptocurrency(aSymbol = '') { - const cryptocurrencySymbol = aSymbol.substring(0, aSymbol.length - 3); - - return ( - aSymbol.endsWith(DEFAULT_CURRENCY) && - this.getCryptocurrencies().includes(cryptocurrencySymbol) - ); + const cryptocurrencySymbol = aSymbol.includes('-') + ? aSymbol.split('-')[0] + : aSymbol; + return this.getCryptocurrencies().includes(cryptocurrencySymbol); } private getCryptocurrencies() { diff --git a/apps/api/src/services/data-provider/data-provider.module.ts b/apps/api/src/services/data-provider/data-provider.module.ts index 71b54f01e..03f11e395 100644 --- a/apps/api/src/services/data-provider/data-provider.module.ts +++ b/apps/api/src/services/data-provider/data-provider.module.ts @@ -1,6 +1,7 @@ import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module'; import { CryptocurrencyModule } from '@ghostfolio/api/services/cryptocurrency/cryptocurrency.module'; +import { CurrencyModule } from '@ghostfolio/api/services/currency/currency.module'; import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; import { CoinGeckoService } from '@ghostfolio/api/services/data-provider/coingecko/coingecko.service'; import { EodHistoricalDataService } from '@ghostfolio/api/services/data-provider/eod-historical-data/eod-historical-data.service'; @@ -24,6 +25,7 @@ import { DataProviderService } from './data-provider.service'; @Module({ imports: [ ConfigurationModule, + CurrencyModule, CryptocurrencyModule, DataEnhancerModule, MarketDataModule, 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 27da18ab0..1e16e51c0 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 @@ -1,4 +1,5 @@ import { CryptocurrencyService } from '@ghostfolio/api/services/cryptocurrency/cryptocurrency.service'; +import { CurrencyService } from '@ghostfolio/api/services/currency/currency.service'; import { YahooFinanceDataEnhancerService } from '@ghostfolio/api/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service'; import { DataProviderInterface, @@ -11,7 +12,6 @@ import { IDataProviderHistoricalResponse, IDataProviderResponse } from '@ghostfolio/api/services/interfaces/interfaces'; -import { DEFAULT_CURRENCY } from '@ghostfolio/common/config'; import { DATE_FORMAT } from '@ghostfolio/common/helper'; import { DataProviderInfo, @@ -33,6 +33,7 @@ import { Quote } from 'yahoo-finance2/dist/esm/src/modules/quote'; @Injectable() export class YahooFinanceService implements DataProviderInterface { public constructor( + private readonly currencyService: CurrencyService, private readonly cryptocurrencyService: CryptocurrencyService, private readonly yahooFinanceDataEnhancerService: YahooFinanceDataEnhancerService ) {} @@ -247,21 +248,16 @@ export class YahooFinanceService implements DataProviderInterface { .filter(({ quoteType, symbol }) => { return ( (quoteType === 'CRYPTOCURRENCY' && - this.cryptocurrencyService.isCryptocurrency( - symbol.replace( - new RegExp(`-${DEFAULT_CURRENCY}$`), - DEFAULT_CURRENCY - ) - )) || + this.currencyService.getCurrencies().some((currency) => { + return this.cryptocurrencyService.isCryptocurrency( + symbol.replace(new RegExp(`-${currency}$`), '') + ); + })) || quoteTypes.includes(quoteType) ); }) .filter(({ quoteType, symbol }) => { - if (quoteType === 'CRYPTOCURRENCY') { - // Only allow cryptocurrencies in base currency to avoid having redundancy in the database. - // Transactions need to be converted manually to the base currency before - return symbol.includes(DEFAULT_CURRENCY); - } else if (quoteType === 'FUTURE') { + if (quoteType === 'FUTURE') { // Allow GC=F, but not MGC=F return symbol.length === 4; }