Skip to content

Commit

Permalink
fix: handle error in case calc parameters not present (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
valiafetisov authored Apr 19, 2022
1 parent 500724b commit f2e8f31
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions core/src/auctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,32 @@ export const enrichAuctionWithPriceDrop = async function (auction: Auction): Pro
if (!auction.isActive || auction.isFinished) {
return auction;
}
const params = await fetchCalcParametersByCollateralType(auction.network, auction.collateralType);
const auctionWithParams = {
...auction,
secondsBetweenPriceDrops: params.secondsBetweenPriceDrops,
priceDropRatio: params.priceDropRatio,
};
const currentDate = await getNetworkDate(auction.network);
const secondsTillNextPriceDrop = calculateAuctionDropTime(auctionWithParams, currentDate);
const approximateUnitPrice = calculateAuctionPrice(auctionWithParams, currentDate);
const totalPrice = auction.collateralAmount.multipliedBy(approximateUnitPrice);
const transactionGrossProfitDate = calculateTransactionGrossProfitDate(auctionWithParams, currentDate);
return {
...auctionWithParams,
secondsTillNextPriceDrop,
approximateUnitPrice,
totalPrice,
transactionGrossProfitDate,
};
try {
const params = await fetchCalcParametersByCollateralType(auction.network, auction.collateralType);
const auctionWithParams = {
...auction,
secondsBetweenPriceDrops: params.secondsBetweenPriceDrops,
priceDropRatio: params.priceDropRatio,
};
const currentDate = await getNetworkDate(auction.network);
const secondsTillNextPriceDrop = calculateAuctionDropTime(auctionWithParams, currentDate);
const approximateUnitPrice = calculateAuctionPrice(auctionWithParams, currentDate);
const totalPrice = auction.collateralAmount.multipliedBy(approximateUnitPrice);
const transactionGrossProfitDate = calculateTransactionGrossProfitDate(auctionWithParams, currentDate);
return {
...auctionWithParams,
secondsTillNextPriceDrop,
approximateUnitPrice,
totalPrice,
transactionGrossProfitDate,
};
} catch (error) {
console.warn(`auction price drop information is not available for auction "${auction.id}"`);
return {
...auction,
totalPrice: auction.collateralAmount.multipliedBy(auction.unitPrice),
};
}
};

export const enrichAuctionWithPriceDropAndMarketValue = async function (
Expand Down

0 comments on commit f2e8f31

Please sign in to comment.