Fix some asset orders incorrectly matching worse prices.

This commit is contained in:
catbref
2019-04-10 15:25:16 +01:00
parent cfbf5c12bf
commit 16dab6972c
3 changed files with 93 additions and 9 deletions

View File

@@ -340,9 +340,17 @@ public class Order {
LOGGER.trace(String.format("Their price: %s %s per %s", theirPrice.toPlainString(), wantAssetData.getName(), haveAssetData.getName()));
}
// If their buyingPrice is less than what we're willing to accept then we're done as prices only get worse as we iterate through list of orders
if (theirPrice.compareTo(ourPrice) < 0)
break;
// If their price is worse than what we're willing to accept then we're done as prices only get worse as we iterate through list of orders
if (isOurOrderNewPricing) {
if (haveAssetId < wantAssetId && theirPrice.compareTo(ourPrice) > 0)
break;
if (haveAssetId > wantAssetId && theirPrice.compareTo(ourPrice) < 0)
break;
} else {
// 'old' pricing scheme
if (theirPrice.compareTo(ourPrice) < 0)
break;
}
// Calculate how much we could buy at their price.
BigDecimal ourMaxAmount;

View File

@@ -284,11 +284,21 @@ public class HSQLDBAssetRepository implements AssetRepository {
Collections.addAll(bindParams, haveAssetId, wantAssetId);
if (minimumPrice != null) {
sql += "AND price >= ? ";
// 'new' pricing scheme implied
// NOTE: haveAssetId and wantAssetId are for TARGET orders, so different from Order.process() caller
if (haveAssetId < wantAssetId)
sql += "AND price >= ? ";
else
sql += "AND price <= ? ";
bindParams.add(minimumPrice);
}
sql += "ORDER BY price DESC, ordered";
sql += "ORDER BY price";
if (minimumPrice == null || haveAssetId < wantAssetId)
sql += " DESC";
sql += ", ordered";
List<OrderData> orders = new ArrayList<OrderData>();