|
@ -13,26 +13,18 @@ import { Inject, Injectable } from '@nestjs/common'; |
|
|
import { DataSource, MarketData } from '@prisma/client'; |
|
|
import { DataSource, MarketData } from '@prisma/client'; |
|
|
import { format } from 'date-fns'; |
|
|
import { format } from 'date-fns'; |
|
|
import { isEmpty } from 'lodash'; |
|
|
import { isEmpty } from 'lodash'; |
|
|
|
|
|
import { DataProviderInterface } from '@ghostfolio/api/services/data-provider/interfaces/data-provider.interface'; |
|
|
import { AlphaVantageService } from './alpha-vantage/alpha-vantage.service'; |
|
|
|
|
|
import { GhostfolioScraperApiService } from './ghostfolio-scraper-api/ghostfolio-scraper-api.service'; |
|
|
|
|
|
import { RakutenRapidApiService } from './rakuten-rapid-api/rakuten-rapid-api.service'; |
|
|
|
|
|
import { YahooFinanceService } from './yahoo-finance/yahoo-finance.service'; |
|
|
|
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
|
export class DataProviderService { |
|
|
export class DataProviderService { |
|
|
public constructor( |
|
|
public constructor( |
|
|
private readonly alphaVantageService: AlphaVantageService, |
|
|
|
|
|
private readonly configurationService: ConfigurationService, |
|
|
private readonly configurationService: ConfigurationService, |
|
|
@Inject('DataEnhancers') |
|
|
@Inject('DataEnhancers') |
|
|
private readonly dataEnhancers: DataEnhancerInterface[], |
|
|
private readonly dataEnhancers: DataEnhancerInterface[], |
|
|
private readonly ghostfolioScraperApiService: GhostfolioScraperApiService, |
|
|
@Inject('DataProviderInterfaces') |
|
|
private readonly prismaService: PrismaService, |
|
|
private readonly dataProviderInterfaces: DataProviderInterface[], |
|
|
private readonly rakutenRapidApiService: RakutenRapidApiService, |
|
|
private readonly prismaService: PrismaService |
|
|
private readonly yahooFinanceService: YahooFinanceService |
|
|
) {} |
|
|
) { |
|
|
|
|
|
this.rakutenRapidApiService?.setPrisma(this.prismaService); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async get(items: IDataGatheringItem[]): Promise<{ |
|
|
public async get(items: IDataGatheringItem[]): Promise<{ |
|
|
[symbol: string]: IDataProviderResponse; |
|
|
[symbol: string]: IDataProviderResponse; |
|
@ -204,17 +196,11 @@ export class DataProviderService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private getDataProvider(providerName: DataSource) { |
|
|
private getDataProvider(providerName: DataSource) { |
|
|
switch (providerName) { |
|
|
for (const dataProviderInterface of this.dataProviderInterfaces) { |
|
|
case DataSource.ALPHA_VANTAGE: |
|
|
if (dataProviderInterface.getName() === providerName) { |
|
|
return this.alphaVantageService; |
|
|
return dataProviderInterface; |
|
|
case DataSource.GHOSTFOLIO: |
|
|
} |
|
|
return this.ghostfolioScraperApiService; |
|
|
|
|
|
case DataSource.RAKUTEN: |
|
|
|
|
|
return this.rakutenRapidApiService; |
|
|
|
|
|
case DataSource.YAHOO: |
|
|
|
|
|
return this.yahooFinanceService; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new Error('No data provider has been found.'); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
throw new Error('No data provider has been found.'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|