Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/add support for custom cryptocurrencies defined in database (#6344)
Thomas Kaul8c88ce918fa9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4261653f2e..7609fa0e42 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Added+- Added support for custom cryptocurrencies defined in the database- Added support for the cryptocurrency _Sky_### Changeddiff --git a/apps/api/src/services/cryptocurrency/cryptocurrency.module.ts b/apps/api/src/services/cryptocurrency/cryptocurrency.module.tsindex 8820205ebb..e882f4da54 100644--- a/apps/api/src/services/cryptocurrency/cryptocurrency.module.ts+++ b/apps/api/src/services/cryptocurrency/cryptocurrency.module.ts@@ -1,9 +1,12 @@+import { PropertyModule } from '@ghostfolio/api/services/property/property.module';+import { Module } from '@nestjs/common';import { CryptocurrencyService } from './cryptocurrency.service';@Module({- providers: [CryptocurrencyService],- exports: [CryptocurrencyService]+ exports: [CryptocurrencyService],+ imports: [PropertyModule],+ providers: [CryptocurrencyService]})export class CryptocurrencyModule {}diff --git a/apps/api/src/services/cryptocurrency/cryptocurrency.service.ts b/apps/api/src/services/cryptocurrency/cryptocurrency.service.tsindex b814fc1861..933029ea2b 100644--- a/apps/api/src/services/cryptocurrency/cryptocurrency.service.ts+++ b/apps/api/src/services/cryptocurrency/cryptocurrency.service.ts@@ -1,31 +1,39 @@-import { DEFAULT_CURRENCY } from '@ghostfolio/common/config';+import { PropertyService } from '@ghostfolio/api/services/property/property.service';+import {+ DEFAULT_CURRENCY,+ PROPERTY_CUSTOM_CRYPTOCURRENCIES+} from '@ghostfolio/common/config';-import { Injectable } from '@nestjs/common';+import { Injectable, OnModuleInit } from '@nestjs/common';const cryptocurrencies = require('../../assets/cryptocurrencies/cryptocurrencies.json');const customCryptocurrencies = require('../../assets/cryptocurrencies/custom.json');@Injectable()-export class CryptocurrencyService {+export class CryptocurrencyService implements OnModuleInit {private combinedCryptocurrencies: string[];+ public constructor(private readonly propertyService: PropertyService) {}++ public async onModuleInit() {+ const customCryptocurrenciesFromDatabase =+ await this.propertyService.getByKey<Record<string, string>>(+ PROPERTY_CUSTOM_CRYPTOCURRENCIES+ );++ this.combinedCryptocurrencies = [+ ...Object.keys(cryptocurrencies),+ ...Object.keys(customCryptocurrencies),+ ...Object.keys(customCryptocurrenciesFromDatabase ?? {})+ ];+ }+public isCryptocurrency(aSymbol = '') {const cryptocurrencySymbol = aSymbol.substring(0, aSymbol.length - 3);return (aSymbol.endsWith(DEFAULT_CURRENCY) &&- this.getCryptocurrencies().includes(cryptocurrencySymbol)+ this.combinedCryptocurrencies.includes(cryptocurrencySymbol));}-- private getCryptocurrencies() {- if (!this.combinedCryptocurrencies) {- this.combinedCryptocurrencies = [- ...Object.keys(cryptocurrencies),- ...Object.keys(customCryptocurrencies)- ];- }-- return this.combinedCryptocurrencies;- }}diff --git a/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.spec.ts b/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.spec.tsindex c37a9fe3e8..9335d86d0c 100644--- a/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.spec.ts+++ b/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.spec.ts@@ -29,7 +29,7 @@ describe('YahooFinanceDataEnhancerService', () => {let yahooFinanceDataEnhancerService: YahooFinanceDataEnhancerService;beforeAll(async () => {- cryptocurrencyService = new CryptocurrencyService();+ cryptocurrencyService = new CryptocurrencyService(null);yahooFinanceDataEnhancerService = new YahooFinanceDataEnhancerService(cryptocurrencyServicediff --git a/libs/common/src/lib/config.ts b/libs/common/src/lib/config.tsindex b558ccc42f..eae1b73cd2 100644--- a/libs/common/src/lib/config.ts+++ b/libs/common/src/lib/config.ts@@ -199,6 +199,7 @@ export const PROPERTY_BETTER_UPTIME_MONITOR_ID = 'BETTER_UPTIME_MONITOR_ID';export const PROPERTY_COUNTRIES_OF_SUBSCRIBERS = 'COUNTRIES_OF_SUBSCRIBERS';export const PROPERTY_COUPONS = 'COUPONS';export const PROPERTY_CURRENCIES = 'CURRENCIES';+export const PROPERTY_CUSTOM_CRYPTOCURRENCIES = 'CUSTOM_CRYPTOCURRENCIES';export const PROPERTY_DATA_SOURCE_MAPPING = 'DATA_SOURCE_MAPPING';export const PROPERTY_DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER_MAX_REQUESTS ='DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER_MAX_REQUESTS';