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

Deactivate open offer if trigger price is reached #5001

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,6 +17,8 @@

package bisq.desktop.main.offer.offerbook;

import bisq.desktop.main.PriceUtil;

import bisq.core.locale.Country;
import bisq.core.locale.CryptoCurrency;
import bisq.core.locale.FiatCurrency;
Expand All @@ -41,6 +43,7 @@
import bisq.core.payment.payload.SpecificBanksAccountPayload;
import bisq.core.provider.price.MarketPrice;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.trade.statistics.TradeStatisticsManager;
import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.coin.ImmutableCoinFormatter;
Expand Down Expand Up @@ -90,6 +93,13 @@ public void setUp() {
Res.setBaseCurrencyName(usd.getName());
}

private PriceUtil getPriceUtil() {
PriceFeedService priceFeedService = mock(PriceFeedService.class);
TradeStatisticsManager tradeStatisticsManager = mock(TradeStatisticsManager.class);
when(tradeStatisticsManager.getObservableTradeStatisticsSet()).thenReturn(FXCollections.observableSet());
return new PriceUtil(priceFeedService, tradeStatisticsManager, empty);
}

@Ignore("PaymentAccountPayload needs to be set (has been changed with PB changes)")
public void testIsAnyPaymentAccountValidForOffer() {
Collection<PaymentAccount> paymentAccounts;
Expand Down Expand Up @@ -229,7 +239,7 @@ public void testMaxCharactersForAmountWithNoOffes() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());
assertEquals(0, model.maxPlacesForAmount.intValue());
}

Expand All @@ -243,7 +253,7 @@ public void testMaxCharactersForAmount() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());
model.activate();

assertEquals(6, model.maxPlacesForAmount.intValue());
Expand All @@ -261,7 +271,7 @@ public void testMaxCharactersForAmountRange() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());
model.activate();

assertEquals(15, model.maxPlacesForAmount.intValue());
Expand All @@ -280,7 +290,7 @@ public void testMaxCharactersForVolumeWithNoOffes() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());
assertEquals(0, model.maxPlacesForVolume.intValue());
}

Expand All @@ -294,7 +304,7 @@ public void testMaxCharactersForVolume() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());
model.activate();

assertEquals(5, model.maxPlacesForVolume.intValue());
Expand All @@ -312,7 +322,7 @@ public void testMaxCharactersForVolumeRange() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());
model.activate();

assertEquals(9, model.maxPlacesForVolume.intValue());
Expand All @@ -331,7 +341,7 @@ public void testMaxCharactersForPriceWithNoOffers() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());
assertEquals(0, model.maxPlacesForPrice.intValue());
}

Expand All @@ -345,7 +355,7 @@ public void testMaxCharactersForPrice() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());
model.activate();

assertEquals(7, model.maxPlacesForPrice.intValue());
Expand All @@ -363,7 +373,7 @@ public void testMaxCharactersForPriceDistanceWithNoOffers() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());
assertEquals(0, model.maxPlacesForMarketPriceMargin.intValue());
}

Expand Down Expand Up @@ -391,7 +401,7 @@ public void testMaxCharactersForPriceDistance() {
offerBookListItems.addAll(item1, item2);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, priceFeedService,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());
model.activate();

assertEquals(8, model.maxPlacesForMarketPriceMargin.intValue()); //" (1.97%)"
Expand All @@ -412,7 +422,7 @@ public void testGetPrice() {
when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true));

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, null, coinFormatter, new BsqFormatter());
null, null, null, null, getPriceUtil(), coinFormatter, new BsqFormatter());

final OfferBookListItem item = make(btcBuyItem.but(
with(useMarketBasedPrice, true),
Expand Down