Skip to content

Commit

Permalink
Merge pull request #2224 from ManfredKarrer/add-validation-for-trades…
Browse files Browse the repository at this point in the history
…tatistics

Add validation for trade statistics
  • Loading branch information
ripcurlx authored Jan 8, 2019
2 parents 307a5b8 + 0072212 commit 0f21859
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
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

0 comments on commit 0f21859

Please sign in to comment.