Browse Source

Increase fear and greed index to 90 days

pull/652/head
Thomas 3 years ago
parent
commit
e58a09df81
  1. 13
      apps/api/src/app/symbol/symbol.controller.ts
  2. 14
      apps/api/src/app/symbol/symbol.service.ts
  3. 3
      apps/client/src/app/components/home-market/home-market.component.ts
  4. 12
      apps/client/src/app/components/home-market/home-market.html
  5. 16
      apps/client/src/app/services/data.service.ts

13
apps/api/src/app/symbol/symbol.controller.ts

@ -1,17 +1,12 @@
import { IDataProviderHistoricalResponse } from '@ghostfolio/api/services/interfaces/interfaces';
import type { RequestWithUser } from '@ghostfolio/common/types';
import {
Controller,
DefaultValuePipe,
Get,
HttpException,
Inject,
Param,
ParseBoolPipe,
Query,
UseGuards
} from '@nestjs/common';
import { REQUEST } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport';
import { DataSource } from '@prisma/client';
import { StatusCodes, getReasonPhrase } from 'http-status-codes';
@ -23,10 +18,7 @@ import { SymbolService } from './symbol.service';
@Controller('symbol')
export class SymbolController {
public constructor(
private readonly symbolService: SymbolService,
@Inject(REQUEST) private readonly request: RequestWithUser
) {}
public constructor(private readonly symbolService: SymbolService) {}
/**
* Must be before /:symbol
@ -54,8 +46,7 @@ export class SymbolController {
public async getSymbolData(
@Param('dataSource') dataSource: DataSource,
@Param('symbol') symbol: string,
@Query('includeHistoricalData', new DefaultValuePipe(false), ParseBoolPipe)
includeHistoricalData: boolean
@Query('includeHistoricalData') includeHistoricalData?: number
): Promise<SymbolItem> {
if (!DataSource[dataSource]) {
throw new HttpException(

14
apps/api/src/app/symbol/symbol.service.ts

@ -5,7 +5,6 @@ import {
IDataProviderHistoricalResponse
} from '@ghostfolio/api/services/interfaces/interfaces';
import { MarketDataService } from '@ghostfolio/api/services/market-data.service';
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { DATE_FORMAT } from '@ghostfolio/common/helper';
import { Injectable, Logger } from '@nestjs/common';
import { DataSource } from '@prisma/client';
@ -18,25 +17,24 @@ import { SymbolItem } from './interfaces/symbol-item.interface';
export class SymbolService {
public constructor(
private readonly dataProviderService: DataProviderService,
private readonly marketDataService: MarketDataService,
private readonly prismaService: PrismaService
private readonly marketDataService: MarketDataService
) {}
public async get({
dataGatheringItem,
includeHistoricalData = false
includeHistoricalData
}: {
dataGatheringItem: IDataGatheringItem;
includeHistoricalData?: boolean;
includeHistoricalData?: number;
}): Promise<SymbolItem> {
const response = await this.dataProviderService.get([dataGatheringItem]);
const { currency, marketPrice } = response[dataGatheringItem.symbol] ?? {};
if (dataGatheringItem.dataSource && marketPrice) {
let historicalData: HistoricalDataItem[];
let historicalData: HistoricalDataItem[] = [];
if (includeHistoricalData) {
const days = 30;
if (includeHistoricalData > 0) {
const days = includeHistoricalData;
const marketData = await this.marketDataService.getRange({
dateQuery: { gte: subDays(new Date(), days) },

3
apps/client/src/app/components/home-market/home-market.component.ts

@ -16,6 +16,7 @@ import { takeUntil } from 'rxjs/operators';
templateUrl: './home-market.html'
})
export class HomeMarketComponent implements OnDestroy, OnInit {
public numberOfDays = 90;
public fearAndGreedIndex: number;
public hasPermissionToAccessFearAndGreedIndex: boolean;
public historicalData: HistoricalDataItem[];
@ -49,7 +50,7 @@ export class HomeMarketComponent implements OnDestroy, OnInit {
this.dataService
.fetchSymbolItem({
dataSource: DataSource.RAKUTEN,
includeHistoricalData: true,
includeHistoricalData: this.numberOfDays,
symbol: ghostfolioFearAndGreedIndexSymbol
})
.pipe(takeUntil(this.unsubscribeSubject))

12
apps/client/src/app/components/home-market/home-market.html

@ -1,18 +1,10 @@
<div
class="
align-items-center
container
d-flex
flex-grow-1
h-100
justify-content-center
w-100
"
class="align-items-center container d-flex flex-grow-1 h-100 justify-content-center w-100"
>
<div class="no-gutters row w-100">
<div class="col-xs-12 col-md-8 offset-md-2">
<div class="mb-2 text-center text-muted">
<small i18n>Last 30 Days</small>
<small i18n>Last {{ numberOfDays }} Days</small>
</div>
<gf-line-chart
class="mb-5"

16
apps/client/src/app/services/data.service.ts

@ -1,4 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { CreateAccessDto } from '@ghostfolio/api/app/access/create-access.dto';
import { CreateAccountDto } from '@ghostfolio/api/app/account/create-account.dto';
@ -138,15 +138,23 @@ export class DataService {
public fetchSymbolItem({
dataSource,
includeHistoricalData = false,
includeHistoricalData,
symbol
}: {
dataSource: DataSource;
includeHistoricalData?: boolean;
includeHistoricalData?: number;
symbol: string;
}) {
let params = new HttpParams();
if (includeHistoricalData) {
params = params.append('includeHistoricalData', includeHistoricalData);
}
console.log(params);
return this.http.get<SymbolItem>(`/api/symbol/${dataSource}/${symbol}`, {
params: { includeHistoricalData }
params
});
}

Loading…
Cancel
Save