|
|
|
@ -10,6 +10,7 @@ import type { RequestWithUser } from '@ghostfolio/common/types';
|
|
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Delete,
|
|
|
|
|
Get,
|
|
|
|
|
HttpException,
|
|
|
|
|
Inject,
|
|
|
|
@ -32,35 +33,49 @@ export class BenchmarkController {
|
|
|
|
|
@Inject(REQUEST) private readonly request: RequestWithUser
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
@UseInterceptors(TransformDataSourceInRequestInterceptor)
|
|
|
|
|
@UseInterceptors(TransformDataSourceInResponseInterceptor)
|
|
|
|
|
public async getBenchmark(): Promise<BenchmarkResponse> {
|
|
|
|
|
return {
|
|
|
|
|
benchmarks: await this.benchmarkService.getBenchmarks()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':dataSource/:symbol/:startDateString')
|
|
|
|
|
@Post()
|
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
|
|
|
@UseInterceptors(TransformDataSourceInRequestInterceptor)
|
|
|
|
|
public async getBenchmarkMarketDataBySymbol(
|
|
|
|
|
@Param('dataSource') dataSource: DataSource,
|
|
|
|
|
@Param('startDateString') startDateString: string,
|
|
|
|
|
@Param('symbol') symbol: string
|
|
|
|
|
): Promise<BenchmarkMarketDataDetails> {
|
|
|
|
|
const startDate = new Date(startDateString);
|
|
|
|
|
public async addBenchmark(@Body() { dataSource, symbol }: UniqueAsset) {
|
|
|
|
|
if (
|
|
|
|
|
!hasPermission(
|
|
|
|
|
this.request.user.permissions,
|
|
|
|
|
permissions.accessAdminControl
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.FORBIDDEN),
|
|
|
|
|
StatusCodes.FORBIDDEN
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.benchmarkService.getMarketDataBySymbol({
|
|
|
|
|
dataSource,
|
|
|
|
|
startDate,
|
|
|
|
|
symbol
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
const benchmark = await this.benchmarkService.addBenchmark({
|
|
|
|
|
dataSource,
|
|
|
|
|
symbol
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!benchmark) {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.NOT_FOUND),
|
|
|
|
|
StatusCodes.NOT_FOUND
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return benchmark;
|
|
|
|
|
} catch {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR),
|
|
|
|
|
StatusCodes.INTERNAL_SERVER_ERROR
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
|
|
|
|
@Delete(':dataSource/:symbol')
|
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
|
|
|
public async addBenchmark(@Body() { dataSource, symbol }: UniqueAsset) {
|
|
|
|
|
public async deleteBenchmark(
|
|
|
|
|
@Param('dataSource') dataSource: DataSource,
|
|
|
|
|
@Param('symbol') symbol: string
|
|
|
|
|
) {
|
|
|
|
|
if (
|
|
|
|
|
!hasPermission(
|
|
|
|
|
this.request.user.permissions,
|
|
|
|
@ -74,7 +89,7 @@ export class BenchmarkController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const benchmark = await this.benchmarkService.addBenchmark({
|
|
|
|
|
const benchmark = await this.benchmarkService.deleteBenchmark({
|
|
|
|
|
dataSource,
|
|
|
|
|
symbol
|
|
|
|
|
});
|
|
|
|
@ -94,4 +109,30 @@ export class BenchmarkController {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
@UseInterceptors(TransformDataSourceInRequestInterceptor)
|
|
|
|
|
@UseInterceptors(TransformDataSourceInResponseInterceptor)
|
|
|
|
|
public async getBenchmark(): Promise<BenchmarkResponse> {
|
|
|
|
|
return {
|
|
|
|
|
benchmarks: await this.benchmarkService.getBenchmarks()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':dataSource/:symbol/:startDateString')
|
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
|
|
|
@UseInterceptors(TransformDataSourceInRequestInterceptor)
|
|
|
|
|
public async getBenchmarkMarketDataBySymbol(
|
|
|
|
|
@Param('dataSource') dataSource: DataSource,
|
|
|
|
|
@Param('startDateString') startDateString: string,
|
|
|
|
|
@Param('symbol') symbol: string
|
|
|
|
|
): Promise<BenchmarkMarketDataDetails> {
|
|
|
|
|
const startDate = new Date(startDateString);
|
|
|
|
|
|
|
|
|
|
return this.benchmarkService.getMarketDataBySymbol({
|
|
|
|
|
dataSource,
|
|
|
|
|
startDate,
|
|
|
|
|
symbol
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|