|
|
|
@ -18,7 +18,8 @@ import {
|
|
|
|
|
Inject,
|
|
|
|
|
Param,
|
|
|
|
|
Query,
|
|
|
|
|
UseGuards
|
|
|
|
|
UseGuards,
|
|
|
|
|
Version
|
|
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import { REQUEST } from '@nestjs/core';
|
|
|
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
@ -36,9 +37,52 @@ export class GhostfolioController {
|
|
|
|
|
@Inject(REQUEST) private readonly request: RequestWithUser
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
@Get('dividends/:symbol')
|
|
|
|
|
@HasPermission(permissions.enableDataProviderGhostfolio)
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
|
|
|
|
|
public async getDividendsV1(
|
|
|
|
|
@Param('symbol') symbol: string,
|
|
|
|
|
@Query() query: GetDividendsDto
|
|
|
|
|
): Promise<DividendsResponse> {
|
|
|
|
|
const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests();
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
this.request.user.dataProviderGhostfolioDailyRequests > maxDailyRequests
|
|
|
|
|
) {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
|
|
|
|
|
StatusCodes.TOO_MANY_REQUESTS
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const dividends = await this.ghostfolioService.getDividends({
|
|
|
|
|
symbol,
|
|
|
|
|
from: parseDate(query.from),
|
|
|
|
|
granularity: query.granularity,
|
|
|
|
|
to: parseDate(query.to)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await this.ghostfolioService.incrementDailyRequests({
|
|
|
|
|
userId: this.request.user.id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return dividends;
|
|
|
|
|
} catch {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR),
|
|
|
|
|
StatusCodes.INTERNAL_SERVER_ERROR
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('dividends/:symbol')
|
|
|
|
|
@HasPermission(permissions.enableDataProviderGhostfolio)
|
|
|
|
|
@UseGuards(AuthGuard('api-key'), HasPermissionGuard)
|
|
|
|
|
@Version('2')
|
|
|
|
|
public async getDividends(
|
|
|
|
|
@Param('symbol') symbol: string,
|
|
|
|
|
@Query() query: GetDividendsDto
|
|
|
|
@ -75,9 +119,52 @@ export class GhostfolioController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
@Get('historical/:symbol')
|
|
|
|
|
@HasPermission(permissions.enableDataProviderGhostfolio)
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
|
|
|
|
|
public async getHistoricalV1(
|
|
|
|
|
@Param('symbol') symbol: string,
|
|
|
|
|
@Query() query: GetHistoricalDto
|
|
|
|
|
): Promise<HistoricalResponse> {
|
|
|
|
|
const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests();
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
this.request.user.dataProviderGhostfolioDailyRequests > maxDailyRequests
|
|
|
|
|
) {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
|
|
|
|
|
StatusCodes.TOO_MANY_REQUESTS
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const historicalData = await this.ghostfolioService.getHistorical({
|
|
|
|
|
symbol,
|
|
|
|
|
from: parseDate(query.from),
|
|
|
|
|
granularity: query.granularity,
|
|
|
|
|
to: parseDate(query.to)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await this.ghostfolioService.incrementDailyRequests({
|
|
|
|
|
userId: this.request.user.id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return historicalData;
|
|
|
|
|
} catch {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR),
|
|
|
|
|
StatusCodes.INTERNAL_SERVER_ERROR
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('historical/:symbol')
|
|
|
|
|
@HasPermission(permissions.enableDataProviderGhostfolio)
|
|
|
|
|
@UseGuards(AuthGuard('api-key'), HasPermissionGuard)
|
|
|
|
|
@Version('2')
|
|
|
|
|
public async getHistorical(
|
|
|
|
|
@Param('symbol') symbol: string,
|
|
|
|
|
@Query() query: GetHistoricalDto
|
|
|
|
@ -114,9 +201,51 @@ export class GhostfolioController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
@Get('lookup')
|
|
|
|
|
@HasPermission(permissions.enableDataProviderGhostfolio)
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
|
|
|
|
|
public async lookupSymbolV1(
|
|
|
|
|
@Query('includeIndices') includeIndicesParam = 'false',
|
|
|
|
|
@Query('query') query = ''
|
|
|
|
|
): Promise<LookupResponse> {
|
|
|
|
|
const includeIndices = includeIndicesParam === 'true';
|
|
|
|
|
const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests();
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
this.request.user.dataProviderGhostfolioDailyRequests > maxDailyRequests
|
|
|
|
|
) {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
|
|
|
|
|
StatusCodes.TOO_MANY_REQUESTS
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const result = await this.ghostfolioService.lookup({
|
|
|
|
|
includeIndices,
|
|
|
|
|
query: query.toLowerCase()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await this.ghostfolioService.incrementDailyRequests({
|
|
|
|
|
userId: this.request.user.id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
} catch {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR),
|
|
|
|
|
StatusCodes.INTERNAL_SERVER_ERROR
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('lookup')
|
|
|
|
|
@HasPermission(permissions.enableDataProviderGhostfolio)
|
|
|
|
|
@UseGuards(AuthGuard('api-key'), HasPermissionGuard)
|
|
|
|
|
@Version('2')
|
|
|
|
|
public async lookupSymbol(
|
|
|
|
|
@Query('includeIndices') includeIndicesParam = 'false',
|
|
|
|
|
@Query('query') query = ''
|
|
|
|
@ -152,9 +281,48 @@ export class GhostfolioController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
@Get('quotes')
|
|
|
|
|
@HasPermission(permissions.enableDataProviderGhostfolio)
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
|
|
|
|
|
public async getQuotesV1(
|
|
|
|
|
@Query() query: GetQuotesDto
|
|
|
|
|
): Promise<QuotesResponse> {
|
|
|
|
|
const maxDailyRequests = await this.ghostfolioService.getMaxDailyRequests();
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
this.request.user.dataProviderGhostfolioDailyRequests > maxDailyRequests
|
|
|
|
|
) {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.TOO_MANY_REQUESTS),
|
|
|
|
|
StatusCodes.TOO_MANY_REQUESTS
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const quotes = await this.ghostfolioService.getQuotes({
|
|
|
|
|
symbols: query.symbols
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await this.ghostfolioService.incrementDailyRequests({
|
|
|
|
|
userId: this.request.user.id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return quotes;
|
|
|
|
|
} catch {
|
|
|
|
|
throw new HttpException(
|
|
|
|
|
getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR),
|
|
|
|
|
StatusCodes.INTERNAL_SERVER_ERROR
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('quotes')
|
|
|
|
|
@HasPermission(permissions.enableDataProviderGhostfolio)
|
|
|
|
|
@UseGuards(AuthGuard('api-key'), HasPermissionGuard)
|
|
|
|
|
@Version('2')
|
|
|
|
|
public async getQuotes(
|
|
|
|
|
@Query() query: GetQuotesDto
|
|
|
|
|
): Promise<QuotesResponse> {
|
|
|
|
@ -187,9 +355,20 @@ export class GhostfolioController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
@Get('status')
|
|
|
|
|
@HasPermission(permissions.enableDataProviderGhostfolio)
|
|
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
|
|
|
|
|
public async getStatusV1(): Promise<DataProviderGhostfolioStatusResponse> {
|
|
|
|
|
return this.ghostfolioService.getStatus({ user: this.request.user });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('status')
|
|
|
|
|
@HasPermission(permissions.enableDataProviderGhostfolio)
|
|
|
|
|
@UseGuards(AuthGuard('api-key'), HasPermissionGuard)
|
|
|
|
|
@Version('2')
|
|
|
|
|
public async getStatus(): Promise<DataProviderGhostfolioStatusResponse> {
|
|
|
|
|
return this.ghostfolioService.getStatus({ user: this.request.user });
|
|
|
|
|
}
|
|
|
|
|