mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-01 01:32:17 +01:00
Merge pull request #7329 from alvasw/api_getoffers_show_all_offers_by_default
getoffers (api): Return all offers by default
This commit is contained in:
commit
cfacafdb2d
15 changed files with 30 additions and 51 deletions
|
@ -277,7 +277,7 @@ public class CreateBSQOffersTest extends AbstractOfferTest {
|
||||||
@Test
|
@Test
|
||||||
@Order(6)
|
@Order(6)
|
||||||
public void testGetAvailableBsqOffers() {
|
public void testGetAvailableBsqOffers() {
|
||||||
List<OfferInfo> offers = bobClient.getOffersSortedByDate(BSQ, false);
|
List<OfferInfo> offers = bobClient.getOffersSortedByDate(BSQ);
|
||||||
log.debug("All Bob's Available BSQ Offers:\n{}", toOffersTable.apply(offers));
|
log.debug("All Bob's Available BSQ Offers:\n{}", toOffersTable.apply(offers));
|
||||||
assertEquals(4, offers.size());
|
assertEquals(4, offers.size());
|
||||||
log.debug("BOB'S BALANCES\n{}", formatBalancesTbls(bobClient.getBalances()));
|
log.debug("BOB'S BALANCES\n{}", formatBalancesTbls(bobClient.getBalances()));
|
||||||
|
|
|
@ -274,7 +274,7 @@ public class CreateXMROffersTest extends AbstractOfferTest {
|
||||||
@Test
|
@Test
|
||||||
@Order(6)
|
@Order(6)
|
||||||
public void testGetAvailableXMROffers() {
|
public void testGetAvailableXMROffers() {
|
||||||
List<OfferInfo> offers = bobClient.getOffersSortedByDate(XMR, false);
|
List<OfferInfo> offers = bobClient.getOffersSortedByDate(XMR);
|
||||||
log.debug("All of Bob's available XMR offers:\n{}", toOffersTable.apply(offers));
|
log.debug("All of Bob's available XMR offers:\n{}", toOffersTable.apply(offers));
|
||||||
assertEquals(4, offers.size());
|
assertEquals(4, offers.size());
|
||||||
log.debug("Bob's balances\n{}", formatBalancesTbls(bobClient.getBalances()));
|
log.debug("Bob's balances\n{}", formatBalancesTbls(bobClient.getBalances()));
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class TakeBuyBTCOfferTest extends AbstractTradeTest {
|
||||||
// Wait for Alice's AddToOfferBook task.
|
// Wait for Alice's AddToOfferBook task.
|
||||||
// Wait times vary; my logs show >= 2-second delay.
|
// Wait times vary; my logs show >= 2-second delay.
|
||||||
var timeout = System.currentTimeMillis() + 3000;
|
var timeout = System.currentTimeMillis() + 3000;
|
||||||
while (bobClient.getOffersSortedByDate(USD, true).size() < 1) {
|
while (bobClient.getOffersSortedByDate(USD).size() < 1) {
|
||||||
sleep(100);
|
sleep(100);
|
||||||
if (System.currentTimeMillis() > timeout)
|
if (System.currentTimeMillis() > timeout)
|
||||||
fail(new TimeoutException("Timed out waiting for Offer to be added to OfferBook"));
|
fail(new TimeoutException("Timed out waiting for Offer to be added to OfferBook"));
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class TakeSellBTCOfferTest extends AbstractTradeTest {
|
||||||
0L,
|
0L,
|
||||||
false);
|
false);
|
||||||
sleep(2_500); // Allow available offer to be removed from offer book.
|
sleep(2_500); // Allow available offer to be removed from offer book.
|
||||||
var takeableUsdOffers = bobClient.getOffersSortedByDate(SELL.name(), USD, false);
|
var takeableUsdOffers = bobClient.getOffersSortedByDate(SELL.name(), USD);
|
||||||
assertEquals(0, takeableUsdOffers.size());
|
assertEquals(0, takeableUsdOffers.size());
|
||||||
|
|
||||||
trade = bobClient.getTrade(tradeId);
|
trade = bobClient.getTrade(tradeId);
|
||||||
|
|
|
@ -487,8 +487,7 @@ public class CliMain {
|
||||||
}
|
}
|
||||||
var direction = opts.getDirection();
|
var direction = opts.getDirection();
|
||||||
var currencyCode = opts.getCurrencyCode();
|
var currencyCode = opts.getCurrencyCode();
|
||||||
var all = opts.getAll();
|
List<OfferInfo> offers = client.getOffers(direction, currencyCode);
|
||||||
List<OfferInfo> offers = client.getOffers(direction, currencyCode, all);
|
|
||||||
if (offers.isEmpty())
|
if (offers.isEmpty())
|
||||||
out.printf("no %s %s offers found%n", direction, currencyCode);
|
out.printf("no %s %s offers found%n", direction, currencyCode);
|
||||||
else
|
else
|
||||||
|
|
|
@ -301,16 +301,16 @@ public final class GrpcClient {
|
||||||
return offersServiceRequest.getBsqSwapOffers(direction);
|
return offersServiceRequest.getBsqSwapOffers(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OfferInfo> getOffers(String direction, String currencyCode, boolean all) {
|
public List<OfferInfo> getOffers(String direction, String currencyCode) {
|
||||||
return offersServiceRequest.getOffers(direction, currencyCode, all);
|
return offersServiceRequest.getOffers(direction, currencyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OfferInfo> getOffersSortedByDate(String currencyCode, boolean all) {
|
public List<OfferInfo> getOffersSortedByDate(String currencyCode) {
|
||||||
return offersServiceRequest.getOffersSortedByDate(currencyCode, all);
|
return offersServiceRequest.getOffersSortedByDate(currencyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OfferInfo> getOffersSortedByDate(String direction, String currencyCode, boolean all) {
|
public List<OfferInfo> getOffersSortedByDate(String direction, String currencyCode) {
|
||||||
return offersServiceRequest.getOffersSortedByDate(direction, currencyCode, all);
|
return offersServiceRequest.getOffersSortedByDate(direction, currencyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OfferInfo> getBsqSwapOffersSortedByDate() {
|
public List<OfferInfo> getBsqSwapOffersSortedByDate() {
|
||||||
|
|
|
@ -20,7 +20,6 @@ package bisq.cli.opts;
|
||||||
|
|
||||||
import joptsimple.OptionSpec;
|
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_CURRENCY_CODE;
|
||||||
import static bisq.cli.opts.OptLabel.OPT_DIRECTION;
|
import static bisq.cli.opts.OptLabel.OPT_DIRECTION;
|
||||||
|
|
||||||
|
@ -32,11 +31,6 @@ public class GetOffersOptionParser extends AbstractMethodOptionParser implements
|
||||||
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency code (bsq|xmr|eur|usd|...)")
|
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency code (bsq|xmr|eur|usd|...)")
|
||||||
.withRequiredArg();
|
.withRequiredArg();
|
||||||
|
|
||||||
final OptionSpec<Boolean> allOpt = parser.accepts(OPT_ALL, "get all offers")
|
|
||||||
.withOptionalArg()
|
|
||||||
.ofType(boolean.class)
|
|
||||||
.defaultsTo(Boolean.FALSE);
|
|
||||||
|
|
||||||
public GetOffersOptionParser(String[] args) {
|
public GetOffersOptionParser(String[] args) {
|
||||||
super(args);
|
super(args);
|
||||||
}
|
}
|
||||||
|
@ -64,8 +58,4 @@ public class GetOffersOptionParser extends AbstractMethodOptionParser implements
|
||||||
public String getCurrencyCode() {
|
public String getCurrencyCode() {
|
||||||
return options.valueOf(currencyCodeOpt);
|
return options.valueOf(currencyCodeOpt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAll() {
|
|
||||||
return options.valueOf(allOpt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ public class OptLabel {
|
||||||
public final static String OPT_AMOUNT = "amount";
|
public final static String OPT_AMOUNT = "amount";
|
||||||
public final static String OPT_CATEGORY = "category";
|
public final static String OPT_CATEGORY = "category";
|
||||||
public final static String OPT_CURRENCY_CODE = "currency-code";
|
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_DAYS = "days";
|
||||||
public final static String OPT_DIRECTION = "direction";
|
public final static String OPT_DIRECTION = "direction";
|
||||||
public final static String OPT_DISPUTE_AGENT_TYPE = "dispute-agent-type";
|
public final static String OPT_DISPUTE_AGENT_TYPE = "dispute-agent-type";
|
||||||
|
|
|
@ -231,24 +231,23 @@ public class OffersServiceRequest {
|
||||||
return grpcStubs.offersService.getBsqSwapOffers(request).getBsqSwapOffersList();
|
return grpcStubs.offersService.getBsqSwapOffers(request).getBsqSwapOffersList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OfferInfo> getOffers(String direction, String currencyCode, boolean all) {
|
public List<OfferInfo> getOffers(String direction, String currencyCode) {
|
||||||
var request = GetOffersRequest.newBuilder()
|
var request = GetOffersRequest.newBuilder()
|
||||||
.setDirection(direction)
|
.setDirection(direction)
|
||||||
.setCurrencyCode(currencyCode)
|
.setCurrencyCode(currencyCode)
|
||||||
.setAll(all)
|
|
||||||
.build();
|
.build();
|
||||||
return grpcStubs.offersService.getOffers(request).getOffersList();
|
return grpcStubs.offersService.getOffers(request).getOffersList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OfferInfo> getOffersSortedByDate(String currencyCode, boolean all) {
|
public List<OfferInfo> getOffersSortedByDate(String currencyCode) {
|
||||||
ArrayList<OfferInfo> offers = new ArrayList<>();
|
ArrayList<OfferInfo> offers = new ArrayList<>();
|
||||||
offers.addAll(getOffers(BUY.name(), currencyCode, all));
|
offers.addAll(getOffers(BUY.name(), currencyCode));
|
||||||
offers.addAll(getOffers(SELL.name(), currencyCode, all));
|
offers.addAll(getOffers(SELL.name(), currencyCode));
|
||||||
return offers.isEmpty() ? offers : sortOffersByDate(offers);
|
return offers.isEmpty() ? offers : sortOffersByDate(offers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OfferInfo> getOffersSortedByDate(String direction, String currencyCode, boolean all) {
|
public List<OfferInfo> getOffersSortedByDate(String direction, String currencyCode) {
|
||||||
var offers = getOffers(direction, currencyCode, all);
|
var offers = getOffers(direction, currencyCode);
|
||||||
return offers.isEmpty() ? offers : sortOffersByDate(offers);
|
return offers.isEmpty() ? offers : sortOffersByDate(offers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,8 +292,8 @@ public class OffersServiceRequest {
|
||||||
return sortOffersByDate(offers);
|
return sortOffersByDate(offers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OfferInfo getMostRecentOffer(String direction, String currencyCode, boolean all) {
|
public OfferInfo getMostRecentOffer(String direction, String currencyCode) {
|
||||||
List<OfferInfo> offers = getOffersSortedByDate(direction, currencyCode, all);
|
List<OfferInfo> offers = getOffersSortedByDate(direction, currencyCode);
|
||||||
return offers.isEmpty() ? null : offers.get(offers.size() - 1);
|
return offers.isEmpty() ? null : offers.get(offers.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,12 +59,12 @@ public class GetOffersCliOutputDiffTest extends AbstractCliTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getAvailableBuyUsdOffers() {
|
private void getAvailableBuyUsdOffers() {
|
||||||
var offers = bobClient.getOffers(BUY.name(), "USD", false);
|
var offers = bobClient.getOffers(BUY.name(), "USD");
|
||||||
printAndCheckDiffs(offers, BUY.name(), "USD");
|
printAndCheckDiffs(offers, BUY.name(), "USD");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getAvailableSellUsdOffers() {
|
private void getAvailableSellUsdOffers() {
|
||||||
var offers = bobClient.getOffers(SELL.name(), "USD", false);
|
var offers = bobClient.getOffers(SELL.name(), "USD");
|
||||||
printAndCheckDiffs(offers, SELL.name(), "USD");
|
printAndCheckDiffs(offers, SELL.name(), "USD");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,12 +79,12 @@ public class GetOffersCliOutputDiffTest extends AbstractCliTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getAvailableBuyXmrOffers() {
|
private void getAvailableBuyXmrOffers() {
|
||||||
var offers = bobClient.getOffers(BUY.name(), "XMR", false);
|
var offers = bobClient.getOffers(BUY.name(), "XMR");
|
||||||
printAndCheckDiffs(offers, BUY.name(), "XMR");
|
printAndCheckDiffs(offers, BUY.name(), "XMR");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getAvailableSellXmrOffers() {
|
private void getAvailableSellXmrOffers() {
|
||||||
var offers = bobClient.getOffers(SELL.name(), "XMR", false);
|
var offers = bobClient.getOffers(SELL.name(), "XMR");
|
||||||
printAndCheckDiffs(offers, SELL.name(), "XMR");
|
printAndCheckDiffs(offers, SELL.name(), "XMR");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,12 +99,12 @@ public class GetOffersCliOutputDiffTest extends AbstractCliTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getAvailableBuyBsqOffers() {
|
private void getAvailableBuyBsqOffers() {
|
||||||
var offers = bobClient.getOffers(BUY.name(), "BSQ", false);
|
var offers = bobClient.getOffers(BUY.name(), "BSQ");
|
||||||
printAndCheckDiffs(offers, BUY.name(), "BSQ");
|
printAndCheckDiffs(offers, BUY.name(), "BSQ");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getAvailableSellBsqOffers() {
|
private void getAvailableSellBsqOffers() {
|
||||||
var offers = bobClient.getOffers(SELL.name(), "BSQ", false);
|
var offers = bobClient.getOffers(SELL.name(), "BSQ");
|
||||||
printAndCheckDiffs(offers, SELL.name(), "BSQ");
|
printAndCheckDiffs(offers, SELL.name(), "BSQ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,8 +166,8 @@ public class CoreApi {
|
||||||
return coreOffersService.getBsqSwapOffers(direction);
|
return coreOffersService.getBsqSwapOffers(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Offer> getOffers(String direction, String currencyCode, boolean all) {
|
public List<Offer> getOffers(String direction, String currencyCode) {
|
||||||
return coreOffersService.getOffers(direction, currencyCode, all);
|
return coreOffersService.getOffers(direction, currencyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OpenOffer> getMyOffers(String direction, String currencyCode) {
|
public List<OpenOffer> getMyOffers(String direction, String currencyCode) {
|
||||||
|
|
|
@ -206,14 +206,12 @@ class CoreOffersService {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Offer> getOffers(String direction, String currencyCode, boolean all) {
|
List<Offer> getOffers(String direction, String currencyCode) {
|
||||||
var upperCaseCurrencyCode = currencyCode.toUpperCase();
|
var upperCaseCurrencyCode = currencyCode.toUpperCase();
|
||||||
var isFiat = isFiatCurrency(upperCaseCurrencyCode);
|
var isFiat = isFiatCurrency(upperCaseCurrencyCode);
|
||||||
if (isFiat) {
|
if (isFiat) {
|
||||||
return offerBookService.getOffers().stream()
|
return offerBookService.getOffers().stream()
|
||||||
.filter(o -> !o.isMyOffer(keyRing))
|
|
||||||
.filter(o -> offerMatchesDirectionAndCurrency(o, direction, upperCaseCurrencyCode))
|
.filter(o -> offerMatchesDirectionAndCurrency(o, direction, upperCaseCurrencyCode))
|
||||||
.filter(o -> all || offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid())
|
|
||||||
.sorted(priceComparator(direction, true))
|
.sorted(priceComparator(direction, true))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} else {
|
} else {
|
||||||
|
@ -223,10 +221,8 @@ class CoreOffersService {
|
||||||
// then filter on the currencyCode param (the altcoin code).
|
// then filter on the currencyCode param (the altcoin code).
|
||||||
if (apiSupportsCryptoCurrency(upperCaseCurrencyCode))
|
if (apiSupportsCryptoCurrency(upperCaseCurrencyCode))
|
||||||
return offerBookService.getOffers().stream()
|
return offerBookService.getOffers().stream()
|
||||||
.filter(o -> !o.isMyOffer(keyRing))
|
|
||||||
.filter(o -> offerMatchesDirectionAndCurrency(o, direction, "BTC"))
|
.filter(o -> offerMatchesDirectionAndCurrency(o, direction, "BTC"))
|
||||||
.filter(o -> o.getBaseCurrencyCode().equalsIgnoreCase(upperCaseCurrencyCode))
|
.filter(o -> o.getBaseCurrencyCode().equalsIgnoreCase(upperCaseCurrencyCode))
|
||||||
.filter(o -> all || offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid())
|
|
||||||
.sorted(priceComparator(direction, false))
|
.sorted(priceComparator(direction, false))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
else
|
else
|
||||||
|
|
|
@ -9,7 +9,6 @@ SYNOPSIS
|
||||||
getoffers
|
getoffers
|
||||||
--direction=<buy|sell>
|
--direction=<buy|sell>
|
||||||
--currency-code=<eur|usd>
|
--currency-code=<eur|usd>
|
||||||
--all=<true|false>
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
|
@ -25,9 +24,6 @@ OPTIONS
|
||||||
--currency-code
|
--currency-code
|
||||||
The three letter code for the fiat used to buy or sell BTC, e.g., EUR, USD, BRL, ...
|
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
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
You have one Brazilian Real payment account with a face-to-face payment method type.
|
You have one Brazilian Real payment account with a face-to-face payment method type.
|
||||||
|
|
|
@ -195,7 +195,7 @@ class GrpcOffersService extends OffersImplBase {
|
||||||
public void getOffers(GetOffersRequest req,
|
public void getOffers(GetOffersRequest req,
|
||||||
StreamObserver<GetOffersReply> responseObserver) {
|
StreamObserver<GetOffersReply> responseObserver) {
|
||||||
try {
|
try {
|
||||||
List<OfferInfo> result = coreApi.getOffers(req.getDirection(), req.getCurrencyCode(), req.getAll())
|
List<OfferInfo> result = coreApi.getOffers(req.getDirection(), req.getCurrencyCode())
|
||||||
.stream()
|
.stream()
|
||||||
.map(OfferInfo::toOfferInfo)
|
.map(OfferInfo::toOfferInfo)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
|
@ -148,7 +148,7 @@ message GetMyOfferReply {
|
||||||
message GetOffersRequest {
|
message GetOffersRequest {
|
||||||
string direction = 1; // The offer's BUY (BTC) or SELL (BTC) direction.
|
string direction = 1; // The offer's BUY (BTC) or SELL (BTC) direction.
|
||||||
string currency_code = 2; // The offer's fiat or altcoin currency code.
|
string currency_code = 2; // The offer's fiat or altcoin currency code.
|
||||||
bool all = 3; // Return all or only these matching my account
|
reserved 3; // This was the "all" field before.
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetOffersReply {
|
message GetOffersReply {
|
||||||
|
|
Loading…
Add table
Reference in a new issue