diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-09-24 19:17:38 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-09-24 19:17:38 +0800 |
commit | e4b664bafa24c2ee788a343edecd0124f784780d (patch) | |
tree | 54cb57eeba44a7140c326cb17624b3839c6e73d3 /packages/asset-buyer/src/utils | |
parent | 7a5376621f2c2503c6415802984b4d8ae05db723 (diff) | |
download | dexon-0x-contracts-e4b664bafa24c2ee788a343edecd0124f784780d.tar.gz dexon-0x-contracts-e4b664bafa24c2ee788a343edecd0124f784780d.tar.zst dexon-0x-contracts-e4b664bafa24c2ee788a343edecd0124f784780d.zip |
Add expiry buffer
Diffstat (limited to 'packages/asset-buyer/src/utils')
-rw-r--r-- | packages/asset-buyer/src/utils/order_provider_response_processor.ts | 14 | ||||
-rw-r--r-- | packages/asset-buyer/src/utils/order_utils.ts | 5 |
2 files changed, 15 insertions, 4 deletions
diff --git a/packages/asset-buyer/src/utils/order_provider_response_processor.ts b/packages/asset-buyer/src/utils/order_provider_response_processor.ts index 9e54300b3..31fdcc182 100644 --- a/packages/asset-buyer/src/utils/order_provider_response_processor.ts +++ b/packages/asset-buyer/src/utils/order_provider_response_processor.ts @@ -41,11 +41,18 @@ export const orderProviderResponseProcessor = { targetOrderProviderResponse: OrderProviderResponse, feeOrderProviderResponse: OrderProviderResponse, zrxTokenAssetData: string, + expiryBufferSeconds: number, orderValidator?: OrderValidatorWrapper, ): Promise<AssetBuyerOrdersAndFillableAmounts> { // drop orders that are expired or not open - const filteredTargetOrders = filterOutExpiredAndNonOpenOrders(targetOrderProviderResponse.orders); - const filteredFeeOrders = filterOutExpiredAndNonOpenOrders(feeOrderProviderResponse.orders); + const filteredTargetOrders = filterOutExpiredAndNonOpenOrders( + targetOrderProviderResponse.orders, + expiryBufferSeconds, + ); + const filteredFeeOrders = filterOutExpiredAndNonOpenOrders( + feeOrderProviderResponse.orders, + expiryBufferSeconds, + ); // set the orders to be sorted equal to the filtered orders let unsortedTargetOrders = filteredTargetOrders; let unsortedFeeOrders = filteredFeeOrders; @@ -98,9 +105,10 @@ export const orderProviderResponseProcessor = { */ function filterOutExpiredAndNonOpenOrders( orders: SignedOrderWithRemainingFillableMakerAssetAmount[], + expiryBufferSeconds: number, ): SignedOrderWithRemainingFillableMakerAssetAmount[] { const result = _.filter(orders, order => { - return orderUtils.isOpenOrder(order) && !orderUtils.isOrderExpired(order); + return orderUtils.isOpenOrder(order) && !orderUtils.willOrderExpire(order, expiryBufferSeconds); }); return result; } diff --git a/packages/asset-buyer/src/utils/order_utils.ts b/packages/asset-buyer/src/utils/order_utils.ts index 27db73257..62166eb76 100644 --- a/packages/asset-buyer/src/utils/order_utils.ts +++ b/packages/asset-buyer/src/utils/order_utils.ts @@ -5,9 +5,12 @@ import { constants } from '../constants'; export const orderUtils = { isOrderExpired(order: SignedOrder): boolean { + return orderUtils.willOrderExpire(order, 0); + }, + willOrderExpire(order: SignedOrder, secondsFromNow: number): boolean { const millisecondsInSecond = 1000; const currentUnixTimestampSec = new BigNumber(Date.now() / millisecondsInSecond).round(); - return order.expirationTimeSeconds.lessThan(currentUnixTimestampSec); + return order.expirationTimeSeconds.lessThan(currentUnixTimestampSec.minus(secondsFromNow)); }, calculateRemainingMakerAssetAmount(order: SignedOrder, remainingTakerAssetAmount: BigNumber): BigNumber { if (remainingTakerAssetAmount.eq(0)) { |