From d131e3c1a6faa9b98f03c0d156b8b317156f7152 Mon Sep 17 00:00:00 2001 From: cfaur09 Date: Thu, 19 Sep 2024 21:14:20 +0300 Subject: [PATCH 1/3] update deprecated pairs query --- src/endpoints/mex/mex.pair.service.ts | 105 ++++++++++++++------------ 1 file changed, 56 insertions(+), 49 deletions(-) diff --git a/src/endpoints/mex/mex.pair.service.ts b/src/endpoints/mex/mex.pair.service.ts index 29cddc97d..bf3cf3825 100644 --- a/src/endpoints/mex/mex.pair.service.ts +++ b/src/endpoints/mex/mex.pair.service.ts @@ -71,63 +71,68 @@ export class MexPairService { } const pairsLimit = gql` - query PairCount { - factory { - pairCount - } - }`; + query PairCount { + factory { + pairCount + } + }`; const pairsLimitResult: any = await this.graphQlService.getExchangeServiceData(pairsLimit); const totalPairs = pairsLimitResult?.factory?.pairCount; const variables = { - "offset": 0, - "pairsLimit": totalPairs, + pagination: { first: totalPairs }, + filters: {}, }; const query = gql` - query ($offset: Int, $pairsLimit: Int) { - pairs(offset: $offset, limit: $pairsLimit) { - address - liquidityPoolToken { - identifier - name - __typename - } - liquidityPoolTokenPriceUSD - firstToken { - name - identifier - decimals - previous24hPrice - __typename - } - secondToken { - name - identifier - decimals - previous24hPrice - __typename - } - firstTokenPrice - firstTokenPriceUSD - secondTokenPrice - secondTokenPriceUSD - info { - reserves0 - reserves1 - totalSupply - __typename + query filteredPairs($pagination: ConnectionArgs!, $filters: PairsFilter!) { + filteredPairs(pagination: $pagination, filters: $filters) { + edges { + cursor + node { + address + liquidityPoolToken { + identifier + name + __typename + } + liquidityPoolTokenPriceUSD + firstToken { + name + identifier + decimals + previous24hPrice + __typename + } + secondToken { + name + identifier + decimals + previous24hPrice + __typename + } + firstTokenPrice + firstTokenPriceUSD + secondTokenPrice + secondTokenPriceUSD + info { + reserves0 + reserves1 + totalSupply + __typename + } + state + type + lockedValueUSD + volumeUSD24h + hasFarms + hasDualFarms + tradesCount + deployedAt + __typename + } } - state - type - lockedValueUSD - volumeUSD24h - hasFarms - hasDualFarms - tradesCount - deployedAt - __typename } } `; @@ -137,7 +142,9 @@ export class MexPairService { return []; } - return result.pairs.map((pair: any) => this.getPairInfo(pair)).filter((x: MexPair | undefined) => x && x.state === MexPairState.active); + return result.filteredPairs.edges + .map((edge: any) => this.getPairInfo(edge.node)) + .filter((x: MexPair | undefined) => x && x.state === MexPairState.active); } catch (error) { this.logger.error('An error occurred while getting all mex pairs'); this.logger.error(error); From e64720d4bfb49bc9a459fcc94973507e6cf42aaa Mon Sep 17 00:00:00 2001 From: cfaur09 Date: Thu, 19 Sep 2024 21:26:07 +0300 Subject: [PATCH 2/3] add tradesCount24h --- src/endpoints/mex/entities/mex.pair.ts | 4 ++++ src/endpoints/mex/mex.pair.service.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/endpoints/mex/entities/mex.pair.ts b/src/endpoints/mex/entities/mex.pair.ts index dff0bc5d4..ea6a9ecc0 100644 --- a/src/endpoints/mex/entities/mex.pair.ts +++ b/src/endpoints/mex/entities/mex.pair.ts @@ -102,6 +102,10 @@ export class MexPair { @ApiProperty({ type: Number, nullable: true }) tradesCount: number | undefined = undefined; + @Field(() => Number, { description: 'Mex pair trades count 24h.', nullable: true }) + @ApiProperty({ type: Number, nullable: true }) + tradesCount24h: number | undefined = undefined; + @Field(() => Number, { description: 'Mex pair deploy date in unix time.', nullable: true }) @ApiProperty({ type: Number, nullable: true }) deployedAt: number | undefined = undefined; diff --git a/src/endpoints/mex/mex.pair.service.ts b/src/endpoints/mex/mex.pair.service.ts index bf3cf3825..368e87ab9 100644 --- a/src/endpoints/mex/mex.pair.service.ts +++ b/src/endpoints/mex/mex.pair.service.ts @@ -129,6 +129,7 @@ export class MexPairService { hasFarms hasDualFarms tradesCount + tradesCount24h deployedAt __typename } @@ -199,6 +200,7 @@ export class MexPairService { hasFarms: pair.hasFarms, hasDualFarms: pair.hasDualFarms, tradesCount: Number(pair.tradesCount), + tradesCount24h: Number(pair.tradesCount24h), deployedAt: Number(pair.deployedAt), state, type, @@ -227,6 +229,7 @@ export class MexPairService { hasFarms: pair.hasFarms, hasDualFarms: pair.hasDualFarms, tradesCount: Number(pair.tradesCount), + tradesCount24h: Number(pair.tradesCount24h), deployedAt: Number(pair.deployedAt), state, type, From 276e171ea0171455f95082d69a3f4f3ecd0cce7d Mon Sep 17 00:00:00 2001 From: cfaur09 Date: Fri, 20 Sep 2024 11:17:39 +0300 Subject: [PATCH 3/3] add mex pair status and apply filter by state --- src/endpoints/mex/entities/mex.pair.status.ts | 27 ++++++++++++++ src/endpoints/mex/mex.pair.service.ts | 36 +++++++++---------- 2 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 src/endpoints/mex/entities/mex.pair.status.ts diff --git a/src/endpoints/mex/entities/mex.pair.status.ts b/src/endpoints/mex/entities/mex.pair.status.ts new file mode 100644 index 000000000..ca79f85a7 --- /dev/null +++ b/src/endpoints/mex/entities/mex.pair.status.ts @@ -0,0 +1,27 @@ +import { registerEnumType } from "@nestjs/graphql"; + +export enum MexPairStatus { + active = 'Active', + inactive = 'Inactive', + paused = 'Paused', + partial = 'Partial', +} + +registerEnumType(MexPairStatus, { + name: 'MexPairStatus', + description: 'MexPairStatus object type.', + valuesMap: { + active: { + description: 'Active state.', + }, + inactive: { + description: 'Inactive state.', + }, + paused: { + description: 'Pause state.', + }, + partial: { + description: 'Partial state.', + }, + }, +}); diff --git a/src/endpoints/mex/mex.pair.service.ts b/src/endpoints/mex/mex.pair.service.ts index 368e87ab9..353503ebb 100644 --- a/src/endpoints/mex/mex.pair.service.ts +++ b/src/endpoints/mex/mex.pair.service.ts @@ -1,17 +1,18 @@ -import { Constants } from "@multiversx/sdk-nestjs-common"; -import { CacheService } from "@multiversx/sdk-nestjs-cache"; -import { BadRequestException, Injectable } from "@nestjs/common"; -import { gql } from "graphql-request"; -import { CacheInfo } from "src/utils/cache.info"; -import { GraphQlService } from "src/common/graphql/graphql.service"; -import { MexPair } from "./entities/mex.pair"; -import { MexPairState } from "./entities/mex.pair.state"; -import { MexPairType } from "./entities/mex.pair.type"; -import { MexSettingsService } from "./mex.settings.service"; -import { OriginLogger } from "@multiversx/sdk-nestjs-common"; -import { ApiConfigService } from "src/common/api-config/api.config.service"; -import { MexPairExchange } from "./entities/mex.pair.exchange"; -import { MexPairsFilter } from "./entities/mex.pairs..filter"; +import { Constants } from '@multiversx/sdk-nestjs-common'; +import { CacheService } from '@multiversx/sdk-nestjs-cache'; +import { BadRequestException, Injectable } from '@nestjs/common'; +import { gql } from 'graphql-request'; +import { CacheInfo } from 'src/utils/cache.info'; +import { GraphQlService } from 'src/common/graphql/graphql.service'; +import { MexPair } from './entities/mex.pair'; +import { MexPairState } from './entities/mex.pair.state'; +import { MexPairType } from './entities/mex.pair.type'; +import { MexSettingsService } from './mex.settings.service'; +import { OriginLogger } from '@multiversx/sdk-nestjs-common'; +import { ApiConfigService } from 'src/common/api-config/api.config.service'; +import { MexPairExchange } from './entities/mex.pair.exchange'; +import { MexPairsFilter } from './entities/mex.pairs..filter'; +import { MexPairStatus } from './entities/mex.pair.status'; @Injectable() export class MexPairService { @@ -52,7 +53,7 @@ export class MexPairService { CacheInfo.MexPairs.key, async () => await this.getAllMexPairsRaw(), CacheInfo.MexPairs.ttl, - Constants.oneSecond() * 30 + Constants.oneSecond() * 30, ); } @@ -82,7 +83,7 @@ export class MexPairService { const variables = { pagination: { first: totalPairs }, - filters: {}, + filters: { state: MexPairStatus.active }, }; const query = gql` @@ -144,8 +145,7 @@ export class MexPairService { } return result.filteredPairs.edges - .map((edge: any) => this.getPairInfo(edge.node)) - .filter((x: MexPair | undefined) => x && x.state === MexPairState.active); + .map((edge: any) => this.getPairInfo(edge.node)); } catch (error) { this.logger.error('An error occurred while getting all mex pairs'); this.logger.error(error);