allow offer trigger price outside of current price
This commit is contained in:
parent
290a3738b7
commit
f675588a2d
3 changed files with 17 additions and 24 deletions
|
@ -595,6 +595,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
offerBookService.activateOffer(offer,
|
offerBookService.activateOffer(offer,
|
||||||
() -> {
|
() -> {
|
||||||
openOffer.setState(OpenOffer.State.AVAILABLE);
|
openOffer.setState(OpenOffer.State.AVAILABLE);
|
||||||
|
applyTriggerState(openOffer);
|
||||||
requestPersistence();
|
requestPersistence();
|
||||||
log.debug("activateOpenOffer, offerId={}", offer.getId());
|
log.debug("activateOpenOffer, offerId={}", offer.getId());
|
||||||
resultHandler.handleResult();
|
resultHandler.handleResult();
|
||||||
|
@ -603,6 +604,13 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void applyTriggerState(OpenOffer openOffer) {
|
||||||
|
if (openOffer.getState() != OpenOffer.State.AVAILABLE) return;
|
||||||
|
if (TriggerPriceService.isTriggered(priceFeedService.getMarketPrice(openOffer.getOffer().getCurrencyCode()), openOffer)) {
|
||||||
|
openOffer.deactivate(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void deactivateOpenOffer(OpenOffer openOffer,
|
public void deactivateOpenOffer(OpenOffer openOffer,
|
||||||
boolean deactivatedByTrigger,
|
boolean deactivatedByTrigger,
|
||||||
ResultHandler resultHandler,
|
ResultHandler resultHandler,
|
||||||
|
@ -688,7 +696,12 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
removeOpenOffer(openOffer);
|
removeOpenOffer(openOffer);
|
||||||
|
|
||||||
OpenOffer editedOpenOffer = new OpenOffer(editedOffer, triggerPrice, openOffer);
|
OpenOffer editedOpenOffer = new OpenOffer(editedOffer, triggerPrice, openOffer);
|
||||||
editedOpenOffer.setState(originalState);
|
if (originalState == OpenOffer.State.DEACTIVATED && openOffer.isDeactivatedByTrigger()) {
|
||||||
|
editedOpenOffer.setState(OpenOffer.State.AVAILABLE);
|
||||||
|
applyTriggerState(editedOpenOffer);
|
||||||
|
} else {
|
||||||
|
editedOpenOffer.setState(originalState);
|
||||||
|
}
|
||||||
|
|
||||||
addOpenOffer(editedOpenOffer);
|
addOpenOffer(editedOpenOffer);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import haveno.common.util.MathUtils;
|
import haveno.common.util.MathUtils;
|
||||||
import haveno.core.locale.CurrencyUtil;
|
import haveno.core.locale.CurrencyUtil;
|
||||||
import haveno.core.locale.Res;
|
|
||||||
import haveno.core.monetary.CryptoMoney;
|
import haveno.core.monetary.CryptoMoney;
|
||||||
import haveno.core.monetary.Price;
|
import haveno.core.monetary.Price;
|
||||||
import haveno.core.monetary.TraditionalMoney;
|
import haveno.core.monetary.TraditionalMoney;
|
||||||
|
@ -69,27 +68,8 @@ public class PriceUtil {
|
||||||
if (!result.isValid) {
|
if (!result.isValid) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
long triggerPriceAsLong = PriceUtil.getMarketPriceAsLong(triggerPriceAsString, marketPrice.getCurrencyCode());
|
return new InputValidator.ValidationResult(true);
|
||||||
long marketPriceAsLong = PriceUtil.getMarketPriceAsLong("" + marketPrice.getPrice(), marketPrice.getCurrencyCode());
|
|
||||||
String marketPriceAsString = FormattingUtils.formatMarketPrice(marketPrice.getPrice(), marketPrice.getCurrencyCode());
|
|
||||||
|
|
||||||
boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode);
|
|
||||||
if ((isSellOffer && !isCryptoCurrency) || (!isSellOffer && isCryptoCurrency)) {
|
|
||||||
if (triggerPriceAsLong >= marketPriceAsLong) {
|
|
||||||
return new InputValidator.ValidationResult(false,
|
|
||||||
Res.get("createOffer.triggerPrice.invalid.tooHigh", marketPriceAsString));
|
|
||||||
} else {
|
|
||||||
return new InputValidator.ValidationResult(true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (triggerPriceAsLong <= marketPriceAsLong) {
|
|
||||||
return new InputValidator.ValidationResult(false,
|
|
||||||
Res.get("createOffer.triggerPrice.invalid.tooLow", marketPriceAsString));
|
|
||||||
} else {
|
|
||||||
return new InputValidator.ValidationResult(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Price marketPriceToPrice(MarketPrice marketPrice) {
|
public static Price marketPriceToPrice(MarketPrice marketPrice) {
|
||||||
|
|
|
@ -692,7 +692,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
|
||||||
AutoTooltipSlideToggleButton checkBox;
|
AutoTooltipSlideToggleButton checkBox;
|
||||||
|
|
||||||
private void updateState(@NotNull OpenOffer openOffer) {
|
private void updateState(@NotNull OpenOffer openOffer) {
|
||||||
if (checkBox != null) checkBox.setSelected(!openOffer.isDeactivated());
|
if (checkBox != null) checkBox.setSelected(openOffer.getState() == OpenOffer.State.AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue