Browse Source

Feature/add support for custom cryptocurrencies defined in database (#6344)

* Add support for custom cryptocurrencies defined in database

* Update changelog
pull/6337/head
Thomas Kaul 2 weeks ago
committed by GitHub
parent
commit
8c88ce918f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 7
      apps/api/src/services/cryptocurrency/cryptocurrency.module.ts
  3. 34
      apps/api/src/services/cryptocurrency/cryptocurrency.service.ts
  4. 2
      apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.spec.ts
  5. 1
      libs/common/src/lib/config.ts

1
CHANGELOG.md

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Added support for custom cryptocurrencies defined in the database
- Added support for the cryptocurrency _Sky_ - Added support for the cryptocurrency _Sky_
### Changed ### Changed

7
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 { Module } from '@nestjs/common';
import { CryptocurrencyService } from './cryptocurrency.service'; import { CryptocurrencyService } from './cryptocurrency.service';
@Module({ @Module({
providers: [CryptocurrencyService], exports: [CryptocurrencyService],
exports: [CryptocurrencyService] imports: [PropertyModule],
providers: [CryptocurrencyService]
}) })
export class CryptocurrencyModule {} export class CryptocurrencyModule {}

34
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 cryptocurrencies = require('../../assets/cryptocurrencies/cryptocurrencies.json');
const customCryptocurrencies = require('../../assets/cryptocurrencies/custom.json'); const customCryptocurrencies = require('../../assets/cryptocurrencies/custom.json');
@Injectable() @Injectable()
export class CryptocurrencyService { export class CryptocurrencyService implements OnModuleInit {
private combinedCryptocurrencies: string[]; private combinedCryptocurrencies: string[];
public isCryptocurrency(aSymbol = '') { public constructor(private readonly propertyService: PropertyService) {}
const cryptocurrencySymbol = aSymbol.substring(0, aSymbol.length - 3);
return ( public async onModuleInit() {
aSymbol.endsWith(DEFAULT_CURRENCY) && const customCryptocurrenciesFromDatabase =
this.getCryptocurrencies().includes(cryptocurrencySymbol) await this.propertyService.getByKey<Record<string, string>>(
PROPERTY_CUSTOM_CRYPTOCURRENCIES
); );
}
private getCryptocurrencies() {
if (!this.combinedCryptocurrencies) {
this.combinedCryptocurrencies = [ this.combinedCryptocurrencies = [
...Object.keys(cryptocurrencies), ...Object.keys(cryptocurrencies),
...Object.keys(customCryptocurrencies) ...Object.keys(customCryptocurrencies),
...Object.keys(customCryptocurrenciesFromDatabase ?? {})
]; ];
} }
return this.combinedCryptocurrencies; public isCryptocurrency(aSymbol = '') {
const cryptocurrencySymbol = aSymbol.substring(0, aSymbol.length - 3);
return (
aSymbol.endsWith(DEFAULT_CURRENCY) &&
this.combinedCryptocurrencies.includes(cryptocurrencySymbol)
);
} }
} }

2
apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.spec.ts

@ -29,7 +29,7 @@ describe('YahooFinanceDataEnhancerService', () => {
let yahooFinanceDataEnhancerService: YahooFinanceDataEnhancerService; let yahooFinanceDataEnhancerService: YahooFinanceDataEnhancerService;
beforeAll(async () => { beforeAll(async () => {
cryptocurrencyService = new CryptocurrencyService(); cryptocurrencyService = new CryptocurrencyService(null);
yahooFinanceDataEnhancerService = new YahooFinanceDataEnhancerService( yahooFinanceDataEnhancerService = new YahooFinanceDataEnhancerService(
cryptocurrencyService cryptocurrencyService

1
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_COUNTRIES_OF_SUBSCRIBERS = 'COUNTRIES_OF_SUBSCRIBERS';
export const PROPERTY_COUPONS = 'COUPONS'; export const PROPERTY_COUPONS = 'COUPONS';
export const PROPERTY_CURRENCIES = 'CURRENCIES'; 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_SOURCE_MAPPING = 'DATA_SOURCE_MAPPING';
export const PROPERTY_DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER_MAX_REQUESTS = export const PROPERTY_DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER_MAX_REQUESTS =
'DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER_MAX_REQUESTS'; 'DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER_MAX_REQUESTS';

Loading…
Cancel
Save