Skip to content

Commit

Permalink
Merge pull request #3034 from HenrikJannsen/add-offer-api
Browse files Browse the repository at this point in the history
Add getOfferbookMarket endpoint
  • Loading branch information
HenrikJannsen authored Nov 26, 2024
2 parents 6108035 + fcc1204 commit 790c0d1
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package bisq.desktop.main.content.bisq_easy.open_trades.trade_details;

import bisq.account.payment_method.BitcoinPaymentRail;
import bisq.bisq_easy.BisqEasyServiceUtil;
import bisq.bisq_easy.NavigationTarget;
import bisq.chat.bisqeasy.open_trades.BisqEasyOpenTradeChannel;
import bisq.contract.bisq_easy.BisqEasyContract;
Expand All @@ -29,6 +28,7 @@
import bisq.desktop.overlay.OverlayController;
import bisq.i18n.Res;
import bisq.offer.price.spec.FixPriceSpec;
import bisq.offer.price.spec.PriceSpecFormatter;
import bisq.presentation.formatters.DateFormatter;
import bisq.presentation.formatters.PriceFormatter;
import bisq.trade.bisq_easy.BisqEasyTrade;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void onActivate() {
model.setPriceCodes(trade.getOffer().getMarket().getMarketCodes());
model.setPriceSpec(trade.getOffer().getPriceSpec() instanceof FixPriceSpec
? ""
: String.format("(%s)", BisqEasyServiceUtil.getFormattedPriceSpec(trade.getOffer().getPriceSpec(), true)));
: String.format("(%s)", PriceSpecFormatter.getFormattedPriceSpec(trade.getOffer().getPriceSpec(), true)));
model.setPaymentMethod(contract.getQuoteSidePaymentMethodSpec().getShortDisplayString());
model.setSettlementMethod(contract.getBaseSidePaymentMethodSpec().getShortDisplayString());
model.setTradeId(trade.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import bisq.desktop.main.content.bisq_easy.open_trades.trade_state.states.*;
import bisq.i18n.Res;
import bisq.offer.price.spec.PriceSpec;
import bisq.offer.price.spec.PriceSpecFormatter;
import bisq.settings.DontShowAgainService;
import bisq.support.mediation.MediationRequestService;
import bisq.trade.bisq_easy.BisqEasyTrade;
Expand Down Expand Up @@ -165,10 +166,10 @@ public void onActivate() {

model.getBuyerPriceDescriptionApprovalOverlay().set(
Res.get("bisqEasy.tradeState.acceptOrRejectSellersPrice.description.buyersPrice",
BisqEasyServiceUtil.getFormattedPriceSpec(bisqEasyTrade.getOffer().getPriceSpec())));
PriceSpecFormatter.getFormattedPriceSpec(bisqEasyTrade.getOffer().getPriceSpec())));
model.getSellerPriceDescriptionApprovalOverlay().set(
Res.get("bisqEasy.tradeState.acceptOrRejectSellersPrice.description.sellersPrice",
BisqEasyServiceUtil.getFormattedPriceSpec(bisqEasyTrade.getContract().getAgreedPriceSpec())));
PriceSpecFormatter.getFormattedPriceSpec(bisqEasyTrade.getContract().getAgreedPriceSpec())));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import bisq.offer.payment_method.PaymentMethodSpecFormatter;
import bisq.offer.payment_method.PaymentMethodSpecUtil;
import bisq.offer.price.spec.PriceSpec;
import bisq.offer.price.spec.PriceSpecFormatter;
import bisq.presentation.formatters.DateFormatter;
import bisq.trade.Trade;
import bisq.trade.bisq_easy.BisqEasyTradeService;
Expand Down Expand Up @@ -270,7 +271,7 @@ public Optional<Pair<String, String>> getBisqEasyOfferAmountAndPriceSpec() {
boolean hasAmountRange = amountSpec instanceof RangeAmountSpec;
Market market = offer.getMarket();
String quoteAmountAsString = OfferAmountFormatter.formatQuoteAmount(marketPriceService, amountSpec, priceSpec, market, hasAmountRange, true);
String priceSpecAsString = BisqEasyServiceUtil.getFormattedPriceSpec(priceSpec);
String priceSpecAsString = PriceSpecFormatter.getFormattedPriceSpec(priceSpec);
return Optional.of(new Pair<>(quoteAmountAsString, priceSpecAsString));
}
return Optional.empty();
Expand Down
34 changes: 3 additions & 31 deletions bisq-easy/src/main/java/bisq/bisq_easy/BisqEasyServiceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@
import bisq.offer.amount.spec.RangeAmountSpec;
import bisq.offer.bisq_easy.BisqEasyOffer;
import bisq.offer.payment_method.PaymentMethodSpecFormatter;
import bisq.offer.price.spec.FixPriceSpec;
import bisq.offer.price.spec.FloatPriceSpec;
import bisq.offer.price.spec.PriceSpec;
import bisq.presentation.formatters.PercentageFormatter;
import bisq.presentation.formatters.PriceFormatter;
import bisq.offer.price.spec.PriceSpecFormatter;
import bisq.trade.Trade;
import bisq.trade.bisq_easy.BisqEasyTrade;
import bisq.trade.bisq_easy.BisqEasyTradeService;
Expand Down Expand Up @@ -74,31 +71,6 @@ public static boolean authorNotBannedOrIgnored(UserProfileService userProfileSer
return true;
}

public static String getFormattedPriceSpec(PriceSpec priceSpec) {
return getFormattedPriceSpec(priceSpec, false);
}

public static String getFormattedPriceSpec(PriceSpec priceSpec, boolean abbreviated) {
String priceInfo;
if (priceSpec instanceof FixPriceSpec fixPriceSpec) {
String price = PriceFormatter.formatWithCode(fixPriceSpec.getPriceQuote());
priceInfo = Res.get("bisqEasy.tradeWizard.review.chatMessage.fixPrice", price);
} else if (priceSpec instanceof FloatPriceSpec floatPriceSpec) {
String percent = PercentageFormatter.formatToPercentWithSymbol(Math.abs(floatPriceSpec.getPercentage()));
priceInfo = Res.get(floatPriceSpec.getPercentage() >= 0
? abbreviated
? "bisqEasy.tradeWizard.review.chatMessage.floatPrice.plus"
: "bisqEasy.tradeWizard.review.chatMessage.floatPrice.above"
: abbreviated
? "bisqEasy.tradeWizard.review.chatMessage.floatPrice.minus"
: "bisqEasy.tradeWizard.review.chatMessage.floatPrice.below"
, percent);
} else {
priceInfo = Res.get("bisqEasy.tradeWizard.review.chatMessage.marketPrice");
}
return priceInfo;
}

public static boolean isMaker(UserIdentityService userIdentityService, BisqEasyOffer bisqEasyOffer) {
return bisqEasyOffer.isMyOffer(userIdentityService.getMyUserProfileIds());
}
Expand All @@ -121,7 +93,7 @@ public static String createBasicOfferBookMessage(MarketPriceService marketPriceS
String fiatPaymentMethodNames,
AmountSpec amountSpec,
PriceSpec priceSpec) {
String priceInfo = String.format("%s %s", Res.get("bisqEasy.tradeWizard.review.chatMessage.price"), getFormattedPriceSpec(priceSpec));
String priceInfo = String.format("%s %s", Res.get("bisqEasy.tradeWizard.review.chatMessage.price"), PriceSpecFormatter.getFormattedPriceSpec(priceSpec));
boolean hasAmountRange = amountSpec instanceof RangeAmountSpec;
String quoteAmountAsString = OfferAmountFormatter.formatQuoteAmount(marketPriceService, amountSpec, priceSpec, market, hasAmountRange, true);
return Res.get("bisqEasy.tradeWizard.review.chatMessage.offerDetails", quoteAmountAsString, bitcoinPaymentMethodNames, fiatPaymentMethodNames, priceInfo);
Expand Down Expand Up @@ -156,7 +128,7 @@ public static String createOfferBookMessageFromPeerPerspective(String messageOwn
AmountSpec amountSpec,
PriceSpec priceSpec) {
String ownerNickName = StringUtils.truncate(messageOwnerNickName, 28);
String priceInfo = String.format("%s %s", Res.get("bisqEasy.tradeWizard.review.chatMessage.price"), getFormattedPriceSpec(priceSpec));
String priceInfo = String.format("%s %s", Res.get("bisqEasy.tradeWizard.review.chatMessage.price"), PriceSpecFormatter.getFormattedPriceSpec(priceSpec));
boolean hasAmountRange = amountSpec instanceof RangeAmountSpec;
String quoteAmountAsString = OfferAmountFormatter.formatQuoteAmount(marketPriceService, amountSpec, priceSpec, market, hasAmountRange, true);
return buildOfferBookMessage(ownerNickName, direction, quoteAmountAsString, bitcoinPaymentMethodNames, fiatPaymentMethodNames, priceInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ public Response getQuotes() {
));

if (result.isEmpty()) {
return buildResponse(Response.Status.NOT_FOUND, "No market price quotes found.");
return buildNotFoundResponse("No market price quotes found.");
}

return buildResponse(Response.Status.OK, new MarketPriceResponse(result));
return buildOkResponse(new MarketPriceResponse(result));
} catch (Exception ex) {
log.error("Failed to retrieve market price quotes", ex);
return buildResponse(Response.Status.INTERNAL_SERVER_ERROR, "An error occurred while retrieving market prices.");
return buildErrorResponse("An error occurred while retrieving market prices.");
}
}

Expand Down
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ tasks.register("buildAll") {
":apps:desktop:desktop-app:build",
":apps:desktop:desktop-app:installDist",
":apps:desktop:desktop-app-launcher:generateInstallers",
":apps:desktop:webcam-app:build",
":apps:oracle-node-app:build",
":apps:rest-api-app:build",
":apps:node-monitor-web-app:build",
// ":REPLACEME:build",
).forEach {
exec {
Expand Down
1 change: 1 addition & 0 deletions chat/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies {
implementation(project(":persistence"))
implementation(project(":security"))
implementation(project(":identity"))
implementation(project(":account"))
implementation(project(":user"))
implementation(project(":offer"))
implementation(project(":settings"))
Expand Down
Loading

0 comments on commit 790c0d1

Please sign in to comment.