From 21bec9098af6b929a3d861a05cec7f19573e9b60 Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Fri, 24 Jan 2025 23:51:47 +0000 Subject: [PATCH] update [skip ci] --- src/order.ts | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/order.ts b/src/order.ts index 7ec7fda0..16fec624 100644 --- a/src/order.ts +++ b/src/order.ts @@ -302,20 +302,14 @@ export function prepareOrdersForRound( const orderbookBundledOrders: BundledOrders[] = []; for (const [, ownerProfile] of ownersProfileMap) { let remainingLimit = ownerProfile.limit; - const activeOrdersProfiles = Array.from(ownerProfile.orders).filter((v) => v[1].active); - let remainingOrdersPairs = activeOrdersProfiles.filter( - (v) => v[1].takeOrders.length > 0, - ); - // reset if all orders are already consumed - if (remainingOrdersPairs.length === 0) { - for (const [, orderProfile] of activeOrdersProfiles) { - orderProfile.takeOrders.push(...orderProfile.consumedTakeOrders.splice(0)); - } - remainingOrdersPairs = activeOrdersProfiles; - } + const ordersProfilesArr = Array.from(ownerProfile.orders); // consume orders limits - for (const [orderHash, orderProfile] of remainingOrdersPairs) { - if (remainingLimit > 0) { + for (const [orderHash, orderProfile] of ordersProfilesArr) { + if ( + remainingLimit > 0 && + orderProfile.active && + orderProfile.takeOrders.length > 0 + ) { const consumingOrderPairs = orderProfile.takeOrders.splice(0, remainingLimit); remainingLimit -= consumingOrderPairs.length; orderProfile.consumedTakeOrders.push(...consumingOrderPairs); @@ -325,21 +319,23 @@ export function prepareOrdersForRound( // if all orders are consumed and still there is limit remaining, // reset and start consuming again from top until limit is reached if (remainingLimit > 0) { - for (const [orderHash, orderProfile] of activeOrdersProfiles) { - orderProfile.takeOrders.push(...orderProfile.consumedTakeOrders.splice(0)); - if (remainingLimit > 0) { - const consumingOrderPairs = orderProfile.takeOrders.splice( - 0, - remainingLimit, - ); - remainingLimit -= consumingOrderPairs.length; - orderProfile.consumedTakeOrders.push(...consumingOrderPairs); - gatherPairs( - orderbook, - orderHash, - consumingOrderPairs, - orderbookBundledOrders, - ); + for (const [orderHash, orderProfile] of ordersProfilesArr) { + if (orderProfile.active) { + orderProfile.takeOrders.push(...orderProfile.consumedTakeOrders.splice(0)); + if (remainingLimit > 0) { + const consumingOrderPairs = orderProfile.takeOrders.splice( + 0, + remainingLimit, + ); + remainingLimit -= consumingOrderPairs.length; + orderProfile.consumedTakeOrders.push(...consumingOrderPairs); + gatherPairs( + orderbook, + orderHash, + consumingOrderPairs, + orderbookBundledOrders, + ); + } } } }