use of bisq.core.provider.price.PriceFeedService in project bisq-desktop by bisq-network.
the class OfferBookViewModelTest method testMaxCharactersForPriceDistance.
@Test
public void testMaxCharactersForPriceDistance() {
OfferBook offerBook = mock(OfferBook.class);
OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
PriceFeedService priceFeedService = mock(PriceFeedService.class);
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
final Maker<OfferBookListItem> item = btcItem.but(with(useMarketBasedPrice, true));
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
when(priceFeedService.getMarketPrice(anyString())).thenReturn(null);
when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
final OfferBookListItem item1 = make(item);
item1.getOffer().setPriceFeedService(priceFeedService);
final OfferBookListItem item2 = make(item.but(with(marketPriceMargin, 0.0197)));
item2.getOffer().setPriceFeedService(priceFeedService);
final OfferBookListItem item3 = make(item.but(with(marketPriceMargin, 0.1)));
item3.getOffer().setPriceFeedService(priceFeedService);
final OfferBookListItem item4 = make(item.but(with(marketPriceMargin, -0.1)));
item4.getOffer().setPriceFeedService(priceFeedService);
offerBookListItems.addAll(item1, item2);
final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, priceFeedService, null, null, null, null, null, new BSFormatter());
model.activate();
// " (1.97%)"
assertEquals(8, model.maxPlacesForMarketPriceMargin.intValue());
offerBookListItems.addAll(item3);
// " (10.00%)"
assertEquals(9, model.maxPlacesForMarketPriceMargin.intValue());
offerBookListItems.addAll(item4);
// " (-10.00%)"
assertEquals(10, model.maxPlacesForMarketPriceMargin.intValue());
}
use of bisq.core.provider.price.PriceFeedService in project bisq-desktop by bisq-network.
the class OfferBookChartViewModelTest method testMaxCharactersForBuyPrice.
@Test
public void testMaxCharactersForBuyPrice() {
OfferBook offerBook = mock(OfferBook.class);
PriceFeedService service = mock(PriceFeedService.class);
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
offerBookListItems.addAll(make(OfferBookListItemMaker.btcItem));
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, service, null, new BSFormatter());
model.activate();
assertEquals(7, model.maxPlacesForBuyPrice.intValue());
offerBookListItems.addAll(make(btcItem.but(with(OfferBookListItemMaker.price, 94016475L))));
assertEquals(9, model.maxPlacesForBuyPrice.intValue());
offerBookListItems.addAll(make(btcItem.but(with(OfferBookListItemMaker.price, 101016475L))));
assertEquals(10, model.maxPlacesForBuyPrice.intValue());
}
use of bisq.core.provider.price.PriceFeedService in project bisq-desktop by bisq-network.
the class OfferBookChartViewModelTest method testMaxCharactersForBuyVolume.
@Test
public void testMaxCharactersForBuyVolume() {
OfferBook offerBook = mock(OfferBook.class);
PriceFeedService service = mock(PriceFeedService.class);
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
offerBookListItems.addAll(make(OfferBookListItemMaker.btcItem));
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, service, null, new BSFormatter());
model.activate();
// 0.01
assertEquals(4, model.maxPlacesForBuyVolume.intValue());
offerBookListItems.addAll(make(btcItem.but(with(OfferBookListItemMaker.amount, 100000000L))));
// 10.00
assertEquals(5, model.maxPlacesForBuyVolume.intValue());
offerBookListItems.addAll(make(btcItem.but(with(OfferBookListItemMaker.amount, 22128600000L))));
// 2212.86
assertEquals(7, model.maxPlacesForBuyVolume.intValue());
}
use of bisq.core.provider.price.PriceFeedService in project bisq-desktop by bisq-network.
the class OfferBookChartViewModelTest method testMaxCharactersForBuyPriceWithOfflinePriceFeedService.
@Test
public void testMaxCharactersForBuyPriceWithOfflinePriceFeedService() {
OfferBook offerBook = mock(OfferBook.class);
PriceFeedService priceFeedService = mock(PriceFeedService.class);
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
final OfferBookListItem item = make(OfferBookListItemMaker.btcItem.but(with(OfferBookListItemMaker.useMarketBasedPrice, true)));
item.getOffer().setPriceFeedService(priceFeedService);
offerBookListItems.addAll(item);
when(priceFeedService.getMarketPrice(anyString())).thenReturn(null);
when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, priceFeedService, null, new BSFormatter());
model.activate();
assertEquals(0, model.maxPlacesForBuyPrice.intValue());
}
use of bisq.core.provider.price.PriceFeedService in project bisq-api by mrosseel.
the class BisqProxy method getPriceFeed.
public PriceFeed getPriceFeed(String[] codes) {
final PriceFeedService priceFeedService = injector.getInstance(PriceFeedService.class);
final List<FiatCurrency> fiatCurrencies = preferences.getFiatCurrencies();
final List<CryptoCurrency> cryptoCurrencies = preferences.getCryptoCurrencies();
final Stream<String> codesStream;
if (null == codes || 0 == codes.length)
codesStream = Stream.concat(fiatCurrencies.stream(), cryptoCurrencies.stream()).map(TradeCurrency::getCode);
else
codesStream = Arrays.asList(codes).stream();
final List<MarketPrice> marketPrices = codesStream.map(priceFeedService::getMarketPrice).filter(i -> null != i).collect(toList());
final PriceFeed priceFeed = new PriceFeed();
for (MarketPrice price : marketPrices) priceFeed.prices.put(price.getCurrencyCode(), price.getPrice());
return priceFeed;
}
Aggregations