Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for trade statistics #2224

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public Volume getTradeVolume() {
}
}

public boolean isValid() {
return tradeAmount > 0 && tradePrice > 0;
}

@Override
public String toString() {
return "TradeStatistics2{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public void onAllServicesInitialized() {
Map<String, TradeStatistics2> map = new HashMap<>();
p2PService.getP2PDataStorage().getAppendOnlyDataStoreMap().values().stream()
.filter(e -> e instanceof TradeStatistics2)
.forEach(e -> addToMap((TradeStatistics2) e, map));
.map(e -> (TradeStatistics2) e)
.filter(TradeStatistics2::isValid)
.forEach(e -> addToMap(e, map));
observableTradeStatisticsSet.addAll(map.values());

priceFeedService.applyLatestBisqMarketPrice(observableTradeStatisticsSet);
Expand Down Expand Up @@ -149,16 +151,18 @@ public ObservableSet<TradeStatistics2> getObservableTradeStatisticsSet() {

private void addToMap(TradeStatistics2 tradeStatistics, boolean storeLocally) {
if (!observableTradeStatisticsSet.contains(tradeStatistics)) {
boolean itemAlreadyAdded = observableTradeStatisticsSet.stream()
.anyMatch(e -> (e.getOfferId().equals(tradeStatistics.getOfferId())));
if (!itemAlreadyAdded) {
observableTradeStatisticsSet.add(tradeStatistics);
if (storeLocally) {
priceFeedService.applyLatestBisqMarketPrice(observableTradeStatisticsSet);
dump();
}
} else {
log.debug("We have already an item with the same offer ID. That might happen if both the maker and the taker published the tradeStatistics");

if (observableTradeStatisticsSet.stream()
.anyMatch(e -> (e.getOfferId().equals(tradeStatistics.getOfferId()))))
return;

if (!tradeStatistics.isValid())
return;

observableTradeStatisticsSet.add(tradeStatistics);
if (storeLocally) {
priceFeedService.applyLatestBisqMarketPrice(observableTradeStatisticsSet);
dump();
}
}
}
Expand Down