Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "all" attribute in getoffers API method #6646

Merged
merged 1 commit into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public void testGetAllMyBsqOffers() {
@Test
@Order(6)
public void testGetAvailableBsqOffers() {
List<OfferInfo> offers = bobClient.getOffersSortedByDate(BSQ);
List<OfferInfo> offers = bobClient.getOffersSortedByDate(BSQ, false);
log.debug("All Bob's Available BSQ Offers:\n{}", toOffersTable.apply(offers));
assertEquals(4, offers.size());
log.debug("BOB'S BALANCES\n{}", formatBalancesTbls(bobClient.getBalances()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void testGetAllMyXMROffers() {
@Test
@Order(6)
public void testGetAvailableXMROffers() {
List<OfferInfo> offers = bobClient.getOffersSortedByDate(XMR);
List<OfferInfo> offers = bobClient.getOffersSortedByDate(XMR, false);
log.debug("All of Bob's available XMR offers:\n{}", toOffersTable.apply(offers));
assertEquals(4, offers.size());
log.debug("Bob's balances\n{}", formatBalancesTbls(bobClient.getBalances()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testTakeAlicesSellOffer(final TestInfo testInfo) {
0L,
false);
sleep(2_500); // Allow available offer to be removed from offer book.
var takeableUsdOffers = bobClient.getOffersSortedByDate(SELL.name(), USD);
var takeableUsdOffers = bobClient.getOffersSortedByDate(SELL.name(), USD, false);
assertEquals(0, takeableUsdOffers.size());

trade = bobClient.getTrade(tradeId);
Expand Down
3 changes: 2 additions & 1 deletion cli/src/main/java/bisq/cli/CliMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ public static void run(String[] args) {
}
var direction = opts.getDirection();
var currencyCode = opts.getCurrencyCode();
List<OfferInfo> offers = client.getOffers(direction, currencyCode);
var all = opts.getAll();
List<OfferInfo> offers = client.getOffers(direction, currencyCode, all);
if (offers.isEmpty())
out.printf("no %s %s offers found%n", direction, currencyCode);
else
Expand Down
12 changes: 6 additions & 6 deletions cli/src/main/java/bisq/cli/GrpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,16 @@ public List<OfferInfo> getBsqSwapOffers(String direction) {
return offersServiceRequest.getBsqSwapOffers(direction);
}

public List<OfferInfo> getOffers(String direction, String currencyCode) {
return offersServiceRequest.getOffers(direction, currencyCode);
public List<OfferInfo> getOffers(String direction, String currencyCode, boolean all) {
return offersServiceRequest.getOffers(direction, currencyCode, all);
}

public List<OfferInfo> getOffersSortedByDate(String currencyCode) {
return offersServiceRequest.getOffersSortedByDate(currencyCode);
public List<OfferInfo> getOffersSortedByDate(String currencyCode, boolean all) {
return offersServiceRequest.getOffersSortedByDate(currencyCode, all);
}

public List<OfferInfo> getOffersSortedByDate(String direction, String currencyCode) {
return offersServiceRequest.getOffersSortedByDate(direction, currencyCode);
public List<OfferInfo> getOffersSortedByDate(String direction, String currencyCode, boolean all) {
return offersServiceRequest.getOffersSortedByDate(direction, currencyCode, all);
}

public List<OfferInfo> getBsqSwapOffersSortedByDate() {
Expand Down
10 changes: 10 additions & 0 deletions cli/src/main/java/bisq/cli/opts/GetOffersOptionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import joptsimple.OptionSpec;

import static bisq.cli.opts.OptLabel.OPT_ALL;
import static bisq.cli.opts.OptLabel.OPT_CURRENCY_CODE;
import static bisq.cli.opts.OptLabel.OPT_DIRECTION;

Expand All @@ -31,6 +32,11 @@ public class GetOffersOptionParser extends AbstractMethodOptionParser implements
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency code (bsq|xmr|eur|usd|...)")
.withRequiredArg();

final OptionSpec<Boolean> allOpt = parser.accepts(OPT_ALL, "get all offers")
.withOptionalArg()
.ofType(boolean.class)
.defaultsTo(Boolean.FALSE);

public GetOffersOptionParser(String[] args) {
super(args);
}
Expand Down Expand Up @@ -58,4 +64,8 @@ public String getDirection() {
public String getCurrencyCode() {
return options.valueOf(currencyCodeOpt);
}

public boolean getAll() {
return options.valueOf(allOpt);
}
}
1 change: 1 addition & 0 deletions cli/src/main/java/bisq/cli/opts/OptLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class OptLabel {
public final static String OPT_AMOUNT = "amount";
public final static String OPT_CATEGORY = "category";
public final static String OPT_CURRENCY_CODE = "currency-code";
public final static String OPT_ALL = "all";
public final static String OPT_DAYS = "days";
public final static String OPT_DIRECTION = "direction";
public final static String OPT_DISPUTE_AGENT_TYPE = "dispute-agent-type";
Expand Down
17 changes: 9 additions & 8 deletions cli/src/main/java/bisq/cli/request/OffersServiceRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,24 @@ public List<OfferInfo> getBsqSwapOffers(String direction) {
return grpcStubs.offersService.getBsqSwapOffers(request).getBsqSwapOffersList();
}

public List<OfferInfo> getOffers(String direction, String currencyCode) {
public List<OfferInfo> getOffers(String direction, String currencyCode, boolean all) {
var request = GetOffersRequest.newBuilder()
.setDirection(direction)
.setCurrencyCode(currencyCode)
.setAll(all)
.build();
return grpcStubs.offersService.getOffers(request).getOffersList();
}

public List<OfferInfo> getOffersSortedByDate(String currencyCode) {
public List<OfferInfo> getOffersSortedByDate(String currencyCode, boolean all) {
ArrayList<OfferInfo> offers = new ArrayList<>();
offers.addAll(getOffers(BUY.name(), currencyCode));
offers.addAll(getOffers(SELL.name(), currencyCode));
offers.addAll(getOffers(BUY.name(), currencyCode, all));
offers.addAll(getOffers(SELL.name(), currencyCode, all));
return offers.isEmpty() ? offers : sortOffersByDate(offers);
}

public List<OfferInfo> getOffersSortedByDate(String direction, String currencyCode) {
var offers = getOffers(direction, currencyCode);
public List<OfferInfo> getOffersSortedByDate(String direction, String currencyCode, boolean all) {
var offers = getOffers(direction, currencyCode, all);
return offers.isEmpty() ? offers : sortOffersByDate(offers);
}

Expand Down Expand Up @@ -292,8 +293,8 @@ public List<OfferInfo> getMyBsqSwapOffersSortedByDate() {
return sortOffersByDate(offers);
}

public OfferInfo getMostRecentOffer(String direction, String currencyCode) {
List<OfferInfo> offers = getOffersSortedByDate(direction, currencyCode);
public OfferInfo getMostRecentOffer(String direction, String currencyCode, boolean all) {
List<OfferInfo> offers = getOffersSortedByDate(direction, currencyCode, all);
return offers.isEmpty() ? null : offers.get(offers.size() - 1);
}

Expand Down
12 changes: 6 additions & 6 deletions cli/src/test/java/bisq/cli/table/GetOffersCliOutputDiffTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ private void getMySellUsdOffers() {
}

private void getAvailableBuyUsdOffers() {
var offers = bobClient.getOffers(BUY.name(), "USD");
var offers = bobClient.getOffers(BUY.name(), "USD", false);
printAndCheckDiffs(offers, BUY.name(), "USD");
}

private void getAvailableSellUsdOffers() {
var offers = bobClient.getOffers(SELL.name(), "USD");
var offers = bobClient.getOffers(SELL.name(), "USD", false);
printAndCheckDiffs(offers, SELL.name(), "USD");
}

Expand All @@ -79,12 +79,12 @@ private void getMySellXmrOffers() {
}

private void getAvailableBuyXmrOffers() {
var offers = bobClient.getOffers(BUY.name(), "XMR");
var offers = bobClient.getOffers(BUY.name(), "XMR", false);
printAndCheckDiffs(offers, BUY.name(), "XMR");
}

private void getAvailableSellXmrOffers() {
var offers = bobClient.getOffers(SELL.name(), "XMR");
var offers = bobClient.getOffers(SELL.name(), "XMR", false);
printAndCheckDiffs(offers, SELL.name(), "XMR");
}

Expand All @@ -99,12 +99,12 @@ private void getMySellBsqOffers() {
}

private void getAvailableBuyBsqOffers() {
var offers = bobClient.getOffers(BUY.name(), "BSQ");
var offers = bobClient.getOffers(BUY.name(), "BSQ", false);
printAndCheckDiffs(offers, BUY.name(), "BSQ");
}

private void getAvailableSellBsqOffers() {
var offers = bobClient.getOffers(SELL.name(), "BSQ");
var offers = bobClient.getOffers(SELL.name(), "BSQ", false);
printAndCheckDiffs(offers, SELL.name(), "BSQ");
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public List<Offer> getBsqSwapOffers(String direction) {
return coreOffersService.getBsqSwapOffers(direction);
}

public List<Offer> getOffers(String direction, String currencyCode) {
return coreOffersService.getOffers(direction, currencyCode);
public List<Offer> getOffers(String direction, String currencyCode, boolean all) {
return coreOffersService.getOffers(direction, currencyCode, all);
}

public List<OpenOffer> getMyOffers(String direction, String currencyCode) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/bisq/core/api/CoreOffersService.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ List<Offer> getBsqSwapOffers(String direction) {
.collect(Collectors.toList());
}

List<Offer> getOffers(String direction, String currencyCode) {
List<Offer> getOffers(String direction, String currencyCode, boolean all) {
var upperCaseCurrencyCode = currencyCode.toUpperCase();
var isFiat = isFiatCurrency(upperCaseCurrencyCode);
if (isFiat) {
return offerBookService.getOffers().stream()
.filter(o -> !o.isMyOffer(keyRing))
.filter(o -> offerMatchesDirectionAndCurrency(o, direction, upperCaseCurrencyCode))
.filter(o -> offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid())
.filter(o -> all || offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid())
.sorted(priceComparator(direction, true))
.collect(Collectors.toList());
} else {
Expand All @@ -226,7 +226,7 @@ List<Offer> getOffers(String direction, String currencyCode) {
.filter(o -> !o.isMyOffer(keyRing))
.filter(o -> offerMatchesDirectionAndCurrency(o, direction, "BTC"))
.filter(o -> o.getBaseCurrencyCode().equalsIgnoreCase(upperCaseCurrencyCode))
.filter(o -> offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid())
.filter(o -> all || offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid())
.sorted(priceComparator(direction, false))
.collect(Collectors.toList());
else
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/resources/help/getoffers-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SYNOPSIS
getoffers
--direction=<buy|sell>
--currency-code=<eur|usd>
--all=<true|false>

DESCRIPTION
-----------
Expand All @@ -24,6 +25,9 @@ OPTIONS
--currency-code
The three letter code for the fiat used to buy or sell BTC, e.g., EUR, USD, BRL, ...

--all
Whether return all offers or only these matching my accounts

EXAMPLES
--------
You have one Brazilian Real payment account with a face-to-face payment method type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void getBsqSwapOffers(GetBsqSwapOffersRequest req,
public void getOffers(GetOffersRequest req,
StreamObserver<GetOffersReply> responseObserver) {
try {
List<OfferInfo> result = coreApi.getOffers(req.getDirection(), req.getCurrencyCode())
List<OfferInfo> result = coreApi.getOffers(req.getDirection(), req.getCurrencyCode(), req.getAll())
.stream()
.map(OfferInfo::toOfferInfo)
.collect(Collectors.toList());
Expand Down
1 change: 1 addition & 0 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ message GetMyOfferReply {
message GetOffersRequest {
string direction = 1; // The offer's BUY (BTC) or SELL (BTC) direction.
string currency_code = 2; // The offer's fiat or altcoin currency code.
bool all = 3; // Return all or only these matching my account
}

message GetOffersReply {
Expand Down