must provide fixed price unless using market price

This commit is contained in:
woodser 2022-11-26 13:02:07 +00:00
parent 9c5fdb5d4a
commit 9aa6bbeff6
9 changed files with 40 additions and 34 deletions

View File

@ -18,7 +18,7 @@
package bisq.cli.request;
import bisq.proto.grpc.CancelOfferRequest;
import bisq.proto.grpc.CreateOfferRequest;
import bisq.proto.grpc.PostOfferRequest;
import bisq.proto.grpc.GetMyOfferRequest;
import bisq.proto.grpc.GetMyOffersRequest;
import bisq.proto.grpc.GetOfferRequest;
@ -76,7 +76,7 @@ public class OffersServiceRequest {
double securityDepositPct,
String paymentAcctId,
String triggerPrice) {
var request = CreateOfferRequest.newBuilder()
var request = PostOfferRequest.newBuilder()
.setDirection(direction)
.setCurrencyCode(currencyCode)
.setAmount(amount)
@ -88,7 +88,7 @@ public class OffersServiceRequest {
.setPaymentAccountId(paymentAcctId)
.setTriggerPrice(triggerPrice)
.build();
return grpcStubs.offersService.createOffer(request).getOffer();
return grpcStubs.offersService.postOffer(request).getOffer();
}
public void cancelOffer(String offerId) {

View File

@ -438,7 +438,7 @@ public class CoreApi {
return coreOffersService.getMyOpenOffer(id);
}
public void createAnPlaceOffer(String currencyCode,
public void postOffer(String currencyCode,
String directionAsString,
String priceAsString,
boolean useMarketBasedPrice,
@ -450,7 +450,7 @@ public class CoreApi {
String paymentAccountId,
Consumer<Offer> resultHandler,
ErrorMessageHandler errorMessageHandler) {
coreOffersService.createAndPlaceOffer(currencyCode,
coreOffersService.postOffer(currencyCode,
directionAsString,
priceAsString,
useMarketBasedPrice,

View File

@ -212,7 +212,7 @@ public class CoreOffersService {
}
// Create and place new offer.
void createAndPlaceOffer(String currencyCode,
void postOffer(String currencyCode,
String directionAsString,
String priceAsString,
boolean useMarketBasedPrice,
@ -234,7 +234,7 @@ public class CoreOffersService {
String upperCaseCurrencyCode = currencyCode.toUpperCase();
String offerId = createOfferService.getRandomOfferId();
OfferDirection direction = OfferDirection.valueOf(directionAsString.toUpperCase());
Price price = Price.valueOf(upperCaseCurrencyCode, priceStringToLong(priceAsString, upperCaseCurrencyCode));
Price price = priceAsString.isEmpty() ? null : Price.valueOf(upperCaseCurrencyCode, priceStringToLong(priceAsString, upperCaseCurrencyCode));
Coin amount = Coin.valueOf(amountAsLong);
Coin minAmount = Coin.valueOf(minAmountAsLong);
Coin useDefaultTxFee = Coin.ZERO;

View File

@ -140,8 +140,8 @@ public class Price extends MonetaryWrapper implements Comparable<Price> {
public String toFriendlyString() {
return monetary instanceof Altcoin ?
((Altcoin) monetary).toFriendlyString() + "/BTC" :
((Fiat) monetary).toFriendlyString().replace(((Fiat) monetary).currencyCode, "") + "BTC/" + ((Fiat) monetary).currencyCode;
((Altcoin) monetary).toFriendlyString() + "/XMR" :
((Fiat) monetary).toFriendlyString().replace(((Fiat) monetary).currencyCode, "") + "XMR/" + ((Fiat) monetary).currencyCode;
}
public String toPlainString() {

View File

@ -129,7 +129,7 @@ public class CreateOfferService {
offerId,
currencyCode,
direction,
price.getValue(),
price == null ? null : price.getValue(),
useMarketBasedPrice,
marketPriceMargin,
amount.value,
@ -138,11 +138,17 @@ public class CreateOfferService {
long creationTime = new Date().getTime();
NodeAddress makerAddress = p2PService.getAddress();
boolean useMarketBasedPriceValue = useMarketBasedPrice &&
boolean useMarketBasedPriceValue = price == null &&
useMarketBasedPrice &&
isMarketPriceAvailable(currencyCode) &&
!paymentAccount.hasPaymentMethodWithId(HAL_CASH_ID);
long priceAsLong = price != null && !useMarketBasedPriceValue ? price.getValue() : 0L;
// verify price
if (price == null && !useMarketBasedPriceValue) {
throw new IllegalArgumentException("Must provide fixed price because market price is unavailable");
}
long priceAsLong = price != null ? price.getValue() : 0L;
double marketPriceMarginParam = useMarketBasedPriceValue ? marketPriceMargin : 0;
long amountAsLong = amount != null ? amount.getValue() : 0L;
long minAmountAsLong = minAmount != null ? minAmount.getValue() : 0L;

View File

@ -70,8 +70,8 @@ public class ValidateOffer extends Task<PlaceOfferModel> {
checkArgument(offer.getAmount().compareTo(offer.getMinAmount()) >= 0, "MinAmount is larger than Amount");
checkNotNull(offer.getPrice(), "Price is null");
checkArgument(offer.getPrice().isPositive(),
"Price must be positive. price=" + offer.getPrice().toFriendlyString());
if (!offer.isUseMarketBasedPrice()) checkArgument(offer.getPrice().isPositive(),
"Price must be positive unless using market based price. price=" + offer.getPrice().toFriendlyString());
checkArgument(offer.getDate().getTime() > 0,
"Date must not be 0. date=" + offer.getDate().toString());

View File

@ -27,14 +27,14 @@ public class PriceTest {
Price result = Price.parse("USD", "0.1");
Assert.assertEquals(
"Fiat value should be formatted with two decimals.",
"0.10 BTC/USD",
"0.10 XMR/USD",
result.toFriendlyString()
);
result = Price.parse("EUR", "0.1234");
Assert.assertEquals(
"Fiat value should be given two decimals",
"0.1234 BTC/EUR",
"0.1234 XMR/EUR",
result.toFriendlyString()
);
@ -57,19 +57,19 @@ public class PriceTest {
Assert.assertEquals(
"Comma (',') as decimal separator should be converted to period ('.')",
"0.0001 BTC/USD",
"0.0001 XMR/USD",
Price.parse("USD", "0,0001").toFriendlyString()
);
Assert.assertEquals(
"Too many decimals should get rounded up properly.",
"10000.2346 LTC/BTC",
"10000.2346 LTC/XMR",
Price.parse("LTC", "10000,23456789").toFriendlyString()
);
Assert.assertEquals(
"Too many decimals should get rounded down properly.",
"10000.2345 LTC/BTC",
"10000.2345 LTC/XMR",
Price.parse("LTC", "10000,23454999").toFriendlyString()
);
@ -95,14 +95,14 @@ public class PriceTest {
Price result = Price.valueOf("USD", 1);
Assert.assertEquals(
"Fiat value should have four decimals.",
"0.0001 BTC/USD",
"0.0001 XMR/USD",
result.toFriendlyString()
);
result = Price.valueOf("EUR", 1234);
Assert.assertEquals(
"Fiat value should be given two decimals",
"0.1234 BTC/EUR",
"0.1234 XMR/EUR",
result.toFriendlyString()
);
@ -114,13 +114,13 @@ public class PriceTest {
Assert.assertEquals(
"Too many decimals should get rounded up properly.",
"10000.2346 LTC/BTC",
"10000.2346 LTC/XMR",
Price.valueOf("LTC", 1000023456789L).toFriendlyString()
);
Assert.assertEquals(
"Too many decimals should get rounded down properly.",
"10000.2345 LTC/BTC",
"10000.2345 LTC/XMR",
Price.valueOf("LTC", 1000023454999L).toFriendlyString()
);

View File

@ -24,8 +24,8 @@ import bisq.core.offer.OpenOffer;
import bisq.core.util.ParsingUtils;
import bisq.proto.grpc.CancelOfferReply;
import bisq.proto.grpc.CancelOfferRequest;
import bisq.proto.grpc.CreateOfferReply;
import bisq.proto.grpc.CreateOfferRequest;
import bisq.proto.grpc.PostOfferReply;
import bisq.proto.grpc.PostOfferRequest;
import bisq.proto.grpc.GetMyOfferReply;
import bisq.proto.grpc.GetMyOfferRequest;
import bisq.proto.grpc.GetMyOffersReply;
@ -140,15 +140,15 @@ class GrpcOffersService extends OffersImplBase {
}
@Override
public void createOffer(CreateOfferRequest req,
StreamObserver<CreateOfferReply> responseObserver) {
public void postOffer(PostOfferRequest req,
StreamObserver<PostOfferReply> responseObserver) {
GrpcErrorMessageHandler errorMessageHandler =
new GrpcErrorMessageHandler(getCreateOfferMethod().getFullMethodName(),
new GrpcErrorMessageHandler(getPostOfferMethod().getFullMethodName(),
responseObserver,
exceptionHandler,
log);
try {
coreApi.createAnPlaceOffer(
coreApi.postOffer(
req.getCurrencyCode(),
req.getDirection(),
req.getPrice(),
@ -164,7 +164,7 @@ class GrpcOffersService extends OffersImplBase {
// the new offer to the gRPC client after async placement is done.
OpenOffer openOffer = coreApi.getMyOpenOffer(offer.getId());
OfferInfo offerInfo = OfferInfo.toMyOfferInfo(openOffer);
CreateOfferReply reply = CreateOfferReply.newBuilder()
PostOfferReply reply = PostOfferReply.newBuilder()
.setOffer(offerInfo.toProtoMessage())
.build();
responseObserver.onNext(reply);
@ -206,7 +206,7 @@ class GrpcOffersService extends OffersImplBase {
put(getGetMyOfferMethod().getFullMethodName(), new GrpcCallRateMeter(10, SECONDS));
put(getGetOffersMethod().getFullMethodName(), new GrpcCallRateMeter(20, SECONDS));
put(getGetMyOffersMethod().getFullMethodName(), new GrpcCallRateMeter(20, SECONDS));
put(getCreateOfferMethod().getFullMethodName(), new GrpcCallRateMeter(20, SECONDS));
put(getPostOfferMethod().getFullMethodName(), new GrpcCallRateMeter(20, SECONDS));
put(getCancelOfferMethod().getFullMethodName(), new GrpcCallRateMeter(10, SECONDS));
}}
)));

View File

@ -446,7 +446,7 @@ service Offers {
}
rpc GetMyOffers (GetMyOffersRequest) returns (GetMyOffersReply) {
}
rpc CreateOffer (CreateOfferRequest) returns (CreateOfferReply) {
rpc PostOffer (PostOfferRequest) returns (PostOfferReply) {
}
rpc CancelOffer (CancelOfferRequest) returns (CancelOfferReply) {
}
@ -486,7 +486,7 @@ message GetMyOffersReply {
repeated OfferInfo offers = 1;
}
message CreateOfferRequest {
message PostOfferRequest {
string currency_code = 1;
string direction = 2;
string price = 3;
@ -499,7 +499,7 @@ message CreateOfferRequest {
string payment_account_id = 10;
}
message CreateOfferReply {
message PostOfferReply {
OfferInfo offer = 1;
}