Skip to content

Commit

Permalink
Fixing, improving and updating code related to fetching orders.
Browse files Browse the repository at this point in the history
  • Loading branch information
danilo-silva-funttastic committed Sep 22, 2023
1 parent 6b28ab5 commit 1a812b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/connectors/kujira/kujira.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 27 additions & 10 deletions src/connectors/kujira/kujira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>();
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<string, any>().asMutable();
Expand Down
4 changes: 2 additions & 2 deletions src/templates/kujira.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ orders:
fee: 'auto'
maxPerTransaction: 8
open:
limit: 255
limit: 155
filled:
limit: 255
limit: 155
cancel:
maxPerTransaction: 25
tokens:
Expand Down

0 comments on commit 1a812b8

Please sign in to comment.