From 1a812b872eb617d935eb2d5fd19a4cf336711bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20Arau=CC=81jo=20Silva?= Date: Fri, 22 Sep 2023 21:08:18 +0200 Subject: [PATCH] Fixing, improving and updating code related to fetching orders. --- src/connectors/kujira/kujira.config.ts | 4 +-- src/connectors/kujira/kujira.ts | 37 +++++++++++++++++++------- src/templates/kujira.yml | 4 +-- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/connectors/kujira/kujira.config.ts b/src/connectors/kujira/kujira.config.ts index f09f8139bc..ebd8c4783d 100644 --- a/src/connectors/kujira/kujira.config.ts +++ b/src/connectors/kujira/kujira.config.ts @@ -67,12 +67,12 @@ export namespace KujiraConfig { ), }, open: { - limit: configManager.get(`kujira.orders.open.limit`) | 255, + limit: configManager.get(`kujira.orders.open.limit`) | (5 * 31), paginationLimit: configManager.get(`kujira.orders.open.paginationLimit`) | 31, }, filled: { - limit: configManager.get(`kujira.orders.filled.limit`) | 255, + limit: configManager.get(`kujira.orders.filled.limit`) | (5 * 31), }, cancel: { maxPerTransaction: configManager.get( diff --git a/src/connectors/kujira/kujira.ts b/src/connectors/kujira/kujira.ts index d7ec5639f2..1a2c7ac256 100644 --- a/src/connectors/kujira/kujira.ts +++ b/src/connectors/kujira/kujira.ts @@ -1305,26 +1305,43 @@ export class Kujira { let partialResponse: JsonObject; do { + let startAfter = '0'; + if (partialResponse && partialResponse.orders.length) { + startAfter = partialResponse.orders.reduce( + (target: any, current: any) => + parseInt(current.idx) > parseInt(target.idx) ? current : target + ).idx; + } + partialResponse = await this.kujiraQueryClientWasmQueryContractSmart( market.connectorMarket.address, { orders_by_user: { address: ownerAddress, - limit: KujiraConfig.config.orders.open.limit, - start_after: partialResponse - ? partialResponse.orders[ - partialResponse.orders.length - 1 - ].idx.toString() - : null, + limit: KujiraConfig.config.orders.open.paginationLimit, + start_after: startAfter, }, } ); - response.orders = [...response.orders, ...partialResponse.orders]; + const combinedOrders = [ + ...response.orders, + ...partialResponse.orders, + ]; + + const seenIndices = new Set(); + response.orders = combinedOrders.filter((order) => { + if (!seenIndices.has(order.idx)) { + seenIndices.add(order.idx); + + return true; + } + + return false; + }); } while ( - partialResponse.orders.length >= - KujiraConfig.config.orders.open.paginationLimit && - response.orders.length <= KujiraConfig.config.orders.open.limit + partialResponse.orders.length > 0 && + response.orders.length < KujiraConfig.config.orders.open.limit ); const bundles = IMap().asMutable(); diff --git a/src/templates/kujira.yml b/src/templates/kujira.yml index 65d5fdaaab..e23c2bfef3 100644 --- a/src/templates/kujira.yml +++ b/src/templates/kujira.yml @@ -45,9 +45,9 @@ orders: fee: 'auto' maxPerTransaction: 8 open: - limit: 255 + limit: 155 filled: - limit: 255 + limit: 155 cancel: maxPerTransaction: 25 tokens: