mirror of https://github.com/ghostfolio/ghostfolio
				
				
			
				 11 changed files with 10 additions and 188 deletions
			
			
		@ -1,22 +0,0 @@ | 
				
			|||
import { Type } from '@prisma/client'; | 
				
			|||
import { IsISO8601, IsNumber, IsString } from 'class-validator'; | 
				
			|||
 | 
				
			|||
export class CreateOrderDto { | 
				
			|||
  @IsString() | 
				
			|||
  currency: string; | 
				
			|||
 | 
				
			|||
  @IsISO8601() | 
				
			|||
  date: string; | 
				
			|||
 | 
				
			|||
  @IsNumber() | 
				
			|||
  quantity: number; | 
				
			|||
 | 
				
			|||
  @IsString() | 
				
			|||
  symbol: string; | 
				
			|||
 | 
				
			|||
  @IsString() | 
				
			|||
  type: Type; | 
				
			|||
 | 
				
			|||
  @IsNumber() | 
				
			|||
  unitPrice: number; | 
				
			|||
} | 
				
			|||
@ -1,69 +0,0 @@ | 
				
			|||
import { baseCurrency, benchmarks } from '@ghostfolio/common/config'; | 
				
			|||
import { DATE_FORMAT } from '@ghostfolio/common/helper'; | 
				
			|||
import { isApiTokenAuthorized } from '@ghostfolio/common/permissions'; | 
				
			|||
import type { RequestWithUser } from '@ghostfolio/common/types'; | 
				
			|||
import { | 
				
			|||
  Body, | 
				
			|||
  Controller, | 
				
			|||
  Get, | 
				
			|||
  Headers, | 
				
			|||
  HttpException, | 
				
			|||
  Inject, | 
				
			|||
  Param, | 
				
			|||
  Post | 
				
			|||
} from '@nestjs/common'; | 
				
			|||
import { REQUEST } from '@nestjs/core'; | 
				
			|||
import { parse } from 'date-fns'; | 
				
			|||
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; | 
				
			|||
 | 
				
			|||
import { CreateOrderDto } from './create-order.dto'; | 
				
			|||
import { ExperimentalService } from './experimental.service'; | 
				
			|||
import { Data } from './interfaces/data.interface'; | 
				
			|||
 | 
				
			|||
@Controller('experimental') | 
				
			|||
export class ExperimentalController { | 
				
			|||
  public constructor( | 
				
			|||
    private readonly experimentalService: ExperimentalService, | 
				
			|||
    @Inject(REQUEST) private readonly request: RequestWithUser | 
				
			|||
  ) {} | 
				
			|||
 | 
				
			|||
  @Get('benchmarks') | 
				
			|||
  public async getBenchmarks( | 
				
			|||
    @Headers('Authorization') apiToken: string | 
				
			|||
  ): Promise<string[]> { | 
				
			|||
    if (!isApiTokenAuthorized(apiToken)) { | 
				
			|||
      throw new HttpException( | 
				
			|||
        getReasonPhrase(StatusCodes.FORBIDDEN), | 
				
			|||
        StatusCodes.FORBIDDEN | 
				
			|||
      ); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    return benchmarks.map(({ symbol }) => { | 
				
			|||
      return symbol; | 
				
			|||
    }); | 
				
			|||
  } | 
				
			|||
 | 
				
			|||
  @Get('benchmarks/:symbol') | 
				
			|||
  public async getBenchmark( | 
				
			|||
    @Headers('Authorization') apiToken: string, | 
				
			|||
    @Param('symbol') symbol: string | 
				
			|||
  ): Promise<{ date: Date; marketPrice: number }[]> { | 
				
			|||
    if (!isApiTokenAuthorized(apiToken)) { | 
				
			|||
      throw new HttpException( | 
				
			|||
        getReasonPhrase(StatusCodes.FORBIDDEN), | 
				
			|||
        StatusCodes.FORBIDDEN | 
				
			|||
      ); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    const marketData = await this.experimentalService.getBenchmark(symbol); | 
				
			|||
 | 
				
			|||
    if (marketData?.length === 0) { | 
				
			|||
      throw new HttpException( | 
				
			|||
        getReasonPhrase(StatusCodes.NOT_FOUND), | 
				
			|||
        StatusCodes.NOT_FOUND | 
				
			|||
      ); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    return marketData; | 
				
			|||
  } | 
				
			|||
} | 
				
			|||
@ -1,23 +0,0 @@ | 
				
			|||
import { AccountService } from '@ghostfolio/api/app/account/account.service'; | 
				
			|||
import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; | 
				
			|||
import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; | 
				
			|||
import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; | 
				
			|||
import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module'; | 
				
			|||
import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; | 
				
			|||
import { Module } from '@nestjs/common'; | 
				
			|||
 | 
				
			|||
import { ExperimentalController } from './experimental.controller'; | 
				
			|||
import { ExperimentalService } from './experimental.service'; | 
				
			|||
 | 
				
			|||
@Module({ | 
				
			|||
  imports: [ | 
				
			|||
    ConfigurationModule, | 
				
			|||
    DataProviderModule, | 
				
			|||
    ExchangeRateDataModule, | 
				
			|||
    RedisCacheModule, | 
				
			|||
    PrismaModule | 
				
			|||
  ], | 
				
			|||
  controllers: [ExperimentalController], | 
				
			|||
  providers: [AccountService, ExperimentalService] | 
				
			|||
}) | 
				
			|||
export class ExperimentalModule {} | 
				
			|||
@ -1,23 +0,0 @@ | 
				
			|||
import { AccountService } from '@ghostfolio/api/app/account/account.service'; | 
				
			|||
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; | 
				
			|||
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; | 
				
			|||
import { PrismaService } from '@ghostfolio/api/services/prisma.service'; | 
				
			|||
import { Injectable } from '@nestjs/common'; | 
				
			|||
 | 
				
			|||
@Injectable() | 
				
			|||
export class ExperimentalService { | 
				
			|||
  public constructor( | 
				
			|||
    private readonly accountService: AccountService, | 
				
			|||
    private readonly dataProviderService: DataProviderService, | 
				
			|||
    private readonly exchangeRateDataService: ExchangeRateDataService, | 
				
			|||
    private readonly prismaService: PrismaService | 
				
			|||
  ) {} | 
				
			|||
 | 
				
			|||
  public async getBenchmark(aSymbol: string) { | 
				
			|||
    return this.prismaService.marketData.findMany({ | 
				
			|||
      orderBy: { date: 'asc' }, | 
				
			|||
      select: { date: true, marketPrice: true }, | 
				
			|||
      where: { symbol: aSymbol } | 
				
			|||
    }); | 
				
			|||
  } | 
				
			|||
} | 
				
			|||
@ -1,4 +0,0 @@ | 
				
			|||
export interface Data { | 
				
			|||
  currency: string; | 
				
			|||
  value: number; | 
				
			|||
} | 
				
			|||
					Loading…
					
					
				
		Reference in new issue