Skip to content

Instantly share code, notes, and snippets.

@agran
Created November 8, 2015 06:13
Show Gist options
  • Save agran/7a054bce084ef0e90ec3 to your computer and use it in GitHub Desktop.
Save agran/7a054bce084ef0e90ec3 to your computer and use it in GitHub Desktop.
@SuppressWarnings({ "unchecked", "rawtypes" })
public SortableList<BigInteger, Order> getOrdersSortableList(long have, long want, boolean filter)
{
//FILTER ALL KEYS
Collection<BigInteger> keys = ((BTreeMap<Tuple4, BigInteger>) this.haveWantKeyMap).subMap(
Fun.t4(have, want, null, null),
Fun.t4(have, want, Fun.HI(), Fun.HI())).values();
//Filters orders with unacceptably small amount. These orders have not worked
if(filter){
Iterator<BigInteger> iter = keys.iterator();
while (iter.hasNext()) {
Order order = this.get(iter.next());
BigDecimal increment = order.calculateBuyIncrement(order, DBSet.getInstance());
BigDecimal amount = order.getAmountLeft();
amount = amount.subtract(amount.remainder(increment));
if (amount.compareTo(BigDecimal.ZERO) <= 0)
iter.remove();
}
}
//RETURN
return new SortableList<BigInteger, Order>(this, keys);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment