Skip to content

Commit

Permalink
Merge pull request #5859 from chimp1984/fix-tradestat-filter
Browse files Browse the repository at this point in the history
Add date for applying filter
  • Loading branch information
ripcurlx committed Nov 24, 2021
2 parents 4f1f689 + 4ec14d3 commit 5358ae8
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
import java.time.ZoneId;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand All @@ -80,6 +82,8 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl

@JsonExclude
private transient static final ZoneId ZONE_ID = ZoneId.systemDefault();
@JsonExclude
private transient static final long STRICT_FILTER_DATE = new GregorianCalendar(2021, Calendar.NOVEMBER, 1).getTime().getTime();

public static TradeStatistics3 from(Trade trade,
@Nullable String referralId,
Expand Down Expand Up @@ -435,26 +439,37 @@ public boolean isValid() {
if (currency == null) {
return false;
}
long maxTradeLimit = Coin.COIN.multiply(2).value;
try {
// We cover only active payment methods. Retired ones will not be found by getActivePaymentMethodById.
String paymentMethodId = getPaymentMethodId();
Optional<PaymentMethod> optionalPaymentMethod = PaymentMethod.getActivePaymentMethod(paymentMethodId);
if (optionalPaymentMethod.isPresent()) {
maxTradeLimit = optionalPaymentMethod.get().getMaxTradeLimitAsCoin(currency).value;

boolean validMaxTradeLimit = true;
boolean currencyFound = true;
// We had historically higher trade limits and assets which are not in the currency list anymore, so we apply
// the filter only for data after STRICT_FILTER_DATE.
if (date > STRICT_FILTER_DATE) {
long maxTradeLimit = Coin.COIN.multiply(2).value;
try {
// We cover only active payment methods. Retired ones will not be found by getActivePaymentMethodById.
String paymentMethodId = getPaymentMethodId();
Optional<PaymentMethod> optionalPaymentMethod = PaymentMethod.getActivePaymentMethod(paymentMethodId);
if (optionalPaymentMethod.isPresent()) {
maxTradeLimit = optionalPaymentMethod.get().getMaxTradeLimitAsCoin(currency).value;
}
} catch (Exception e) {
log.warn("Error at isValid().", e);
}
} catch (Exception e) {
log.warn("Error at isValid().", e);
validMaxTradeLimit = amount <= maxTradeLimit;

currencyFound = CurrencyUtil.getCryptoCurrency(currency).isPresent() ||
CurrencyUtil.getFiatCurrency(currency).isPresent();
}

return amount > 0 &&
amount <= maxTradeLimit &&
validMaxTradeLimit &&
price > 0 &&
date > 0 &&
paymentMethod != null &&
!paymentMethod.isEmpty() &&
!currency.isEmpty() &&
(CurrencyUtil.getCryptoCurrency(currency).isPresent() ||
CurrencyUtil.getFiatCurrency(currency).isPresent());
currencyFound;
}

@Override
Expand Down

0 comments on commit 5358ae8

Please sign in to comment.