fix adjustment < min amount creating offers
This commit is contained in:
parent
4f5f82bf0f
commit
f261a38cce
@ -47,7 +47,7 @@ public class CoinUtil {
|
|||||||
|
|
||||||
public static double getFeePerVbyte(Coin miningFee, int txVsize) {
|
public static double getFeePerVbyte(Coin miningFee, int txVsize) {
|
||||||
double value = miningFee != null ? miningFee.value : 0;
|
double value = miningFee != null ? miningFee.value : 0;
|
||||||
return MathUtils.roundDouble((value / (double) txVsize), 2);
|
return MathUtils.roundDouble((value / txVsize), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,8 +127,8 @@ public class CoinUtil {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static BigInteger getAdjustedAmount(BigInteger amount, Price price, long maxTradeLimit, int factor) {
|
static BigInteger getAdjustedAmount(BigInteger amount, Price price, long maxTradeLimit, int factor) {
|
||||||
checkArgument(
|
checkArgument(
|
||||||
amount.longValueExact() >= HavenoUtils.xmrToAtomicUnits(0.0001).longValueExact(),
|
amount.longValueExact() >= Restrictions.getMinTradeAmount().longValueExact(),
|
||||||
"amount needs to be above minimum of 0.0001 xmr" // TODO: update amount for XMR
|
"amount needs to be above minimum of " + HavenoUtils.atomicUnitsToXmr(Restrictions.getMinTradeAmount()) + " xmr"
|
||||||
);
|
);
|
||||||
checkArgument(
|
checkArgument(
|
||||||
factor > 0,
|
factor > 0,
|
||||||
@ -143,10 +143,9 @@ public class CoinUtil {
|
|||||||
BigInteger smallestUnitForAmount = price.getAmountByVolume(smallestUnitForVolume);
|
BigInteger smallestUnitForAmount = price.getAmountByVolume(smallestUnitForVolume);
|
||||||
long minTradeAmount = Restrictions.getMinTradeAmount().longValueExact();
|
long minTradeAmount = Restrictions.getMinTradeAmount().longValueExact();
|
||||||
|
|
||||||
// We use 10 000 satoshi as min allowed amount
|
|
||||||
checkArgument(
|
checkArgument(
|
||||||
minTradeAmount >= HavenoUtils.xmrToAtomicUnits(0.0001).longValueExact(),
|
minTradeAmount >= Restrictions.getMinTradeAmount().longValueExact(),
|
||||||
"MinTradeAmount must be at least 0.0001 xmr" // TODO: update amount for XMR
|
"MinTradeAmount must be at least " + HavenoUtils.atomicUnitsToXmr(Restrictions.getMinTradeAmount()) + " xmr"
|
||||||
);
|
);
|
||||||
smallestUnitForAmount = BigInteger.valueOf(Math.max(minTradeAmount, smallestUnitForAmount.longValueExact()));
|
smallestUnitForAmount = BigInteger.valueOf(Math.max(minTradeAmount, smallestUnitForAmount.longValueExact()));
|
||||||
// We don't allow smaller amount values than smallestUnitForAmount
|
// We don't allow smaller amount values than smallestUnitForAmount
|
||||||
@ -164,8 +163,7 @@ public class CoinUtil {
|
|||||||
BigInteger amountByVolume = price.getAmountByVolume(volume);
|
BigInteger amountByVolume = price.getAmountByVolume(volume);
|
||||||
|
|
||||||
// For the amount we allow only 4 decimal places
|
// For the amount we allow only 4 decimal places
|
||||||
// TODO: remove rounding for XMR?
|
long adjustedAmount = HavenoUtils.centinerosToAtomicUnits(Math.round(HavenoUtils.atomicUnitsToCentineros(amountByVolume) / 10000d) * 10000).longValueExact();
|
||||||
long adjustedAmount = HavenoUtils.centinerosToAtomicUnits(Math.round((double) HavenoUtils.atomicUnitsToCentineros(amountByVolume) / 10000d) * 10000).longValueExact();
|
|
||||||
|
|
||||||
// If we are above our trade limit we reduce the amount by the smallestUnitForAmount
|
// If we are above our trade limit we reduce the amount by the smallestUnitForAmount
|
||||||
while (adjustedAmount > maxTradeLimit) {
|
while (adjustedAmount > maxTradeLimit) {
|
||||||
|
@ -59,7 +59,7 @@ public class CoinUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetAdjustedAmount() {
|
public void testGetAdjustedAmount() {
|
||||||
BigInteger result = CoinUtil.getAdjustedAmount(
|
BigInteger result = CoinUtil.getAdjustedAmount(
|
||||||
HavenoUtils.xmrToAtomicUnits(0.001),
|
HavenoUtils.xmrToAtomicUnits(0.1),
|
||||||
Price.valueOf("USD", 1000_0000),
|
Price.valueOf("USD", 1000_0000),
|
||||||
HavenoUtils.xmrToAtomicUnits(0.2).longValueExact(),
|
HavenoUtils.xmrToAtomicUnits(0.2).longValueExact(),
|
||||||
1);
|
1);
|
||||||
@ -78,7 +78,7 @@ public class CoinUtilTest {
|
|||||||
fail("Expected IllegalArgumentException to be thrown when amount is too low.");
|
fail("Expected IllegalArgumentException to be thrown when amount is too low.");
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"amount needs to be above minimum of 0.0001 xmr",
|
"amount needs to be above minimum of 0.1 xmr",
|
||||||
iae.getMessage(),
|
iae.getMessage(),
|
||||||
"Unexpected exception message."
|
"Unexpected exception message."
|
||||||
);
|
);
|
||||||
@ -112,7 +112,7 @@ public class CoinUtilTest {
|
|||||||
// 0.05 USD worth, which is below the factor of 1 USD, but does respect the maxTradeLimit.
|
// 0.05 USD worth, which is below the factor of 1 USD, but does respect the maxTradeLimit.
|
||||||
// Basically the given constraints (maxTradeLimit vs factor) are impossible to both fulfill..
|
// Basically the given constraints (maxTradeLimit vs factor) are impossible to both fulfill..
|
||||||
result = CoinUtil.getAdjustedAmount(
|
result = CoinUtil.getAdjustedAmount(
|
||||||
HavenoUtils.xmrToAtomicUnits(0.001),
|
HavenoUtils.xmrToAtomicUnits(0.1),
|
||||||
Price.valueOf("USD", 1000_0000),
|
Price.valueOf("USD", 1000_0000),
|
||||||
HavenoUtils.xmrToAtomicUnits(0.00005).longValueExact(),
|
HavenoUtils.xmrToAtomicUnits(0.00005).longValueExact(),
|
||||||
1);
|
1);
|
||||||
|
@ -524,6 +524,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
|
|||||||
// if the volume != amount * price, we need to adjust the amount
|
// if the volume != amount * price, we need to adjust the amount
|
||||||
if (amount.get() == null || !volumeBefore.equals(price.get().getVolumeByAmount(amount.get()))) {
|
if (amount.get() == null || !volumeBefore.equals(price.get().getVolumeByAmount(amount.get()))) {
|
||||||
BigInteger value = price.get().getAmountByVolume(volumeBefore);
|
BigInteger value = price.get().getAmountByVolume(volumeBefore);
|
||||||
|
value = value.max(Restrictions.getMinTradeAmount()); // adjust if below minimum
|
||||||
value = CoinUtil.getRoundedAmount(value, price.get(), getMaxTradeLimit(), tradeCurrencyCode.get(), paymentAccount.getPaymentMethod().getId());
|
value = CoinUtil.getRoundedAmount(value, price.get(), getMaxTradeLimit(), tradeCurrencyCode.get(), paymentAccount.getPaymentMethod().getId());
|
||||||
amount.set(value);
|
amount.set(value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user