OrderValuesHelper { public BigDecimal adjustAmount(BigDecimal amount) { BigDecimal maximumAmount = metaData.getMaximumAmount(); if (maximumAmount != null && amount.compareTo(maximumAmount) > 0) { return maximumAmount; } BigDecimal result = amount; BigDecimal stepSize = metaData.getAmountStepSize(); if (stepSize != null && stepSize.compareTo(BigDecimal.ZERO) != 0) { result = BigDecimalUtils.roundToStepSize(result, stepSize, RoundingMode.FLOOR); } Integer baseScale = metaData.getBaseScale(); if (baseScale != null) { result = result.setScale(baseScale, RoundingMode.FLOOR); } return result; } OrderValuesHelper(CurrencyPairMetaData metaData); boolean amountUnderMinimum(BigDecimal amount); BigDecimal adjustAmount(BigDecimal amount); BigDecimal adjustPrice(BigDecimal price, Order.OrderType orderType); BigDecimal adjustPrice(BigDecimal price, RoundingMode roundingMode);  }
@Test public void shouldAdjustAmountToStepSize() { given(pairMetaData.getAmountStepSize()).willReturn(new BigDecimal("0.001")); given(pairMetaData.getBaseScale()).willReturn(null); BigDecimal result = adjuster.adjustAmount(new BigDecimal("0.93851732")); assertThat(result).isEqualByComparingTo("0.938"); }
@Test public void shouldAdjustAmountToScale() { given(pairMetaData.getAmountStepSize()).willReturn(null); given(pairMetaData.getBaseScale()).willReturn(5); BigDecimal result = adjuster.adjustAmount(new BigDecimal("10.123456789")); assertThat(result).isEqualByComparingTo("10.12345"); }
@Test public void shouldAdjustAmountToMaximal() { BigDecimal minimal = new BigDecimal("100"); given(pairMetaData.getMaximumAmount()).willReturn(minimal); given(pairMetaData.getBaseScale()).willReturn(null); BigDecimal result = adjuster.adjustAmount(new BigDecimal("128.32432")); assertThat(result).isEqualByComparingTo(minimal); }