Merge pull request #5076 from ghubstan/03-support-trigger-price

Stub out support for OpenOffer's triggerPrice in api
This commit is contained in:
sqrrm 2021-01-14 10:34:29 +01:00 committed by GitHub
commit f838b1a475
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 17 deletions

View file

@ -125,7 +125,7 @@ public class TableFormat {
+ padEnd(COL_HEADER_PAYMENT_METHOD, paymentMethodColWidth, ' ') + COL_HEADER_DELIMITER
+ COL_HEADER_CREATION_DATE + COL_HEADER_DELIMITER
+ COL_HEADER_UUID.trim() + "%n";
String headerLine = format(headersFormat, fiatCurrency, fiatCurrency);
String headerLine = format(headersFormat, fiatCurrency.toUpperCase(), fiatCurrency.toUpperCase());
String colDataFormat = "%-" + (COL_HEADER_DIRECTION.length() + COL_HEADER_DELIMITER.length()) + "s" // left
+ "%" + (COL_HEADER_PRICE.length() - 1) + "s" // rt justify to end of hdr

View file

@ -24,6 +24,7 @@ import bisq.core.btc.wallet.TxBroadcaster;
import bisq.core.monetary.Price;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload;
import bisq.core.offer.OpenOffer;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.trade.Trade;
@ -120,6 +121,10 @@ public class CoreApi {
return coreOffersService.getMyOffers(direction, currencyCode);
}
public OpenOffer getMyOpenOffer(String id) {
return coreOffersService.getMyOpenOffer(id);
}
public void createAnPlaceOffer(String currencyCode,
String directionAsString,
String priceAsString,
@ -128,6 +133,7 @@ public class CoreApi {
long amountAsLong,
long minAmountAsLong,
double buyerSecurityDeposit,
long triggerPrice,
String paymentAccountId,
String makerFeeCurrencyCode,
Consumer<Offer> resultHandler) {
@ -139,6 +145,7 @@ public class CoreApi {
amountAsLong,
minAmountAsLong,
buyerSecurityDeposit,
triggerPrice,
paymentAccountId,
makerFeeCurrencyCode,
resultHandler);

View file

@ -24,6 +24,7 @@ import bisq.core.offer.Offer;
import bisq.core.offer.OfferBookService;
import bisq.core.offer.OfferFilter;
import bisq.core.offer.OfferUtil;
import bisq.core.offer.OpenOffer;
import bisq.core.offer.OpenOfferManager;
import bisq.core.payment.PaymentAccount;
import bisq.core.user.User;
@ -123,6 +124,13 @@ class CoreOffersService {
.collect(Collectors.toList());
}
OpenOffer getMyOpenOffer(String id) {
return openOfferManager.getOpenOfferById(id)
.filter(open -> open.getOffer().isMyOffer(keyRing))
.orElseThrow(() ->
new IllegalStateException(format("openoffer with id '%s' not found", id)));
}
// Create and place new offer.
void createAndPlaceOffer(String currencyCode,
String directionAsString,
@ -132,6 +140,7 @@ class CoreOffersService {
long amountAsLong,
long minAmountAsLong,
double buyerSecurityDeposit,
long triggerPrice,
String paymentAccountId,
String makerFeeCurrencyCode,
Consumer<Offer> resultHandler) {
@ -163,6 +172,7 @@ class CoreOffersService {
//noinspection ConstantConditions
placeOffer(offer,
buyerSecurityDeposit,
triggerPrice,
useSavingsWallet,
transaction -> resultHandler.accept(offer));
}
@ -204,13 +214,13 @@ class CoreOffersService {
private void placeOffer(Offer offer,
double buyerSecurityDeposit,
long triggerPrice,
boolean useSavingsWallet,
Consumer<Transaction> resultHandler) {
// TODO add support for triggerPrice parameter. If value is 0 it is interpreted as not used. Its an optional value
openOfferManager.placeOffer(offer,
buyerSecurityDeposit,
useSavingsWallet,
0,
triggerPrice,
resultHandler::accept,
log::error);

View file

@ -46,8 +46,9 @@ public class OfferInfo implements Payload {
private final long volume;
private final long minVolume;
private final long buyerSecurityDeposit;
private final long triggerPrice;
private final boolean isCurrencyForMakerFeeBtc;
private final String paymentAccountId; // only used when creating offer
private final String paymentAccountId;
private final String paymentMethodId;
private final String paymentMethodShortName;
// For fiat offer the baseCurrencyCode is BTC and the counterCurrencyCode is the fiat currency
@ -68,6 +69,7 @@ public class OfferInfo implements Payload {
this.volume = builder.volume;
this.minVolume = builder.minVolume;
this.buyerSecurityDeposit = builder.buyerSecurityDeposit;
this.triggerPrice = builder.triggerPrice;
this.isCurrencyForMakerFeeBtc = builder.isCurrencyForMakerFeeBtc;
this.paymentAccountId = builder.paymentAccountId;
this.paymentMethodId = builder.paymentMethodId;
@ -79,6 +81,16 @@ public class OfferInfo implements Payload {
}
public static OfferInfo toOfferInfo(Offer offer) {
return getOfferInfoBuilder(offer).build();
}
public static OfferInfo toOfferInfo(Offer offer, long triggerPrice) {
// The Offer does not have a triggerPrice attribute, so we get
// the base OfferInfoBuilder, then add the OpenOffer's triggerPrice.
return getOfferInfoBuilder(offer).withTriggerPrice(triggerPrice).build();
}
private static OfferInfo.OfferInfoBuilder getOfferInfoBuilder(Offer offer) {
return new OfferInfo.OfferInfoBuilder()
.withId(offer.getId())
.withDirection(offer.getDirection().name())
@ -97,8 +109,7 @@ public class OfferInfo implements Payload {
.withBaseCurrencyCode(offer.getOfferPayload().getBaseCurrencyCode())
.withCounterCurrencyCode(offer.getOfferPayload().getCounterCurrencyCode())
.withDate(offer.getDate().getTime())
.withState(offer.getState().name())
.build();
.withState(offer.getState().name());
}
///////////////////////////////////////////////////////////////////////////////////////////
@ -118,6 +129,7 @@ public class OfferInfo implements Payload {
.setVolume(volume)
.setMinVolume(minVolume)
.setBuyerSecurityDeposit(buyerSecurityDeposit)
.setTriggerPrice(triggerPrice)
.setIsCurrencyForMakerFeeBtc(isCurrencyForMakerFeeBtc)
.setPaymentAccountId(paymentAccountId)
.setPaymentMethodId(paymentMethodId)
@ -142,6 +154,7 @@ public class OfferInfo implements Payload {
.withVolume(proto.getVolume())
.withMinVolume(proto.getMinVolume())
.withBuyerSecurityDeposit(proto.getBuyerSecurityDeposit())
.withTriggerPrice(proto.getTriggerPrice())
.withIsCurrencyForMakerFeeBtc(proto.getIsCurrencyForMakerFeeBtc())
.withPaymentAccountId(proto.getPaymentAccountId())
.withPaymentMethodId(proto.getPaymentMethodId())
@ -170,6 +183,7 @@ public class OfferInfo implements Payload {
private long volume;
private long minVolume;
private long buyerSecurityDeposit;
private long triggerPrice;
private boolean isCurrencyForMakerFeeBtc;
private String paymentAccountId;
private String paymentMethodId;
@ -229,6 +243,11 @@ public class OfferInfo implements Payload {
return this;
}
public OfferInfoBuilder withTriggerPrice(long triggerPrice) {
this.triggerPrice = triggerPrice;
return this;
}
public OfferInfoBuilder withIsCurrencyForMakerFeeBtc(boolean isCurrencyForMakerFeeBtc) {
this.isCurrencyForMakerFeeBtc = isCurrencyForMakerFeeBtc;
return this;

View file

@ -20,6 +20,7 @@ package bisq.daemon.grpc;
import bisq.core.api.CoreApi;
import bisq.core.api.model.OfferInfo;
import bisq.core.offer.Offer;
import bisq.core.offer.OpenOffer;
import bisq.proto.grpc.CancelOfferReply;
import bisq.proto.grpc.CancelOfferRequest;
@ -78,8 +79,9 @@ class GrpcOffersService extends OffersGrpc.OffersImplBase {
StreamObserver<GetMyOfferReply> responseObserver) {
try {
Offer offer = coreApi.getMyOffer(req.getId());
OpenOffer openOffer = coreApi.getMyOpenOffer(req.getId());
var reply = GetMyOfferReply.newBuilder()
.setOffer(toOfferInfo(offer).toProtoMessage())
.setOffer(toOfferInfo(offer, openOffer.getTriggerPrice()).toProtoMessage())
.build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
@ -139,6 +141,7 @@ class GrpcOffersService extends OffersGrpc.OffersImplBase {
req.getAmount(),
req.getMinAmount(),
req.getBuyerSecurityDeposit(),
req.getTriggerPrice(),
req.getPaymentAccountId(),
req.getMakerFeeCurrencyCode(),
offer -> {

View file

@ -102,8 +102,9 @@ message CreateOfferRequest {
uint64 amount = 6;
uint64 minAmount = 7;
double buyerSecurityDeposit = 8;
string paymentAccountId = 9;
string makerFeeCurrencyCode = 10;
uint64 triggerPrice = 9;
string paymentAccountId = 10;
string makerFeeCurrencyCode = 11;
}
message CreateOfferReply {
@ -128,14 +129,15 @@ message OfferInfo {
uint64 volume = 8;
uint64 minVolume = 9;
uint64 buyerSecurityDeposit = 10;
bool isCurrencyForMakerFeeBtc = 11;
string paymentAccountId = 12;
string paymentMethodId = 13;
string paymentMethodShortName = 14;
string baseCurrencyCode = 15;
string counterCurrencyCode = 16;
uint64 date = 17;
string state = 18;
uint64 triggerPrice = 11;
bool isCurrencyForMakerFeeBtc = 12;
string paymentAccountId = 13;
string paymentMethodId = 14;
string paymentMethodShortName = 15;
string baseCurrencyCode = 16;
string counterCurrencyCode = 17;
uint64 date = 18;
string state = 19;
}
///////////////////////////////////////////////////////////////////////////////////////////