Skip to content

Commit

Permalink
feat: Optimize profitability time calculation (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben authored May 25, 2022
1 parent 66dd011 commit 372c3c0
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions core/src/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit 372c3c0

Please sign in to comment.