Search in sources :

Example 1 with MarketPrice

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

the class BsqDashboardView method updatePrice.

private void updatePrice() {
    final Coin issuedAmount = bsqBlockChain.getIssuedAmountAtGenesis();
    final MarketPrice bsqMarketPrice = priceFeedService.getMarketPrice("BSQ");
    if (bsqMarketPrice != null) {
        long bsqPrice = MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(bsqMarketPrice.getPrice(), Altcoin.SMALLEST_UNIT_EXPONENT));
        priceTextField.setText(bsqFormatter.formatPrice(Price.valueOf("BSQ", bsqPrice)) + " BSQ/BTC");
        marketCapTextField.setText(bsqFormatter.formatMarketCap(bsqMarketPrice, priceFeedService.getMarketPrice("USD"), issuedAmount));
    }
}
Also used : Coin(org.bitcoinj.core.Coin) MarketPrice(bisq.core.provider.price.MarketPrice)

Example 2 with MarketPrice

use of bisq.core.provider.price.MarketPrice 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;
}
Also used : Arrays(java.util.Arrays) OpenOffer(bisq.core.offer.OpenOffer) User(bisq.core.user.User) PriceFeed(network.bisq.api.model.PriceFeed) Statistic(bisq.network.p2p.network.Statistic) ZoneOffset(java.time.ZoneOffset) KeyParameter(org.spongycastle.crypto.params.KeyParameter) ClosedTradableDetails(network.bisq.api.model.ClosedTradableDetails) CurrencyList(network.bisq.api.model.CurrencyList) WalletAddress(network.bisq.api.model.WalletAddress) AddressEntryException(bisq.core.btc.AddressEntryException) Offer(bisq.core.offer.Offer) ClosedTradableManager(bisq.core.trade.closed.ClosedTradableManager) SellerAsMakerProtocol(bisq.core.trade.protocol.SellerAsMakerProtocol) WalletTransactionList(network.bisq.api.model.WalletTransactionList) InsufficientFundsException(bisq.core.btc.InsufficientFundsException) Set(java.util.Set) TokenRegistry(network.bisq.api.service.TokenRegistry) BlockChainExplorer(bisq.core.user.BlockChainExplorer) TradeProtocol(bisq.core.trade.protocol.TradeProtocol) ZoneId(java.time.ZoneId) ECKey(org.bitcoinj.core.ECKey) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) AddressEntry(bisq.core.btc.AddressEntry) WalletsSetup(bisq.core.btc.wallet.WalletsSetup) CryptoCurrency(bisq.core.locale.CryptoCurrency) Currency(network.bisq.api.model.Currency) TradeManager(bisq.core.trade.TradeManager) NodeAddress(bisq.network.p2p.NodeAddress) SellerAsTakerProtocol(bisq.core.trade.protocol.SellerAsTakerProtocol) CountryUtil(bisq.core.locale.CountryUtil) BuyerAsTakerProtocol(bisq.core.trade.protocol.BuyerAsTakerProtocol) TransactionOutput(org.bitcoinj.core.TransactionOutput) FeeService(bisq.core.provider.fee.FeeService) ObservableList(javafx.collections.ObservableList) PaymentAccountHelper(network.bisq.api.model.payment.PaymentAccountHelper) Restrictions(bisq.core.btc.Restrictions) Arbitrator(bisq.core.arbitration.Arbitrator) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) Wallet(org.bitcoinj.wallet.Wallet) Peer(org.bitcoinj.core.Peer) ArrayList(java.util.ArrayList) ClosedTradableConverter(network.bisq.api.model.ClosedTradableConverter) OfferPayload(bisq.core.offer.OfferPayload) Country(bisq.core.locale.Country) BitcoinNetworkStatus(network.bisq.api.model.BitcoinNetworkStatus) WalletDetails(network.bisq.api.model.WalletDetails) Nullable(javax.annotation.Nullable) IOException(java.io.IOException) OfferBookService(bisq.core.offer.OfferBookService) Names(com.google.inject.name.Names) BisqEnvironment(bisq.core.app.BisqEnvironment) SeedWords(network.bisq.api.model.SeedWords) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) OpenOfferManager(bisq.core.offer.OpenOfferManager) InputValidator(bisq.core.util.validation.InputValidator) PriceFeedService(bisq.core.provider.price.PriceFeedService) PaymentAccountList(network.bisq.api.model.PaymentAccountList) KeyRing(bisq.common.crypto.KeyRing) PreferencesAvailableValues(network.bisq.api.model.PreferencesAvailableValues) Transaction(org.bitcoinj.core.Transaction) Preferences(network.bisq.api.model.Preferences) Date(java.util.Date) Coin(org.bitcoinj.core.Coin) Key(com.google.inject.Key) AltCoinAddressValidator(bisq.core.payment.validation.AltCoinAddressValidator) VersionDetails(network.bisq.api.model.VersionDetails) Res(bisq.core.locale.Res) ErrorMessageHandler(bisq.common.handlers.ErrorMessageHandler) KeyCrypterScrypt(org.bitcoinj.crypto.KeyCrypterScrypt) PaymentAccountUtil.isPaymentAccountValidForOffer(bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer) OfferUtil(bisq.core.offer.OfferUtil) P2PService(bisq.network.p2p.P2PService) Predicate(java.util.function.Predicate) ArbitratorManager(bisq.core.arbitration.ArbitratorManager) Collection(java.util.Collection) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) AccountAgeWitnessService(bisq.core.payment.AccountAgeWitnessService) FileUtil(bisq.common.storage.FileUtil) List(java.util.List) PaymentAccount(bisq.core.payment.PaymentAccount) DeterministicSeed(org.bitcoinj.wallet.DeterministicSeed) DevEnv(bisq.common.app.DevEnv) MarketList(network.bisq.api.model.MarketList) AppOptionKeys(bisq.core.app.AppOptionKeys) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Address(org.bitcoinj.core.Address) NotNull(org.jetbrains.annotations.NotNull) MarketPrice(bisq.core.provider.price.MarketPrice) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) TradeCurrency(bisq.core.locale.TradeCurrency) SellerAsMakerTrade(bisq.core.trade.SellerAsMakerTrade) Getter(lombok.Getter) WalletService(bisq.core.btc.wallet.WalletService) CompletableFuture(java.util.concurrent.CompletableFuture) FiatCurrency(bisq.core.locale.FiatCurrency) WalletsManager(bisq.core.btc.wallet.WalletsManager) Tuple2(bisq.common.util.Tuple2) BuyerAsMakerProtocol(bisq.core.trade.protocol.BuyerAsMakerProtocol) P2PNetworkStatus(network.bisq.api.model.P2PNetworkStatus) Market(network.bisq.api.model.Market) CurrencyUtil(bisq.core.locale.CurrencyUtil) BitcoinNodes(bisq.core.btc.BitcoinNodes) Version(bisq.common.app.Version) CryptoCurrencyAccount(bisq.core.payment.CryptoCurrencyAccount) P2PNetworkConnection(network.bisq.api.model.P2PNetworkConnection) BuyerAsMakerTrade(bisq.core.trade.BuyerAsMakerTrade) Trade(bisq.core.trade.Trade) WalletAddressList(network.bisq.api.model.WalletAddressList) ResultHandler(bisq.common.handlers.ResultHandler) FailedTradesManager(bisq.core.trade.failed.FailedTradesManager) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FileInputStream(java.io.FileInputStream) WalletTransaction(network.bisq.api.model.WalletTransaction) Injector(com.google.inject.Injector) Collectors.toList(java.util.stream.Collectors.toList) AuthResult(network.bisq.api.model.AuthResult) ValidationException(javax.validation.ValidationException) Storage(bisq.common.storage.Storage) Comparator(java.util.Comparator) Collections(java.util.Collections) CoinUtil(bisq.core.util.CoinUtil) InputStream(java.io.InputStream) TradeCurrency(bisq.core.locale.TradeCurrency) PriceFeed(network.bisq.api.model.PriceFeed) CryptoCurrency(bisq.core.locale.CryptoCurrency) MarketPrice(bisq.core.provider.price.MarketPrice) PriceFeedService(bisq.core.provider.price.PriceFeedService) FiatCurrency(bisq.core.locale.FiatCurrency)

Example 3 with MarketPrice

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

the class SpreadViewModel method update.

private void update(ObservableList<OfferBookListItem> offerBookListItems) {
    Map<String, List<Offer>> offersByCurrencyMap = new HashMap<>();
    for (OfferBookListItem offerBookListItem : offerBookListItems) {
        Offer offer = offerBookListItem.getOffer();
        String currencyCode = offer.getCurrencyCode();
        if (!offersByCurrencyMap.containsKey(currencyCode))
            offersByCurrencyMap.put(currencyCode, new ArrayList<>());
        offersByCurrencyMap.get(currencyCode).add(offer);
    }
    spreadItems.clear();
    Coin totalAmount = null;
    for (String currencyCode : offersByCurrencyMap.keySet()) {
        List<Offer> offers = offersByCurrencyMap.get(currencyCode);
        final boolean isFiatCurrency = CurrencyUtil.isFiatCurrency(currencyCode);
        List<Offer> buyOffers = offers.stream().filter(e -> e.getDirection().equals(OfferPayload.Direction.BUY)).sorted((o1, o2) -> {
            long a = o1.getPrice() != null ? o1.getPrice().getValue() : 0;
            long b = o2.getPrice() != null ? o2.getPrice().getValue() : 0;
            if (a != b) {
                if (isFiatCurrency) {
                    return a < b ? 1 : -1;
                } else {
                    return a < b ? -1 : 1;
                }
            }
            return 0;
        }).collect(Collectors.toList());
        List<Offer> sellOffers = offers.stream().filter(e -> e.getDirection().equals(OfferPayload.Direction.SELL)).sorted((o1, o2) -> {
            long a = o1.getPrice() != null ? o1.getPrice().getValue() : 0;
            long b = o2.getPrice() != null ? o2.getPrice().getValue() : 0;
            if (a != b) {
                if (isFiatCurrency) {
                    return a > b ? 1 : -1;
                } else {
                    return a > b ? -1 : 1;
                }
            }
            return 0;
        }).collect(Collectors.toList());
        Price spread = null;
        String percentage = "";
        Price bestSellOfferPrice = sellOffers.isEmpty() ? null : sellOffers.get(0).getPrice();
        Price bestBuyOfferPrice = buyOffers.isEmpty() ? null : buyOffers.get(0).getPrice();
        if (bestBuyOfferPrice != null && bestSellOfferPrice != null) {
            MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
            // happens again
            try {
                if (isFiatCurrency)
                    spread = bestSellOfferPrice.subtract(bestBuyOfferPrice);
                else
                    spread = bestBuyOfferPrice.subtract(bestSellOfferPrice);
                if (spread != null && marketPrice != null && marketPrice.isPriceAvailable()) {
                    double marketPriceAsDouble = marketPrice.getPrice();
                    final double precision = isFiatCurrency ? Math.pow(10, Fiat.SMALLEST_UNIT_EXPONENT) : Math.pow(10, Altcoin.SMALLEST_UNIT_EXPONENT);
                    BigDecimal marketPriceAsBigDecimal = BigDecimal.valueOf(marketPriceAsDouble).multiply(BigDecimal.valueOf(precision));
                    // We multiply with 10000 because we use precision of 2 at % (100.00%)
                    double result = BigDecimal.valueOf(spread.getValue()).multiply(BigDecimal.valueOf(10000)).divide(marketPriceAsBigDecimal, RoundingMode.HALF_UP).doubleValue() / 10000;
                    percentage = formatter.formatPercentagePrice(result);
                }
            } catch (Throwable t) {
                try {
                    // Don't translate msg. It is just for rare error cases and can be removed probably later if
                    // that error never gets reported again.
                    String msg = "An error occurred at the spread calculation.\n" + "Error msg: " + t.toString() + "\n" + "Details of offer data: \n" + "bestSellOfferPrice: " + bestSellOfferPrice.getValue() + "\n" + "bestBuyOfferPrice: " + bestBuyOfferPrice.getValue() + "\n" + "sellOffer getCurrencyCode: " + sellOffers.get(0).getCurrencyCode() + "\n" + "buyOffer getCurrencyCode: " + buyOffers.get(0).getCurrencyCode() + "\n\n" + "Please copy and paste this data and send it to the developers so they can investigate the issue.";
                    new Popup<>().error(msg).show();
                    log.error(t.toString());
                    t.printStackTrace();
                } catch (Throwable t2) {
                    log.error(t2.toString());
                    t2.printStackTrace();
                }
            }
        }
        totalAmount = Coin.valueOf(offers.stream().mapToLong(offer -> offer.getAmount().getValue()).sum());
        spreadItems.add(new SpreadItem(currencyCode, buyOffers.size(), sellOffers.size(), offers.size(), spread, percentage, totalAmount));
    }
    maxPlacesForAmount.set(formatAmount(totalAmount, false).length());
}
Also used : Altcoin(bisq.core.monetary.Altcoin) GUIUtil(bisq.desktop.util.GUIUtil) Coin(org.bitcoinj.core.Coin) Inject(com.google.inject.Inject) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) IntegerProperty(javafx.beans.property.IntegerProperty) BSFormatter(bisq.desktop.util.BSFormatter) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) OfferPayload(bisq.core.offer.OfferPayload) ListChangeListener(javafx.collections.ListChangeListener) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Map(java.util.Map) CurrencyUtil(bisq.core.locale.CurrencyUtil) RoundingMode(java.math.RoundingMode) Popup(bisq.desktop.main.overlays.popups.Popup) Offer(bisq.core.offer.Offer) OfferBook(bisq.desktop.main.offer.offerbook.OfferBook) Fiat(org.bitcoinj.utils.Fiat) OfferBookListItem(bisq.desktop.main.offer.offerbook.OfferBookListItem) Collectors(java.util.stream.Collectors) ActivatableViewModel(bisq.desktop.common.model.ActivatableViewModel) List(java.util.List) PriceFeedService(bisq.core.provider.price.PriceFeedService) Price(bisq.core.monetary.Price) ObservableList(javafx.collections.ObservableList) MarketPrice(bisq.core.provider.price.MarketPrice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Coin(org.bitcoinj.core.Coin) OfferBookListItem(bisq.desktop.main.offer.offerbook.OfferBookListItem) MarketPrice(bisq.core.provider.price.MarketPrice) Offer(bisq.core.offer.Offer) Price(bisq.core.monetary.Price) MarketPrice(bisq.core.provider.price.MarketPrice) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList)

Example 4 with MarketPrice

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

the class CreateOfferViewModel method createListeners.

private void createListeners() {
    amountStringListener = (ov, oldValue, newValue) -> {
        if (!ignoreAmountStringListener) {
            if (isBtcInputValid(newValue).isValid) {
                setAmountToModel();
                dataModel.calculateVolume();
                dataModel.calculateTotalToPay();
            }
            updateButtonDisableState();
        }
    };
    minAmountStringListener = (ov, oldValue, newValue) -> {
        if (isBtcInputValid(newValue).isValid)
            setMinAmountToModel();
        updateButtonDisableState();
    };
    priceStringListener = (ov, oldValue, newValue) -> {
        updateMarketPriceAvailable();
        final String currencyCode = dataModel.getTradeCurrencyCode().get();
        if (!ignorePriceStringListener) {
            if (isPriceInputValid(newValue).isValid) {
                setPriceToModel();
                dataModel.calculateVolume();
                dataModel.calculateTotalToPay();
                if (!inputIsMarketBasedPrice) {
                    if (marketPrice != null && marketPrice.isRecentExternalPriceAvailable()) {
                        double marketPriceAsDouble = marketPrice.getPrice();
                        try {
                            double priceAsDouble = btcFormatter.parseNumberStringToDouble(price.get());
                            double relation = priceAsDouble / marketPriceAsDouble;
                            final OfferPayload.Direction compareDirection = CurrencyUtil.isCryptoCurrency(currencyCode) ? OfferPayload.Direction.SELL : OfferPayload.Direction.BUY;
                            double percentage = dataModel.getDirection() == compareDirection ? 1 - relation : relation - 1;
                            percentage = MathUtils.roundDouble(percentage, 4);
                            dataModel.setMarketPriceMargin(percentage);
                            marketPriceMargin.set(btcFormatter.formatToPercent(percentage));
                            applyMakerFee();
                        } catch (NumberFormatException t) {
                            marketPriceMargin.set("");
                            new Popup<>().warning(Res.get("validation.NaN")).show();
                        }
                    } else {
                        log.debug("We don't have a market price. We use the static price instead.");
                    }
                }
            }
        }
        updateButtonDisableState();
    };
    marketPriceMarginStringListener = (ov, oldValue, newValue) -> {
        if (inputIsMarketBasedPrice) {
            try {
                if (!newValue.isEmpty() && !newValue.equals("-")) {
                    double percentage = btcFormatter.parsePercentStringToDouble(newValue);
                    if (percentage >= 1 || percentage <= -1) {
                        new Popup<>().warning(Res.get("popup.warning.tooLargePercentageValue") + "\n" + Res.get("popup.warning.examplePercentageValue")).show();
                    } else {
                        final String currencyCode = dataModel.getTradeCurrencyCode().get();
                        MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
                        if (marketPrice != null && marketPrice.isRecentExternalPriceAvailable()) {
                            percentage = MathUtils.roundDouble(percentage, 4);
                            double marketPriceAsDouble = marketPrice.getPrice();
                            final boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode);
                            final OfferPayload.Direction compareDirection = isCryptoCurrency ? OfferPayload.Direction.SELL : OfferPayload.Direction.BUY;
                            double factor = dataModel.getDirection() == compareDirection ? 1 - percentage : 1 + percentage;
                            double targetPrice = marketPriceAsDouble * factor;
                            int precision = isCryptoCurrency ? Altcoin.SMALLEST_UNIT_EXPONENT : Fiat.SMALLEST_UNIT_EXPONENT;
                            // protect from triggering unwanted updates
                            ignorePriceStringListener = true;
                            price.set(btcFormatter.formatRoundedDoubleWithPrecision(targetPrice, precision));
                            ignorePriceStringListener = false;
                            setPriceToModel();
                            dataModel.setMarketPriceMargin(percentage);
                            dataModel.calculateVolume();
                            dataModel.calculateTotalToPay();
                            updateButtonDisableState();
                            applyMakerFee();
                        } else {
                            new Popup<>().warning(Res.get("popup.warning.noPriceFeedAvailable")).show();
                            marketPriceMargin.set("");
                        }
                    }
                }
            } catch (NumberFormatException t) {
                log.error(t.toString());
                t.printStackTrace();
                new Popup<>().warning(Res.get("validation.NaN")).show();
            } catch (Throwable t) {
                log.error(t.toString());
                t.printStackTrace();
                new Popup<>().warning(Res.get("validation.inputError", t.toString())).show();
            }
        }
    };
    useMarketBasedPriceListener = (observable, oldValue, newValue) -> {
        if (newValue)
            priceValidationResult.set(new InputValidator.ValidationResult(true));
    };
    volumeStringListener = (ov, oldValue, newValue) -> {
        if (!ignoreVolumeStringListener) {
            if (isVolumeInputValid(newValue).isValid) {
                setVolumeToModel();
                setPriceToModel();
                dataModel.calculateAmount();
                dataModel.calculateTotalToPay();
            }
            updateButtonDisableState();
        }
    };
    securityDepositStringListener = (ov, oldValue, newValue) -> {
        if (!ignoreSecurityDepositStringListener) {
            if (securityDepositValidator.validate(newValue).isValid) {
                setBuyerSecurityDepositToModel();
                dataModel.calculateTotalToPay();
            }
            updateButtonDisableState();
        }
    };
    amountAsCoinListener = (ov, oldValue, newValue) -> {
        if (newValue != null)
            amount.set(btcFormatter.formatCoin(newValue));
        else
            amount.set("");
        applyMakerFee();
    };
    minAmountAsCoinListener = (ov, oldValue, newValue) -> {
        if (newValue != null)
            minAmount.set(btcFormatter.formatCoin(newValue));
        else
            minAmount.set("");
    };
    priceListener = (ov, oldValue, newValue) -> {
        ignorePriceStringListener = true;
        if (newValue != null)
            price.set(btcFormatter.formatPrice(newValue));
        else
            price.set("");
        ignorePriceStringListener = false;
        applyMakerFee();
    };
    volumeListener = (ov, oldValue, newValue) -> {
        ignoreVolumeStringListener = true;
        if (newValue != null)
            volume.set(btcFormatter.formatVolume(newValue));
        else
            volume.set("");
        ignoreVolumeStringListener = false;
        applyMakerFee();
    };
    securityDepositAsCoinListener = (ov, oldValue, newValue) -> {
        if (newValue != null)
            buyerSecurityDeposit.set(btcFormatter.formatCoin(newValue));
        else
            buyerSecurityDeposit.set("");
    };
    isWalletFundedListener = (ov, oldValue, newValue) -> updateButtonDisableState();
    /* feeFromFundingTxListener = (ov, oldValue, newValue) -> {
            updateButtonDisableState();
        };*/
    currenciesUpdateListener = (observable, oldValue, newValue) -> {
        updateMarketPriceAvailable();
        updateButtonDisableState();
    };
}
Also used : MarketPrice(bisq.core.provider.price.MarketPrice) Popup(bisq.desktop.main.overlays.popups.Popup) OfferPayload(bisq.core.offer.OfferPayload)

Example 5 with MarketPrice

use of bisq.core.provider.price.MarketPrice 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)

Aggregations

MarketPrice (bisq.core.provider.price.MarketPrice)8 OfferPayload (bisq.core.offer.OfferPayload)3 PriceFeedService (bisq.core.provider.price.PriceFeedService)3 BSFormatter (bisq.desktop.util.BSFormatter)3 AddressEntry (bisq.core.btc.AddressEntry)2 BsqWalletService (bisq.core.btc.wallet.BsqWalletService)2 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)2 CryptoCurrency (bisq.core.locale.CryptoCurrency)2 CurrencyUtil (bisq.core.locale.CurrencyUtil)2 Offer (bisq.core.offer.Offer)2 OpenOfferManager (bisq.core.offer.OpenOfferManager)2 PaymentAccount (bisq.core.payment.PaymentAccount)2 Popup (bisq.desktop.main.overlays.popups.Popup)2 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)2 Coin (org.bitcoinj.core.Coin)2 DevEnv (bisq.common.app.DevEnv)1 Version (bisq.common.app.Version)1 KeyRing (bisq.common.crypto.KeyRing)1 ErrorMessageHandler (bisq.common.handlers.ErrorMessageHandler)1 ResultHandler (bisq.common.handlers.ResultHandler)1