set precision for price
This commit is contained in:
parent
31c54dae8f
commit
e862ca4703
1 changed files with 6 additions and 6 deletions
|
|
@ -46,7 +46,7 @@ public class OrderCalculationService {
|
|||
: calculationSums(registry, listing.getLotSize().intValue(), s, n);
|
||||
|
||||
BigDecimal quantityLot = result.sum3().abs();
|
||||
BigDecimal price = swapPriceCalc(pair.getBaseCurrency(), s, n);
|
||||
BigDecimal price = swapPriceCalc(pair.getBaseCurrency(), s, n, listing.getPrecision().intValue());
|
||||
|
||||
return new FinalCalculationResult(price, s, quantityLot);
|
||||
}
|
||||
|
|
@ -69,11 +69,11 @@ public class OrderCalculationService {
|
|||
BigDecimal price;
|
||||
if (SettleCode.T0 == settleCode) {
|
||||
quantityLot = result.sum3().abs();
|
||||
price = rates.getUnitRate();
|
||||
price = rates.getUnitRate().setScale(listing.getPrecision().intValue(), RoundingMode.HALF_UP);
|
||||
} else {
|
||||
quantityLot = result.sum5().abs();
|
||||
BigDecimal delta = swapPriceCalc(pair.getBaseCurrency(), s, n);
|
||||
price = rates.getUnitRate().add(delta);
|
||||
BigDecimal delta = swapPriceCalc(pair.getBaseCurrency(), s, n, listing.getPrecision().intValue());
|
||||
price = rates.getUnitRate().add(delta).setScale(listing.getPrecision().intValue(), RoundingMode.HALF_UP);;
|
||||
}
|
||||
|
||||
return new FinalCalculationResult(price, s, quantityLot);
|
||||
|
|
@ -136,7 +136,7 @@ public class OrderCalculationService {
|
|||
return new CalculationResult(sum1, sum2, sum3, sum4, sum5, sum6);
|
||||
}
|
||||
|
||||
private BigDecimal swapPriceCalc(String baseCurrency, BigDecimal s, BigDecimal n) {
|
||||
private BigDecimal swapPriceCalc(String baseCurrency, BigDecimal s, BigDecimal n, int precision) {
|
||||
Rates rate = imdgQueryService.getRate(baseCurrency, LocalDate.now());
|
||||
BigDecimal p = BigDecimal.ONE.divide(n, MC);
|
||||
log.info("Calculation swap price: {}*{}*{}", s, n, p);
|
||||
|
|
@ -144,7 +144,7 @@ public class OrderCalculationService {
|
|||
.multiply(s, MC)
|
||||
.multiply(n, MC)
|
||||
.multiply(p, MC)
|
||||
.setScale(8, RoundingMode.HALF_UP);
|
||||
.setScale(precision, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
private boolean isRub(Registry registry) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue