Convert mktPriceMargin to %, make createAndPlaceOffer private

And move createAndPlaceOffer to bottom of class file.
This commit is contained in:
ghubstan 2020-09-25 13:50:50 -03:00
parent 96278b9bab
commit 995af0dd21
No known key found for this signature in database
GPG key ID: E35592D6800A861E

View file

@ -40,6 +40,7 @@ import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import static bisq.common.util.MathUtils.exactMultiply;
import static bisq.common.util.MathUtils.roundDoubleToLong; import static bisq.common.util.MathUtils.roundDoubleToLong;
import static bisq.common.util.MathUtils.scaleUpByPowerOf10; import static bisq.common.util.MathUtils.scaleUpByPowerOf10;
import static bisq.core.locale.CurrencyUtil.isCryptoCurrency; import static bisq.core.locale.CurrencyUtil.isCryptoCurrency;
@ -84,6 +85,7 @@ class CoreOffersService {
return offers; return offers;
} }
// Create offer with a random offer id.
Offer createOffer(String currencyCode, Offer createOffer(String currencyCode,
String directionAsString, String directionAsString,
String priceAsString, String priceAsString,
@ -119,42 +121,7 @@ class CoreOffersService {
resultHandler); resultHandler);
} }
Offer createAndPlaceOffer(String offerId, // Create offer for given offer id.
String currencyCode,
Direction direction,
Price price,
boolean useMarketBasedPrice,
double marketPriceMargin,
Coin amount,
Coin minAmount,
double buyerSecurityDeposit,
PaymentAccount paymentAccount,
boolean useSavingsWallet,
TransactionResultHandler resultHandler) {
Coin useDefaultTxFee = Coin.ZERO;
Offer offer = createOfferService.createAndGetOffer(offerId,
direction,
currencyCode,
amount,
minAmount,
price,
useDefaultTxFee,
useMarketBasedPrice,
marketPriceMargin,
buyerSecurityDeposit,
paymentAccount);
// TODO give user chance to examine offer before placing it (placeoffer)
openOfferManager.placeOffer(offer,
buyerSecurityDeposit,
useSavingsWallet,
resultHandler,
log::error);
return offer;
}
Offer createOffer(String offerId, Offer createOffer(String offerId,
String currencyCode, String currencyCode,
Direction direction, Direction direction,
@ -177,7 +144,7 @@ class CoreOffersService {
price, price,
useDefaultTxFee, useDefaultTxFee,
useMarketBasedPrice, useMarketBasedPrice,
marketPriceMargin, exactMultiply(marketPriceMargin, 0.01),
buyerSecurityDeposit, buyerSecurityDeposit,
paymentAccount); paymentAccount);
@ -190,6 +157,43 @@ class CoreOffersService {
return offer; return offer;
} }
private Offer createAndPlaceOffer(String offerId,
String currencyCode,
Direction direction,
Price price,
boolean useMarketBasedPrice,
double marketPriceMargin,
Coin amount,
Coin minAmount,
double buyerSecurityDeposit,
PaymentAccount paymentAccount,
boolean useSavingsWallet,
TransactionResultHandler resultHandler) {
Coin useDefaultTxFee = Coin.ZERO;
Offer offer = createOfferService.createAndGetOffer(offerId,
direction,
currencyCode,
amount,
minAmount,
price,
useDefaultTxFee,
useMarketBasedPrice,
exactMultiply(marketPriceMargin, 0.01),
buyerSecurityDeposit,
paymentAccount);
// TODO give user chance to examine offer before placing it (placeoffer)
openOfferManager.placeOffer(offer,
buyerSecurityDeposit,
useSavingsWallet,
resultHandler,
log::error);
return offer;
}
private long priceStringToLong(String priceAsString, String currencyCode) { private long priceStringToLong(String priceAsString, String currencyCode) {
int precision = isCryptoCurrency(currencyCode) ? Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT; int precision = isCryptoCurrency(currencyCode) ? Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
double priceAsDouble = new BigDecimal(priceAsString).doubleValue(); double priceAsDouble = new BigDecimal(priceAsString).doubleValue();