Skip to content

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

Task/implement OnModuleInit interface in data provider services (#6449)

Thomas Kaul418581587afd
diff --git a/apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts b/apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts
index 6030e62d47..40b45a115b 100644
--- a/apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts
+++ b/apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts
@@ -16,7 +16,7 @@ import {
LookupResponse
} from '@ghostfolio/common/interfaces';
-import { Injectable } from '@nestjs/common';
+import { Injectable, OnModuleInit } from '@nestjs/common';
import { DataSource, SymbolProfile } from '@prisma/client';
import Alphavantage from 'alphavantage';
import { format, isAfter, isBefore, parse } from 'date-fns';
@@ -24,12 +24,16 @@ import { format, isAfter, isBefore, parse } from 'date-fns';
import { AlphaVantageHistoricalResponse } from './interfaces/interfaces';
@Injectable()
-export class AlphaVantageService implements DataProviderInterface {
+export class AlphaVantageService
+ implements DataProviderInterface, OnModuleInit
+{
public alphaVantage;
public constructor(
private readonly configurationService: ConfigurationService
- ) {
+ ) {}
+
+ public onModuleInit() {
this.alphaVantage = Alphavantage({
key: this.configurationService.get('API_KEY_ALPHA_VANTAGE')
});
diff --git a/apps/api/src/services/data-provider/coingecko/coingecko.service.ts b/apps/api/src/services/data-provider/coingecko/coingecko.service.ts
index d0d96acacd..d5ed69d060 100644
--- a/apps/api/src/services/data-provider/coingecko/coingecko.service.ts
+++ b/apps/api/src/services/data-provider/coingecko/coingecko.service.ts
@@ -17,7 +17,7 @@ import {
LookupResponse
} from '@ghostfolio/common/interfaces';
-import { Injectable, Logger } from '@nestjs/common';
+import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import {
AssetClass,
AssetSubClass,
@@ -27,13 +27,15 @@ import {
import { format, fromUnixTime, getUnixTime } from 'date-fns';
@Injectable()
-export class CoinGeckoService implements DataProviderInterface {
- private readonly apiUrl: string;
- private readonly headers: HeadersInit = {};
+export class CoinGeckoService implements DataProviderInterface, OnModuleInit {
+ private apiUrl: string;
+ private headers: HeadersInit = {};
public constructor(
private readonly configurationService: ConfigurationService
- ) {
+ ) {}
+
+ public onModuleInit() {
const apiKeyDemo = this.configurationService.get('API_KEY_COINGECKO_DEMO');
const apiKeyPro = this.configurationService.get('API_KEY_COINGECKO_PRO');
diff --git a/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts b/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts
index cd20fca449..8c718108c2 100644
--- a/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts
+++ b/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts
@@ -22,7 +22,7 @@ import {
} from '@ghostfolio/common/interfaces';
import { MarketState } from '@ghostfolio/common/types';
-import { Injectable, Logger } from '@nestjs/common';
+import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import {
AssetClass,
AssetSubClass,
@@ -33,14 +33,18 @@ import { addDays, format, isSameDay, isToday } from 'date-fns';
import { isNumber } from 'lodash';
@Injectable()
-export class EodHistoricalDataService implements DataProviderInterface {
+export class EodHistoricalDataService
+ implements DataProviderInterface, OnModuleInit
+{
private apiKey: string;
private readonly URL = 'https://eodhistoricaldata.com/api';
public constructor(
private readonly configurationService: ConfigurationService,
private readonly symbolProfileService: SymbolProfileService
- ) {
+ ) {}
+
+ public onModuleInit() {
this.apiKey = this.configurationService.get('API_KEY_EOD_HISTORICAL_DATA');
}
diff --git a/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts b/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts
index 2b4193af53..27391130e1 100644
--- a/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts
+++ b/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts
@@ -23,7 +23,7 @@ import {
} from '@ghostfolio/common/interfaces';
import { MarketState } from '@ghostfolio/common/types';
-import { Injectable, Logger } from '@nestjs/common';
+import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import {
AssetClass,
AssetSubClass,
@@ -44,7 +44,9 @@ import {
import { uniqBy } from 'lodash';
@Injectable()
-export class FinancialModelingPrepService implements DataProviderInterface {
+export class FinancialModelingPrepService
+ implements DataProviderInterface, OnModuleInit
+{
private static countriesMapping = {
'Korea (the Republic of)': 'South Korea',
'Russian Federation': 'Russia',
@@ -57,7 +59,9 @@ export class FinancialModelingPrepService implements DataProviderInterface {
private readonly configurationService: ConfigurationService,
private readonly cryptocurrencyService: CryptocurrencyService,
private readonly prismaService: PrismaService
- ) {
+ ) {}
+
+ public onModuleInit() {
this.apiKey = this.configurationService.get(
'API_KEY_FINANCIAL_MODELING_PREP'
);