diff --git a/src/endpoints/mex/mex.controller.ts b/src/endpoints/mex/mex.controller.ts index 5dcfddb2d..e48a76fe8 100644 --- a/src/endpoints/mex/mex.controller.ts +++ b/src/endpoints/mex/mex.controller.ts @@ -160,14 +160,26 @@ export class MexController { @Get('mex/tokens/prices/hourly/:identifier') async getTokenPricesHourResolution( - @Param('identifier', new ParseTokenPipe) identifier: string): Promise { - return await this.mexTokenChartsService.getTokenPricesHourResolution(identifier); + @Param('identifier', new ParseTokenPipe) identifier: string): Promise { + const charts = await this.mexTokenChartsService.getTokenPricesHourResolution(identifier); + + if(!charts){ + throw new NotFoundException('Token not found'); + } + + return charts; } @Get('mex/tokens/prices/daily/:identifier') async getTokenPricesDayResolution( @Param('identifier',new ParseTokenPipe) identifier: string, - @Query('after') after: string): Promise { - return await this.mexTokenChartsService.getTokenPricesDayResolution(identifier, after); + @Query('after') after: string): Promise { + const charts = await this.mexTokenChartsService.getTokenPricesDayResolution(identifier, after); + + if(!charts){ + throw new NotFoundException('Token not found'); + } + + return charts; } } diff --git a/src/endpoints/mex/mex.token.charts.service.ts b/src/endpoints/mex/mex.token.charts.service.ts index 7c540d3ac..a47014b92 100644 --- a/src/endpoints/mex/mex.token.charts.service.ts +++ b/src/endpoints/mex/mex.token.charts.service.ts @@ -17,20 +17,19 @@ export class MexTokenChartsService { private readonly cachingService: CacheService, ) { } - async getTokenPricesHourResolution(tokenIdentifier: string): Promise { + async getTokenPricesHourResolution(tokenIdentifier: string): Promise { return await this.cachingService.getOrSet( - CacheInfo.TokenHourChar(tokenIdentifier).key, + CacheInfo.TokenHourChart(tokenIdentifier).key, async () => await this.getTokenPricesHourResolutionRaw(tokenIdentifier), - CacheInfo.TokenHourChar(tokenIdentifier).ttl, + CacheInfo.TokenHourChart(tokenIdentifier).ttl, ); } - async getTokenPricesHourResolutionRaw(tokenIdentifier: string): Promise { + async getTokenPricesHourResolutionRaw(tokenIdentifier: string): Promise { const tokenExists = await this.checkTokenExists(tokenIdentifier); if (!tokenExists) { - this.logger.error(`Token ${tokenIdentifier} does not exist or has no trading pair`); - return []; + return undefined; } const query = gql` @@ -54,20 +53,19 @@ export class MexTokenChartsService { } } - async getTokenPricesDayResolution(tokenIdentifier: string, after: string): Promise { + async getTokenPricesDayResolution(tokenIdentifier: string, after: string): Promise { return await this.cachingService.getOrSet( - CacheInfo.TokenDailyChar(tokenIdentifier, after).key, + CacheInfo.TokenDailyChart(tokenIdentifier, after).key, async () => await this.getTokenPricesDayResolutionRaw(tokenIdentifier, after), - CacheInfo.TokenDailyChar(tokenIdentifier, after).ttl, + CacheInfo.TokenDailyChart(tokenIdentifier, after).ttl, ); } - async getTokenPricesDayResolutionRaw(tokenIdentifier: string, after: string): Promise { + async getTokenPricesDayResolutionRaw(tokenIdentifier: string, after: string): Promise { const tokenExists = await this.checkTokenExists(tokenIdentifier); if (!tokenExists) { - this.logger.error(`Token ${tokenIdentifier} does not exist or has no trading pair`); - return []; + return undefined; } const query = gql` diff --git a/src/utils/cache.info.ts b/src/utils/cache.info.ts index 14d5603d1..d95dcec43 100644 --- a/src/utils/cache.info.ts +++ b/src/utils/cache.info.ts @@ -155,14 +155,14 @@ export class CacheInfo { }; } - static TokenHourChar(tokenIdentifier: string): CacheInfo { + static TokenHourChart(tokenIdentifier: string): CacheInfo { return { key: `tokenHourChart:${tokenIdentifier}`, ttl: Constants.oneMinute() * 10, }; } - static TokenDailyChar(tokenIdentifier: string, after: string): CacheInfo { + static TokenDailyChart(tokenIdentifier: string, after: string): CacheInfo { return { key: `tokenDailyChart:${tokenIdentifier}:${after}`, ttl: Constants.oneDay(),