|
|
@ -1,8 +1,9 @@
|
|
|
|
|
|
|
|
import { isCrypto, isRakutenRapidApi } from '@ghostfolio/helper';
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { MarketData } from '@prisma/client';
|
|
|
|
import { MarketData } from '@prisma/client';
|
|
|
|
import { format } from 'date-fns';
|
|
|
|
import { format } from 'date-fns';
|
|
|
|
import { isCrypto, isRakutenRapidApi } from 'libs/helper/src';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { ConfigurationService } from './configuration.service';
|
|
|
|
import { AlphaVantageService } from './data-provider/alpha-vantage/alpha-vantage.service';
|
|
|
|
import { AlphaVantageService } from './data-provider/alpha-vantage/alpha-vantage.service';
|
|
|
|
import { RakutenRapidApiService } from './data-provider/rakuten-rapid-api/rakuten-rapid-api.service';
|
|
|
|
import { RakutenRapidApiService } from './data-provider/rakuten-rapid-api/rakuten-rapid-api.service';
|
|
|
|
import { YahooFinanceService } from './data-provider/yahoo-finance/yahoo-finance.service';
|
|
|
|
import { YahooFinanceService } from './data-provider/yahoo-finance/yahoo-finance.service';
|
|
|
@ -17,10 +18,11 @@ import { PrismaService } from './prisma.service';
|
|
|
|
@Injectable()
|
|
|
|
@Injectable()
|
|
|
|
export class DataProviderService implements DataProviderInterface {
|
|
|
|
export class DataProviderService implements DataProviderInterface {
|
|
|
|
public constructor(
|
|
|
|
public constructor(
|
|
|
|
private alphaVantageService: AlphaVantageService,
|
|
|
|
private readonly alphaVantageService: AlphaVantageService,
|
|
|
|
|
|
|
|
private readonly configurationService: ConfigurationService,
|
|
|
|
private prisma: PrismaService,
|
|
|
|
private prisma: PrismaService,
|
|
|
|
private rakutenRapidApiService: RakutenRapidApiService,
|
|
|
|
private readonly rakutenRapidApiService: RakutenRapidApiService,
|
|
|
|
private yahooFinanceService: YahooFinanceService
|
|
|
|
private readonly yahooFinanceService: YahooFinanceService
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
this.rakutenRapidApiService.setPrisma(this.prisma);
|
|
|
|
this.rakutenRapidApiService.setPrisma(this.prisma);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -107,7 +109,10 @@ export class DataProviderService implements DataProviderInterface {
|
|
|
|
if (aSymbols.length === 1) {
|
|
|
|
if (aSymbols.length === 1) {
|
|
|
|
const symbol = aSymbols[0];
|
|
|
|
const symbol = aSymbols[0];
|
|
|
|
|
|
|
|
|
|
|
|
if (isCrypto(symbol)) {
|
|
|
|
if (
|
|
|
|
|
|
|
|
isCrypto(symbol) &&
|
|
|
|
|
|
|
|
this.configurationService.get('ALPHA_VANTAGE_API_KEY')
|
|
|
|
|
|
|
|
) {
|
|
|
|
// Merge data from Yahoo with data from Alpha Vantage
|
|
|
|
// Merge data from Yahoo with data from Alpha Vantage
|
|
|
|
const dataOfAlphaVantage = await this.alphaVantageService.getHistorical(
|
|
|
|
const dataOfAlphaVantage = await this.alphaVantageService.getHistorical(
|
|
|
|
[symbol],
|
|
|
|
[symbol],
|
|
|
@ -122,7 +127,10 @@ export class DataProviderService implements DataProviderInterface {
|
|
|
|
...dataOfAlphaVantage[symbol]
|
|
|
|
...dataOfAlphaVantage[symbol]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} else if (isRakutenRapidApi(symbol)) {
|
|
|
|
} else if (
|
|
|
|
|
|
|
|
isRakutenRapidApi(symbol) &&
|
|
|
|
|
|
|
|
this.configurationService.get('RAKUTEN_RAPID_API_KEY')
|
|
|
|
|
|
|
|
) {
|
|
|
|
const dataOfRakutenRapidApi = await this.rakutenRapidApiService.getHistorical(
|
|
|
|
const dataOfRakutenRapidApi = await this.rakutenRapidApiService.getHistorical(
|
|
|
|
[symbol],
|
|
|
|
[symbol],
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|