mirror of
https://github.com/boldsuck/haveno.git
synced 2024-12-22 20:19:21 +00:00
must provide fixed price unless using market price
This commit is contained in:
parent
9c5fdb5d4a
commit
9aa6bbeff6
9 changed files with 40 additions and 34 deletions
|
@ -18,7 +18,7 @@
|
||||||
package bisq.cli.request;
|
package bisq.cli.request;
|
||||||
|
|
||||||
import bisq.proto.grpc.CancelOfferRequest;
|
import bisq.proto.grpc.CancelOfferRequest;
|
||||||
import bisq.proto.grpc.CreateOfferRequest;
|
import bisq.proto.grpc.PostOfferRequest;
|
||||||
import bisq.proto.grpc.GetMyOfferRequest;
|
import bisq.proto.grpc.GetMyOfferRequest;
|
||||||
import bisq.proto.grpc.GetMyOffersRequest;
|
import bisq.proto.grpc.GetMyOffersRequest;
|
||||||
import bisq.proto.grpc.GetOfferRequest;
|
import bisq.proto.grpc.GetOfferRequest;
|
||||||
|
@ -76,7 +76,7 @@ public class OffersServiceRequest {
|
||||||
double securityDepositPct,
|
double securityDepositPct,
|
||||||
String paymentAcctId,
|
String paymentAcctId,
|
||||||
String triggerPrice) {
|
String triggerPrice) {
|
||||||
var request = CreateOfferRequest.newBuilder()
|
var request = PostOfferRequest.newBuilder()
|
||||||
.setDirection(direction)
|
.setDirection(direction)
|
||||||
.setCurrencyCode(currencyCode)
|
.setCurrencyCode(currencyCode)
|
||||||
.setAmount(amount)
|
.setAmount(amount)
|
||||||
|
@ -88,7 +88,7 @@ public class OffersServiceRequest {
|
||||||
.setPaymentAccountId(paymentAcctId)
|
.setPaymentAccountId(paymentAcctId)
|
||||||
.setTriggerPrice(triggerPrice)
|
.setTriggerPrice(triggerPrice)
|
||||||
.build();
|
.build();
|
||||||
return grpcStubs.offersService.createOffer(request).getOffer();
|
return grpcStubs.offersService.postOffer(request).getOffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelOffer(String offerId) {
|
public void cancelOffer(String offerId) {
|
||||||
|
|
|
@ -438,7 +438,7 @@ public class CoreApi {
|
||||||
return coreOffersService.getMyOpenOffer(id);
|
return coreOffersService.getMyOpenOffer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createAnPlaceOffer(String currencyCode,
|
public void postOffer(String currencyCode,
|
||||||
String directionAsString,
|
String directionAsString,
|
||||||
String priceAsString,
|
String priceAsString,
|
||||||
boolean useMarketBasedPrice,
|
boolean useMarketBasedPrice,
|
||||||
|
@ -450,7 +450,7 @@ public class CoreApi {
|
||||||
String paymentAccountId,
|
String paymentAccountId,
|
||||||
Consumer<Offer> resultHandler,
|
Consumer<Offer> resultHandler,
|
||||||
ErrorMessageHandler errorMessageHandler) {
|
ErrorMessageHandler errorMessageHandler) {
|
||||||
coreOffersService.createAndPlaceOffer(currencyCode,
|
coreOffersService.postOffer(currencyCode,
|
||||||
directionAsString,
|
directionAsString,
|
||||||
priceAsString,
|
priceAsString,
|
||||||
useMarketBasedPrice,
|
useMarketBasedPrice,
|
||||||
|
|
|
@ -212,7 +212,7 @@ public class CoreOffersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and place new offer.
|
// Create and place new offer.
|
||||||
void createAndPlaceOffer(String currencyCode,
|
void postOffer(String currencyCode,
|
||||||
String directionAsString,
|
String directionAsString,
|
||||||
String priceAsString,
|
String priceAsString,
|
||||||
boolean useMarketBasedPrice,
|
boolean useMarketBasedPrice,
|
||||||
|
@ -234,7 +234,7 @@ public class CoreOffersService {
|
||||||
String upperCaseCurrencyCode = currencyCode.toUpperCase();
|
String upperCaseCurrencyCode = currencyCode.toUpperCase();
|
||||||
String offerId = createOfferService.getRandomOfferId();
|
String offerId = createOfferService.getRandomOfferId();
|
||||||
OfferDirection direction = OfferDirection.valueOf(directionAsString.toUpperCase());
|
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 amount = Coin.valueOf(amountAsLong);
|
||||||
Coin minAmount = Coin.valueOf(minAmountAsLong);
|
Coin minAmount = Coin.valueOf(minAmountAsLong);
|
||||||
Coin useDefaultTxFee = Coin.ZERO;
|
Coin useDefaultTxFee = Coin.ZERO;
|
||||||
|
|
|
@ -140,8 +140,8 @@ public class Price extends MonetaryWrapper implements Comparable<Price> {
|
||||||
|
|
||||||
public String toFriendlyString() {
|
public String toFriendlyString() {
|
||||||
return monetary instanceof Altcoin ?
|
return monetary instanceof Altcoin ?
|
||||||
((Altcoin) monetary).toFriendlyString() + "/BTC" :
|
((Altcoin) monetary).toFriendlyString() + "/XMR" :
|
||||||
((Fiat) monetary).toFriendlyString().replace(((Fiat) monetary).currencyCode, "") + "BTC/" + ((Fiat) monetary).currencyCode;
|
((Fiat) monetary).toFriendlyString().replace(((Fiat) monetary).currencyCode, "") + "XMR/" + ((Fiat) monetary).currencyCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toPlainString() {
|
public String toPlainString() {
|
||||||
|
|
|
@ -129,7 +129,7 @@ public class CreateOfferService {
|
||||||
offerId,
|
offerId,
|
||||||
currencyCode,
|
currencyCode,
|
||||||
direction,
|
direction,
|
||||||
price.getValue(),
|
price == null ? null : price.getValue(),
|
||||||
useMarketBasedPrice,
|
useMarketBasedPrice,
|
||||||
marketPriceMargin,
|
marketPriceMargin,
|
||||||
amount.value,
|
amount.value,
|
||||||
|
@ -138,11 +138,17 @@ public class CreateOfferService {
|
||||||
|
|
||||||
long creationTime = new Date().getTime();
|
long creationTime = new Date().getTime();
|
||||||
NodeAddress makerAddress = p2PService.getAddress();
|
NodeAddress makerAddress = p2PService.getAddress();
|
||||||
boolean useMarketBasedPriceValue = useMarketBasedPrice &&
|
boolean useMarketBasedPriceValue = price == null &&
|
||||||
|
useMarketBasedPrice &&
|
||||||
isMarketPriceAvailable(currencyCode) &&
|
isMarketPriceAvailable(currencyCode) &&
|
||||||
!paymentAccount.hasPaymentMethodWithId(HAL_CASH_ID);
|
!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;
|
double marketPriceMarginParam = useMarketBasedPriceValue ? marketPriceMargin : 0;
|
||||||
long amountAsLong = amount != null ? amount.getValue() : 0L;
|
long amountAsLong = amount != null ? amount.getValue() : 0L;
|
||||||
long minAmountAsLong = minAmount != null ? minAmount.getValue() : 0L;
|
long minAmountAsLong = minAmount != null ? minAmount.getValue() : 0L;
|
||||||
|
|
|
@ -70,8 +70,8 @@ public class ValidateOffer extends Task<PlaceOfferModel> {
|
||||||
checkArgument(offer.getAmount().compareTo(offer.getMinAmount()) >= 0, "MinAmount is larger than Amount");
|
checkArgument(offer.getAmount().compareTo(offer.getMinAmount()) >= 0, "MinAmount is larger than Amount");
|
||||||
|
|
||||||
checkNotNull(offer.getPrice(), "Price is null");
|
checkNotNull(offer.getPrice(), "Price is null");
|
||||||
checkArgument(offer.getPrice().isPositive(),
|
if (!offer.isUseMarketBasedPrice()) checkArgument(offer.getPrice().isPositive(),
|
||||||
"Price must be positive. price=" + offer.getPrice().toFriendlyString());
|
"Price must be positive unless using market based price. price=" + offer.getPrice().toFriendlyString());
|
||||||
|
|
||||||
checkArgument(offer.getDate().getTime() > 0,
|
checkArgument(offer.getDate().getTime() > 0,
|
||||||
"Date must not be 0. date=" + offer.getDate().toString());
|
"Date must not be 0. date=" + offer.getDate().toString());
|
||||||
|
|
|
@ -27,14 +27,14 @@ public class PriceTest {
|
||||||
Price result = Price.parse("USD", "0.1");
|
Price result = Price.parse("USD", "0.1");
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Fiat value should be formatted with two decimals.",
|
"Fiat value should be formatted with two decimals.",
|
||||||
"0.10 BTC/USD",
|
"0.10 XMR/USD",
|
||||||
result.toFriendlyString()
|
result.toFriendlyString()
|
||||||
);
|
);
|
||||||
|
|
||||||
result = Price.parse("EUR", "0.1234");
|
result = Price.parse("EUR", "0.1234");
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Fiat value should be given two decimals",
|
"Fiat value should be given two decimals",
|
||||||
"0.1234 BTC/EUR",
|
"0.1234 XMR/EUR",
|
||||||
result.toFriendlyString()
|
result.toFriendlyString()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -57,19 +57,19 @@ public class PriceTest {
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Comma (',') as decimal separator should be converted to period ('.')",
|
"Comma (',') as decimal separator should be converted to period ('.')",
|
||||||
"0.0001 BTC/USD",
|
"0.0001 XMR/USD",
|
||||||
Price.parse("USD", "0,0001").toFriendlyString()
|
Price.parse("USD", "0,0001").toFriendlyString()
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Too many decimals should get rounded up properly.",
|
"Too many decimals should get rounded up properly.",
|
||||||
"10000.2346 LTC/BTC",
|
"10000.2346 LTC/XMR",
|
||||||
Price.parse("LTC", "10000,23456789").toFriendlyString()
|
Price.parse("LTC", "10000,23456789").toFriendlyString()
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Too many decimals should get rounded down properly.",
|
"Too many decimals should get rounded down properly.",
|
||||||
"10000.2345 LTC/BTC",
|
"10000.2345 LTC/XMR",
|
||||||
Price.parse("LTC", "10000,23454999").toFriendlyString()
|
Price.parse("LTC", "10000,23454999").toFriendlyString()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -95,14 +95,14 @@ public class PriceTest {
|
||||||
Price result = Price.valueOf("USD", 1);
|
Price result = Price.valueOf("USD", 1);
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Fiat value should have four decimals.",
|
"Fiat value should have four decimals.",
|
||||||
"0.0001 BTC/USD",
|
"0.0001 XMR/USD",
|
||||||
result.toFriendlyString()
|
result.toFriendlyString()
|
||||||
);
|
);
|
||||||
|
|
||||||
result = Price.valueOf("EUR", 1234);
|
result = Price.valueOf("EUR", 1234);
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Fiat value should be given two decimals",
|
"Fiat value should be given two decimals",
|
||||||
"0.1234 BTC/EUR",
|
"0.1234 XMR/EUR",
|
||||||
result.toFriendlyString()
|
result.toFriendlyString()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -114,13 +114,13 @@ public class PriceTest {
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Too many decimals should get rounded up properly.",
|
"Too many decimals should get rounded up properly.",
|
||||||
"10000.2346 LTC/BTC",
|
"10000.2346 LTC/XMR",
|
||||||
Price.valueOf("LTC", 1000023456789L).toFriendlyString()
|
Price.valueOf("LTC", 1000023456789L).toFriendlyString()
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Too many decimals should get rounded down properly.",
|
"Too many decimals should get rounded down properly.",
|
||||||
"10000.2345 LTC/BTC",
|
"10000.2345 LTC/XMR",
|
||||||
Price.valueOf("LTC", 1000023454999L).toFriendlyString()
|
Price.valueOf("LTC", 1000023454999L).toFriendlyString()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ import bisq.core.offer.OpenOffer;
|
||||||
import bisq.core.util.ParsingUtils;
|
import bisq.core.util.ParsingUtils;
|
||||||
import bisq.proto.grpc.CancelOfferReply;
|
import bisq.proto.grpc.CancelOfferReply;
|
||||||
import bisq.proto.grpc.CancelOfferRequest;
|
import bisq.proto.grpc.CancelOfferRequest;
|
||||||
import bisq.proto.grpc.CreateOfferReply;
|
import bisq.proto.grpc.PostOfferReply;
|
||||||
import bisq.proto.grpc.CreateOfferRequest;
|
import bisq.proto.grpc.PostOfferRequest;
|
||||||
import bisq.proto.grpc.GetMyOfferReply;
|
import bisq.proto.grpc.GetMyOfferReply;
|
||||||
import bisq.proto.grpc.GetMyOfferRequest;
|
import bisq.proto.grpc.GetMyOfferRequest;
|
||||||
import bisq.proto.grpc.GetMyOffersReply;
|
import bisq.proto.grpc.GetMyOffersReply;
|
||||||
|
@ -140,15 +140,15 @@ class GrpcOffersService extends OffersImplBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createOffer(CreateOfferRequest req,
|
public void postOffer(PostOfferRequest req,
|
||||||
StreamObserver<CreateOfferReply> responseObserver) {
|
StreamObserver<PostOfferReply> responseObserver) {
|
||||||
GrpcErrorMessageHandler errorMessageHandler =
|
GrpcErrorMessageHandler errorMessageHandler =
|
||||||
new GrpcErrorMessageHandler(getCreateOfferMethod().getFullMethodName(),
|
new GrpcErrorMessageHandler(getPostOfferMethod().getFullMethodName(),
|
||||||
responseObserver,
|
responseObserver,
|
||||||
exceptionHandler,
|
exceptionHandler,
|
||||||
log);
|
log);
|
||||||
try {
|
try {
|
||||||
coreApi.createAnPlaceOffer(
|
coreApi.postOffer(
|
||||||
req.getCurrencyCode(),
|
req.getCurrencyCode(),
|
||||||
req.getDirection(),
|
req.getDirection(),
|
||||||
req.getPrice(),
|
req.getPrice(),
|
||||||
|
@ -164,7 +164,7 @@ class GrpcOffersService extends OffersImplBase {
|
||||||
// the new offer to the gRPC client after async placement is done.
|
// the new offer to the gRPC client after async placement is done.
|
||||||
OpenOffer openOffer = coreApi.getMyOpenOffer(offer.getId());
|
OpenOffer openOffer = coreApi.getMyOpenOffer(offer.getId());
|
||||||
OfferInfo offerInfo = OfferInfo.toMyOfferInfo(openOffer);
|
OfferInfo offerInfo = OfferInfo.toMyOfferInfo(openOffer);
|
||||||
CreateOfferReply reply = CreateOfferReply.newBuilder()
|
PostOfferReply reply = PostOfferReply.newBuilder()
|
||||||
.setOffer(offerInfo.toProtoMessage())
|
.setOffer(offerInfo.toProtoMessage())
|
||||||
.build();
|
.build();
|
||||||
responseObserver.onNext(reply);
|
responseObserver.onNext(reply);
|
||||||
|
@ -206,7 +206,7 @@ class GrpcOffersService extends OffersImplBase {
|
||||||
put(getGetMyOfferMethod().getFullMethodName(), new GrpcCallRateMeter(10, SECONDS));
|
put(getGetMyOfferMethod().getFullMethodName(), new GrpcCallRateMeter(10, SECONDS));
|
||||||
put(getGetOffersMethod().getFullMethodName(), new GrpcCallRateMeter(20, SECONDS));
|
put(getGetOffersMethod().getFullMethodName(), new GrpcCallRateMeter(20, SECONDS));
|
||||||
put(getGetMyOffersMethod().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));
|
put(getCancelOfferMethod().getFullMethodName(), new GrpcCallRateMeter(10, SECONDS));
|
||||||
}}
|
}}
|
||||||
)));
|
)));
|
||||||
|
|
|
@ -446,7 +446,7 @@ service Offers {
|
||||||
}
|
}
|
||||||
rpc GetMyOffers (GetMyOffersRequest) returns (GetMyOffersReply) {
|
rpc GetMyOffers (GetMyOffersRequest) returns (GetMyOffersReply) {
|
||||||
}
|
}
|
||||||
rpc CreateOffer (CreateOfferRequest) returns (CreateOfferReply) {
|
rpc PostOffer (PostOfferRequest) returns (PostOfferReply) {
|
||||||
}
|
}
|
||||||
rpc CancelOffer (CancelOfferRequest) returns (CancelOfferReply) {
|
rpc CancelOffer (CancelOfferRequest) returns (CancelOfferReply) {
|
||||||
}
|
}
|
||||||
|
@ -486,7 +486,7 @@ message GetMyOffersReply {
|
||||||
repeated OfferInfo offers = 1;
|
repeated OfferInfo offers = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateOfferRequest {
|
message PostOfferRequest {
|
||||||
string currency_code = 1;
|
string currency_code = 1;
|
||||||
string direction = 2;
|
string direction = 2;
|
||||||
string price = 3;
|
string price = 3;
|
||||||
|
@ -499,7 +499,7 @@ message CreateOfferRequest {
|
||||||
string payment_account_id = 10;
|
string payment_account_id = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateOfferReply {
|
message PostOfferReply {
|
||||||
OfferInfo offer = 1;
|
OfferInfo offer = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue