|
|
@ -5,20 +5,18 @@ import {
|
|
|
|
IDataProviderHistoricalResponse,
|
|
|
|
IDataProviderHistoricalResponse,
|
|
|
|
IDataProviderResponse
|
|
|
|
IDataProviderResponse
|
|
|
|
} from '@ghostfolio/api/services/interfaces/interfaces';
|
|
|
|
} from '@ghostfolio/api/services/interfaces/interfaces';
|
|
|
|
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
|
|
|
|
|
|
|
|
import { ghostfolioFearAndGreedIndexSymbol } from '@ghostfolio/common/config';
|
|
|
|
import { ghostfolioFearAndGreedIndexSymbol } from '@ghostfolio/common/config';
|
|
|
|
import { DATE_FORMAT, getToday, getYesterday } from '@ghostfolio/common/helper';
|
|
|
|
import { DATE_FORMAT, getYesterday } from '@ghostfolio/common/helper';
|
|
|
|
import { Granularity } from '@ghostfolio/common/types';
|
|
|
|
import { Granularity } from '@ghostfolio/common/types';
|
|
|
|
import { Injectable, Logger } from '@nestjs/common';
|
|
|
|
import { Injectable, Logger } from '@nestjs/common';
|
|
|
|
import { DataSource, SymbolProfile } from '@prisma/client';
|
|
|
|
import { DataSource, SymbolProfile } from '@prisma/client';
|
|
|
|
import bent from 'bent';
|
|
|
|
import bent from 'bent';
|
|
|
|
import { format, subMonths, subWeeks, subYears } from 'date-fns';
|
|
|
|
import { format } from 'date-fns';
|
|
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
@Injectable()
|
|
|
|
export class RapidApiService implements DataProviderInterface {
|
|
|
|
export class RapidApiService implements DataProviderInterface {
|
|
|
|
public constructor(
|
|
|
|
public constructor(
|
|
|
|
private readonly configurationService: ConfigurationService,
|
|
|
|
private readonly configurationService: ConfigurationService
|
|
|
|
private readonly prismaService: PrismaService
|
|
|
|
|
|
|
|
) {}
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
public canHandle(symbol: string) {
|
|
|
|
public canHandle(symbol: string) {
|
|
|
@ -47,41 +45,6 @@ export class RapidApiService implements DataProviderInterface {
|
|
|
|
if (symbol === ghostfolioFearAndGreedIndexSymbol) {
|
|
|
|
if (symbol === ghostfolioFearAndGreedIndexSymbol) {
|
|
|
|
const fgi = await this.getFearAndGreedIndex();
|
|
|
|
const fgi = await this.getFearAndGreedIndex();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// Rebuild historical data
|
|
|
|
|
|
|
|
// TODO: can be removed after all data from the last year has been gathered
|
|
|
|
|
|
|
|
// (introduced on 27.03.2021)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.prismaService.marketData.create({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
symbol,
|
|
|
|
|
|
|
|
dataSource: this.getName(),
|
|
|
|
|
|
|
|
date: subWeeks(getToday(), 1),
|
|
|
|
|
|
|
|
marketPrice: fgi.oneWeekAgo.value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.prismaService.marketData.create({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
symbol,
|
|
|
|
|
|
|
|
dataSource: this.getName(),
|
|
|
|
|
|
|
|
date: subMonths(getToday(), 1),
|
|
|
|
|
|
|
|
marketPrice: fgi.oneMonthAgo.value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.prismaService.marketData.create({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
symbol,
|
|
|
|
|
|
|
|
dataSource: this.getName(),
|
|
|
|
|
|
|
|
date: subYears(getToday(), 1),
|
|
|
|
|
|
|
|
marketPrice: fgi.oneYearAgo.value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
} catch {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
[ghostfolioFearAndGreedIndexSymbol]: {
|
|
|
|
[ghostfolioFearAndGreedIndexSymbol]: {
|
|
|
|
[format(getYesterday(), DATE_FORMAT)]: {
|
|
|
|
[format(getYesterday(), DATE_FORMAT)]: {
|
|
|
|