Add log for trade price

This commit is contained in:
Manfred Karrer 2018-12-07 21:16:13 +01:00
parent fd2d2fd1d8
commit 79c573640a
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46

View File

@ -207,15 +207,20 @@ public class Offer implements NetworkPayload, PersistablePayload {
checkArgument(takersTradePrice > 0, "takersTradePrice must be positive");
double factor = (double) takersTradePrice / (double) offerPrice.getValue();
double relation = (double) takersTradePrice / (double) offerPrice.getValue();
// We allow max. 2 % difference between own offerPayload price calculation and takers calculation.
// Market price might be different at maker's and takers side so we need a bit of tolerance.
// The tolerance will get smaller once we have multiple price feeds avoiding fast price fluctuations
// from one provider.
if (Math.abs(1 - factor) > PRICE_TOLERANCE) {
double deviation = Math.abs(1 - relation);
log.info("Price at take-offer time: id={}, currency={}, takersPrice={}, makersPrice={}, deviation={}",
getShortId(), getCurrencyCode(), takersTradePrice, offerPrice.getValue(),
deviation * 100 + "%");
if (deviation > PRICE_TOLERANCE) {
String msg = "Taker's trade price is too far away from our calculated price based on the market price.\n" +
"tradePrice=" + tradePrice.getValue() + "\n" +
"offerPrice=" + offerPrice.getValue();
"takersPrice=" + tradePrice.getValue() + "\n" +
"makersPrice=" + offerPrice.getValue();
log.warn(msg);
throw new TradePriceOutOfToleranceException(msg);
}