From 418581587afda903a6f1c05140c2dce0c7797dd5 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 19 Mar 2026 19:31:31 +0100 Subject: [PATCH] Task/implement OnModuleInit interface in data provider services (#6449) * Implement OnModuleInit interface --- .../alpha-vantage/alpha-vantage.service.ts | 10 +++++++--- .../data-provider/coingecko/coingecko.service.ts | 12 +++++++----- .../eod-historical-data.service.ts | 10 +++++++--- .../financial-modeling-prep.service.ts | 10 +++++++--- 4 files changed, 28 insertions(+), 14 deletions(-) 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 6030e62d4..40b45a115 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 d0d96acac..d5ed69d06 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 cd20fca44..8c718108c 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 2b4193af5..27391130e 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' );