Search in sources :

Example 6 with PriceFeedService

use of bisq.core.provider.price.PriceFeedService in project bisq-desktop by bisq-network.

the class OfferBookChartViewModelTest method testMaxCharactersForSellVolume.

@Test
public void testMaxCharactersForSellVolume() {
    OfferBook offerBook = mock(OfferBook.class);
    PriceFeedService service = mock(PriceFeedService.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    offerBookListItems.addAll(make(OfferBookListItemMaker.btcSellItem));
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, service, null, new BSFormatter());
    model.activate();
    // 0.01
    assertEquals(4, model.maxPlacesForSellVolume.intValue());
    offerBookListItems.addAll(make(btcSellItem.but(with(OfferBookListItemMaker.amount, 100000000L))));
    // 10.00
    assertEquals(5, model.maxPlacesForSellVolume.intValue());
    offerBookListItems.addAll(make(btcSellItem.but(with(OfferBookListItemMaker.amount, 22128600000L))));
    // 2212.86
    assertEquals(7, model.maxPlacesForSellVolume.intValue());
}
Also used : OfferBook(bisq.desktop.main.offer.offerbook.OfferBook) OfferBookListItem(bisq.desktop.main.offer.offerbook.OfferBookListItem) PriceFeedService(bisq.core.provider.price.PriceFeedService) BSFormatter(bisq.desktop.util.BSFormatter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with PriceFeedService

use of bisq.core.provider.price.PriceFeedService in project bisq-desktop by bisq-network.

the class OfferBookChartViewModelTest method testMaxCharactersForSellPrice.

@Test
public void testMaxCharactersForSellPrice() {
    OfferBook offerBook = mock(OfferBook.class);
    PriceFeedService service = mock(PriceFeedService.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    offerBookListItems.addAll(make(OfferBookListItemMaker.btcSellItem));
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, service, null, new BSFormatter());
    model.activate();
    assertEquals(7, model.maxPlacesForSellPrice.intValue());
    offerBookListItems.addAll(make(btcSellItem.but(with(OfferBookListItemMaker.price, 94016475L))));
    assertEquals(9, model.maxPlacesForSellPrice.intValue());
    offerBookListItems.addAll(make(btcSellItem.but(with(OfferBookListItemMaker.price, 101016475L))));
    assertEquals(10, model.maxPlacesForSellPrice.intValue());
}
Also used : OfferBook(bisq.desktop.main.offer.offerbook.OfferBook) OfferBookListItem(bisq.desktop.main.offer.offerbook.OfferBookListItem) PriceFeedService(bisq.core.provider.price.PriceFeedService) BSFormatter(bisq.desktop.util.BSFormatter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with PriceFeedService

use of bisq.core.provider.price.PriceFeedService in project bisq-desktop by bisq-network.

the class CreateOfferViewModelTest method setUp.

@Before
public void setUp() {
    final CryptoCurrency btc = new CryptoCurrency("BTC", "bitcoin");
    GlobalSettings.setDefaultTradeCurrency(btc);
    Res.setBaseCurrencyCode(btc.getCode());
    Res.setBaseCurrencyName(btc.getName());
    final BSFormatter bsFormatter = new BSFormatter();
    final BtcValidator btcValidator = new BtcValidator(bsFormatter);
    final AltcoinValidator altcoinValidator = new AltcoinValidator();
    final FiatPriceValidator fiatPriceValidator = new FiatPriceValidator();
    FeeService feeService = mock(FeeService.class);
    AddressEntry addressEntry = mock(AddressEntry.class);
    BtcWalletService btcWalletService = mock(BtcWalletService.class);
    PriceFeedService priceFeedService = mock(PriceFeedService.class);
    User user = mock(User.class);
    PaymentAccount paymentAccount = mock(PaymentAccount.class);
    BsqWalletService bsqWalletService = mock(BsqWalletService.class);
    SecurityDepositValidator securityDepositValidator = mock(SecurityDepositValidator.class);
    when(btcWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry);
    when(btcWalletService.getBalanceForAddress(any())).thenReturn(Coin.valueOf(1000L));
    when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
    when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true));
    when(feeService.getTxFee(anyInt())).thenReturn(Coin.valueOf(1000L));
    when(user.findFirstPaymentAccountWithCurrency(any())).thenReturn(paymentAccount);
    when(user.getPaymentAccountsAsObservable()).thenReturn(FXCollections.observableSet());
    when(securityDepositValidator.validate(any())).thenReturn(new InputValidator.ValidationResult(false));
    CreateOfferDataModel dataModel = new CreateOfferDataModel(null, btcWalletService, bsqWalletService, empty, user, null, null, priceFeedService, null, null, null, feeService, bsFormatter);
    dataModel.initWithData(OfferPayload.Direction.BUY, new CryptoCurrency("BTC", "bitcoin"));
    dataModel.activate();
    model = new CreateOfferViewModel(dataModel, null, fiatPriceValidator, altcoinValidator, btcValidator, null, securityDepositValidator, null, null, priceFeedService, null, null, bsFormatter, null);
    model.activate();
}
Also used : BtcValidator(bisq.desktop.util.validation.BtcValidator) FiatPriceValidator(bisq.desktop.util.validation.FiatPriceValidator) User(bisq.core.user.User) AddressEntry(bisq.core.btc.AddressEntry) PaymentAccount(bisq.core.payment.PaymentAccount) FeeService(bisq.core.provider.fee.FeeService) BSFormatter(bisq.desktop.util.BSFormatter) AltcoinValidator(bisq.desktop.util.validation.AltcoinValidator) CryptoCurrency(bisq.core.locale.CryptoCurrency) SecurityDepositValidator(bisq.desktop.util.validation.SecurityDepositValidator) MarketPrice(bisq.core.provider.price.MarketPrice) InputValidator(bisq.core.util.validation.InputValidator) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) PriceFeedService(bisq.core.provider.price.PriceFeedService) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Before(org.junit.Before)

Example 9 with PriceFeedService

use of bisq.core.provider.price.PriceFeedService in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method testGetPrice.

@Test
public void testGetPrice() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    PriceFeedService priceFeedService = mock(PriceFeedService.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    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, new BSFormatter());
    final OfferBookListItem item = make(btcItem.but(with(useMarketBasedPrice, true), with(marketPriceMargin, -0.12)));
    final OfferBookListItem lowItem = make(btcItem.but(with(useMarketBasedPrice, true), with(marketPriceMargin, 0.01)));
    final OfferBookListItem fixedItem = make(btcItem);
    item.getOffer().setPriceFeedService(priceFeedService);
    lowItem.getOffer().setPriceFeedService(priceFeedService);
    offerBookListItems.addAll(lowItem, fixedItem);
    model.activate();
    assertEquals("12557.2046 (1.00%)", model.getPrice(lowItem));
    assertEquals("   10.0000        ", model.getPrice(fixedItem));
    offerBookListItems.addAll(item);
    assertEquals("14206.1304 (-12.00%)", model.getPrice(item));
    assertEquals("12557.2046   (1.00%)", model.getPrice(lowItem));
}
Also used : OpenOfferManager(bisq.core.offer.OpenOfferManager) MarketPrice(bisq.core.provider.price.MarketPrice) PriceFeedService(bisq.core.provider.price.PriceFeedService) BSFormatter(bisq.desktop.util.BSFormatter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

PriceFeedService (bisq.core.provider.price.PriceFeedService)9 BSFormatter (bisq.desktop.util.BSFormatter)9 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 OfferBook (bisq.desktop.main.offer.offerbook.OfferBook)6 OfferBookListItem (bisq.desktop.main.offer.offerbook.OfferBookListItem)6 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)4 OpenOfferManager (bisq.core.offer.OpenOfferManager)2 MarketPrice (bisq.core.provider.price.MarketPrice)2 AddressEntry (bisq.core.btc.AddressEntry)1 BsqWalletService (bisq.core.btc.wallet.BsqWalletService)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 CryptoCurrency (bisq.core.locale.CryptoCurrency)1 PaymentAccount (bisq.core.payment.PaymentAccount)1 FeeService (bisq.core.provider.fee.FeeService)1 User (bisq.core.user.User)1 InputValidator (bisq.core.util.validation.InputValidator)1 AltcoinValidator (bisq.desktop.util.validation.AltcoinValidator)1 BtcValidator (bisq.desktop.util.validation.BtcValidator)1 FiatPriceValidator (bisq.desktop.util.validation.FiatPriceValidator)1