Created
November 8, 2015 00:32
-
-
Save agran/8f49b5f8e9c0b3c58021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Pair<BigDecimal, BigDecimal> bruteforceAmount(BigDecimal price, BigDecimal amountLeft, BigDecimal increment) | |
{ | |
BigDecimal add = BigDecimal.ZERO.setScale(8); | |
BigDecimal satoshi = new BigDecimal("0.00000001").setScale(8); | |
BigDecimal amount = price.multiply(amountLeft).setScale(8, RoundingMode.DOWN); | |
amount = amount.subtract(amount.remainder(increment)); | |
price = BigDecimal.ONE.setScale(8).divide( | |
price, | |
8, | |
RoundingMode.DOWN ); | |
boolean nonstop = true; | |
while ( nonstop ) | |
{ | |
amount = amount.add(add); | |
BigDecimal multiply = price.multiply(amount).setScale(8, RoundingMode.DOWN); | |
if(multiply.compareTo(amountLeft) == 1) | |
{ | |
amount = amount.subtract(add); | |
nonstop = false; | |
} | |
if(multiply.compareTo(amountLeft) == 0) | |
{ | |
return new Pair<BigDecimal, BigDecimal> (price, amount); | |
} | |
add = increment; | |
} | |
nonstop = true; | |
amount = amount.subtract(increment); | |
if(amount.compareTo(BigDecimal.ZERO)<=0) | |
{ | |
amount = increment; | |
} | |
price = price.multiply(amount).setScale(8, RoundingMode.DOWN); | |
/* | |
while ( nonstop ) | |
{ | |
price = price.add(satoshi); | |
BigDecimal multiply = price.multiply(amount).setScale(8, RoundingMode.DOWN); | |
if(multiply.compareTo(amountLeft) == 1) | |
{ | |
price = price.subtract(satoshi); | |
nonstop = false; | |
} | |
if(multiply.compareTo(amountLeft) == 0) | |
{ | |
nonstop = false; | |
} | |
add = increment; | |
} | |
*/ | |
return new Pair<BigDecimal, BigDecimal> (price, amount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment