From 372c3c0f7d521ab5d3c7155076ea011e8c26157e Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 25 May 2022 18:22:09 +0200 Subject: [PATCH] feat: Optimize profitability time calculation (#249) --- core/src/price.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/src/price.ts b/core/src/price.ts index e1e67c395..b73742cd7 100644 --- a/core/src/price.ts +++ b/core/src/price.ts @@ -110,14 +110,12 @@ export const calculateTransactionGrossProfitDate = function (auction: Auction, c return undefined; } - let steps = 0; - let currentValue = new BigNumber(auction.approximateUnitPrice); + const stepNumber = Math.ceil( + Math.log(auction.marketUnitPrice.dividedBy(auction.approximateUnitPrice).toNumber()) / + Math.log(auction.priceDropRatio.toNumber()) + ); - while (currentValue.isGreaterThan(auction.marketUnitPrice)) { - steps += 1; - currentValue = currentValue.multipliedBy(auction.priceDropRatio); - } const secondsSinceLastPriceDrop = auction.secondsBetweenPriceDrops - auction.secondsTillNextPriceDrop; - const secondsTillProfitable = auction.secondsBetweenPriceDrops * steps - secondsSinceLastPriceDrop; + const secondsTillProfitable = auction.secondsBetweenPriceDrops * stepNumber - secondsSinceLastPriceDrop; return addSeconds(currentDate, secondsTillProfitable); };