Search in sources :

Example 21 with Trade

use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.

the class ClosedTradesView method initialize.

@Override
public void initialize() {
    priceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.price")));
    amountColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountWithCur", Res.getBaseCurrencyCode())));
    volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amount")));
    marketColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.market")));
    directionColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.offerType")));
    dateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.dateTime")));
    tradeIdColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.tradeId")));
    stateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.state")));
    avatarColumn.setText("");
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tableView.setPlaceholder(new AutoTooltipLabel(Res.get("table.placeholder.noItems", Res.get("shared.trades"))));
    setTradeIdColumnCellFactory();
    setDirectionColumnCellFactory();
    setAmountColumnCellFactory();
    setPriceColumnCellFactory();
    setVolumeColumnCellFactory();
    setDateColumnCellFactory();
    setMarketColumnCellFactory();
    setStateColumnCellFactory();
    setAvatarColumnCellFactory();
    tradeIdColumn.setComparator(Comparator.comparing(o -> o.getTradable().getId()));
    dateColumn.setComparator(Comparator.comparing(o -> o.getTradable().getDate()));
    directionColumn.setComparator(Comparator.comparing(o -> o.getTradable().getOffer().getDirection()));
    marketColumn.setComparator(Comparator.comparing(model::getMarketLabel));
    priceColumn.setComparator((o1, o2) -> {
        final Tradable tradable1 = o1.getTradable();
        final Tradable tradable2 = o2.getTradable();
        Price price1 = null;
        Price price2 = null;
        if (tradable1 != null)
            price1 = tradable1 instanceof Trade ? ((Trade) tradable1).getTradePrice() : tradable1.getOffer().getPrice();
        if (tradable2 != null)
            price2 = tradable2 instanceof Trade ? ((Trade) tradable2).getTradePrice() : tradable2.getOffer().getPrice();
        return price1 != null && price2 != null ? price1.compareTo(price2) : 0;
    });
    volumeColumn.setComparator((o1, o2) -> {
        if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
            Volume tradeVolume1 = ((Trade) o1.getTradable()).getTradeVolume();
            Volume tradeVolume2 = ((Trade) o2.getTradable()).getTradeVolume();
            return tradeVolume1 != null && tradeVolume2 != null ? tradeVolume1.compareTo(tradeVolume2) : 0;
        } else
            return 0;
    });
    amountColumn.setComparator((o1, o2) -> {
        if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
            Coin amount1 = ((Trade) o1.getTradable()).getTradeAmount();
            Coin amount2 = ((Trade) o2.getTradable()).getTradeAmount();
            return amount1 != null && amount2 != null ? amount1.compareTo(amount2) : 0;
        } else
            return 0;
    });
    avatarColumn.setComparator((o1, o2) -> {
        if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
            NodeAddress tradingPeerNodeAddress1 = ((Trade) o1.getTradable()).getTradingPeerNodeAddress();
            NodeAddress tradingPeerNodeAddress2 = ((Trade) o2.getTradable()).getTradingPeerNodeAddress();
            String address1 = tradingPeerNodeAddress1 != null ? tradingPeerNodeAddress1.getFullAddress() : "";
            String address2 = tradingPeerNodeAddress2 != null ? tradingPeerNodeAddress2.getFullAddress() : "";
            return address1 != null && address2 != null ? address1.compareTo(address2) : 0;
        } else
            return 0;
    });
    stateColumn.setComparator((o1, o2) -> model.getState(o1).compareTo(model.getState(o2)));
    dateColumn.setSortType(TableColumn.SortType.DESCENDING);
    tableView.getSortOrder().add(dateColumn);
    exportButton.setText(Res.get("shared.exportCSV"));
}
Also used : Button(javafx.scene.control.Button) GUIUtil(bisq.desktop.util.GUIUtil) OfferDetailsWindow(bisq.desktop.main.overlays.windows.OfferDetailsWindow) OpenOffer(bisq.core.offer.OpenOffer) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Coin(org.bitcoinj.core.Coin) Tradable(bisq.core.trade.Tradable) CSVEntryConverter(com.googlecode.jcsv.writer.CSVEntryConverter) VBox(javafx.scene.layout.VBox) Volume(bisq.core.monetary.Volume) FxmlView(bisq.desktop.common.view.FxmlView) BSFormatter(bisq.desktop.util.BSFormatter) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) Res(bisq.core.locale.Res) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) PrivateNotificationManager(bisq.core.alert.PrivateNotificationManager) SortedList(javafx.collections.transformation.SortedList) Offer(bisq.core.offer.Offer) TradeDetailsWindow(bisq.desktop.main.overlays.windows.TradeDetailsWindow) Trade(bisq.core.trade.Trade) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Node(javafx.scene.Node) PeerInfoIcon(bisq.desktop.components.PeerInfoIcon) FXML(javafx.fxml.FXML) Stage(javafx.stage.Stage) NodeAddress(bisq.network.p2p.NodeAddress) AppOptionKeys(bisq.core.app.AppOptionKeys) Preferences(bisq.core.user.Preferences) Price(bisq.core.monetary.Price) Named(com.google.inject.name.Named) ObservableList(javafx.collections.ObservableList) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) Comparator(java.util.Comparator) Trade(bisq.core.trade.Trade) Coin(org.bitcoinj.core.Coin) Price(bisq.core.monetary.Price) Volume(bisq.core.monetary.Volume) Tradable(bisq.core.trade.Tradable) NodeAddress(bisq.network.p2p.NodeAddress) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel)

Example 22 with Trade

use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.

the class ClosedTradesView method setTradeIdColumnCellFactory.

private void setTradeIdColumnCellFactory() {
    tradeIdColumn.setCellValueFactory((offerListItem) -> new ReadOnlyObjectWrapper<>(offerListItem.getValue()));
    tradeIdColumn.setCellFactory(new Callback<TableColumn<ClosedTradableListItem, ClosedTradableListItem>, TableCell<ClosedTradableListItem, ClosedTradableListItem>>() {

        @Override
        public TableCell<ClosedTradableListItem, ClosedTradableListItem> call(TableColumn<ClosedTradableListItem, ClosedTradableListItem> column) {
            return new TableCell<ClosedTradableListItem, ClosedTradableListItem>() {

                private HyperlinkWithIcon field;

                @Override
                public void updateItem(final ClosedTradableListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        field = new HyperlinkWithIcon(model.getTradeId(item));
                        field.setOnAction(event -> {
                            Tradable tradable = item.getTradable();
                            if (tradable instanceof Trade)
                                tradeDetailsWindow.show((Trade) tradable);
                            else if (tradable instanceof OpenOffer)
                                offerDetailsWindow.show(tradable.getOffer());
                        });
                        field.setTooltip(new Tooltip(Res.get("tooltip.openPopupForDetails")));
                        setGraphic(field);
                    } else {
                        setGraphic(null);
                        if (field != null)
                            field.setOnAction(null);
                    }
                }
            };
        }
    });
}
Also used : Button(javafx.scene.control.Button) GUIUtil(bisq.desktop.util.GUIUtil) OfferDetailsWindow(bisq.desktop.main.overlays.windows.OfferDetailsWindow) OpenOffer(bisq.core.offer.OpenOffer) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Coin(org.bitcoinj.core.Coin) Tradable(bisq.core.trade.Tradable) CSVEntryConverter(com.googlecode.jcsv.writer.CSVEntryConverter) VBox(javafx.scene.layout.VBox) Volume(bisq.core.monetary.Volume) FxmlView(bisq.desktop.common.view.FxmlView) BSFormatter(bisq.desktop.util.BSFormatter) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) Res(bisq.core.locale.Res) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) PrivateNotificationManager(bisq.core.alert.PrivateNotificationManager) SortedList(javafx.collections.transformation.SortedList) Offer(bisq.core.offer.Offer) TradeDetailsWindow(bisq.desktop.main.overlays.windows.TradeDetailsWindow) Trade(bisq.core.trade.Trade) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Node(javafx.scene.Node) PeerInfoIcon(bisq.desktop.components.PeerInfoIcon) FXML(javafx.fxml.FXML) Stage(javafx.stage.Stage) NodeAddress(bisq.network.p2p.NodeAddress) AppOptionKeys(bisq.core.app.AppOptionKeys) Preferences(bisq.core.user.Preferences) Price(bisq.core.monetary.Price) Named(com.google.inject.name.Named) ObservableList(javafx.collections.ObservableList) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) Comparator(java.util.Comparator) Tradable(bisq.core.trade.Tradable) OpenOffer(bisq.core.offer.OpenOffer) Tooltip(javafx.scene.control.Tooltip) TableColumn(javafx.scene.control.TableColumn) Trade(bisq.core.trade.Trade) TableCell(javafx.scene.control.TableCell) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon)

Example 23 with Trade

use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.

the class PendingTradesView method setAvatarColumnCellFactory.

@SuppressWarnings("UnusedReturnValue")
private TableColumn<PendingTradesListItem, PendingTradesListItem> setAvatarColumnCellFactory() {
    avatarColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    avatarColumn.setCellFactory(new Callback<TableColumn<PendingTradesListItem, PendingTradesListItem>, TableCell<PendingTradesListItem, PendingTradesListItem>>() {

        @Override
        public TableCell<PendingTradesListItem, PendingTradesListItem> call(TableColumn<PendingTradesListItem, PendingTradesListItem> column) {
            return new TableCell<PendingTradesListItem, PendingTradesListItem>() {

                @Override
                public void updateItem(final PendingTradesListItem newItem, boolean empty) {
                    super.updateItem(newItem, empty);
                    if (!empty && newItem != null) {
                        final Trade trade = newItem.getTrade();
                        final NodeAddress tradingPeerNodeAddress = trade.getTradingPeerNodeAddress();
                        int numPastTrades = model.getNumPastTrades(trade);
                        final Offer offer = trade.getOffer();
                        String role = Res.get("peerInfoIcon.tooltip.tradePeer");
                        Node peerInfoIcon = new PeerInfoIcon(tradingPeerNodeAddress, role, numPastTrades, privateNotificationManager, offer, preferences, model.accountAgeWitnessService, formatter, useDevPrivilegeKeys);
                        setPadding(new Insets(1, 0, 0, 0));
                        setGraphic(peerInfoIcon);
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    return avatarColumn;
}
Also used : Insets(javafx.geometry.Insets) Node(javafx.scene.Node) PeerInfoIcon(bisq.desktop.components.PeerInfoIcon) TableColumn(javafx.scene.control.TableColumn) Trade(bisq.core.trade.Trade) TableCell(javafx.scene.control.TableCell) Offer(bisq.core.offer.Offer) NodeAddress(bisq.network.p2p.NodeAddress)

Example 24 with Trade

use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.

the class PendingTradesViewModel method getMyRole.

// 
String getMyRole(PendingTradesListItem item) {
    Trade trade = item.getTrade();
    Contract contract = trade.getContract();
    if (contract != null) {
        Offer offer = trade.getOffer();
        return btcFormatter.getRole(contract.isBuyerMakerAndSellerTaker(), dataModel.isMaker(offer), offer.getCurrencyCode());
    } else {
        return "";
    }
}
Also used : Trade(bisq.core.trade.Trade) Offer(bisq.core.offer.Offer) Contract(bisq.core.trade.Contract)

Example 25 with Trade

use of bisq.core.trade.Trade in project bisq-api by mrosseel.

the class BisqProxy method offerTake.

// / START TODO REFACTOR OFFER TAKE DEPENDENCIES //////////////////////////
public CompletableFuture<Trade> offerTake(String offerId, String paymentAccountId, long amount, boolean useSavingsWallet) {
    final CompletableFuture<Trade> futureResult = new CompletableFuture<>();
    final Offer offer;
    try {
        offer = getOffer(offerId);
    } catch (NotFoundException e) {
        return failFuture(futureResult, e);
    }
    if (offer.getMakerNodeAddress().equals(p2PService.getAddress())) {
        return failFuture(futureResult, new OfferTakerSameAsMakerException("Taker's address same as maker's"));
    }
    // check the paymentAccountId is valid
    final PaymentAccount paymentAccount = getPaymentAccount(paymentAccountId);
    if (paymentAccount == null) {
        return failFuture(futureResult, new PaymentAccountNotFoundException("Could not find payment account with id: " + paymentAccountId));
    }
    // check the paymentAccountId is compatible with the offer
    if (!isPaymentAccountValidForOffer(offer, paymentAccount)) {
        final String errorMessage = "PaymentAccount is not valid for offer, needs " + offer.getCurrencyCode();
        return failFuture(futureResult, new IncompatiblePaymentAccountException(errorMessage));
    }
    // check the amount is within the range
    Coin coinAmount = Coin.valueOf(amount);
    // workaround because TradeTask does not have an error handler to notify us that something went wrong
    if (btcWalletService.getAvailableBalance().isLessThan(coinAmount)) {
        final String errorMessage = "Available balance " + btcWalletService.getAvailableBalance() + " is less than needed amount: " + coinAmount;
        return failFuture(futureResult, new InsufficientMoneyException(errorMessage));
    }
    // check that the price is correct ??
    // check taker fee
    // check security deposit for BTC buyer
    // check security deposit for BTC seller
    Coin securityDeposit = offer.getDirection() == OfferPayload.Direction.SELL ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit();
    Coin txFeeFromFeeService = feeService.getTxFee(600);
    Coin fundsNeededForTradeTemp = securityDeposit.add(txFeeFromFeeService).add(txFeeFromFeeService);
    final Coin fundsNeededForTrade;
    if (offer.isBuyOffer())
        fundsNeededForTrade = fundsNeededForTradeTemp.add(coinAmount);
    else
        fundsNeededForTrade = fundsNeededForTradeTemp;
    Coin takerFee = getTakerFee(coinAmount);
    checkNotNull(txFeeFromFeeService, "txFeeFromFeeService must not be null");
    checkNotNull(takerFee, "takerFee must not be null");
    tradeManager.onTakeOffer(coinAmount, txFeeFromFeeService, takerFee, isCurrencyForTakerFeeBtc(coinAmount), offer.getPrice().getValue(), fundsNeededForTrade, offer, paymentAccount.getId(), useSavingsWallet, futureResult::complete, error -> futureResult.completeExceptionally(new RuntimeException(error)));
    return futureResult;
}
Also used : PaymentAccount(bisq.core.payment.PaymentAccount) FileNotFoundException(java.io.FileNotFoundException) SellerAsMakerTrade(bisq.core.trade.SellerAsMakerTrade) BuyerAsMakerTrade(bisq.core.trade.BuyerAsMakerTrade) Trade(bisq.core.trade.Trade) Coin(org.bitcoinj.core.Coin) CompletableFuture(java.util.concurrent.CompletableFuture) OpenOffer(bisq.core.offer.OpenOffer) Offer(bisq.core.offer.Offer) PaymentAccountUtil.isPaymentAccountValidForOffer(bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer)

Aggregations

Trade (bisq.core.trade.Trade)30 Coin (org.bitcoinj.core.Coin)16 Res (bisq.core.locale.Res)13 Offer (bisq.core.offer.Offer)13 OpenOffer (bisq.core.offer.OpenOffer)13 TradeManager (bisq.core.trade.TradeManager)13 List (java.util.List)11 ObservableList (javafx.collections.ObservableList)11 Nullable (javax.annotation.Nullable)11 Transaction (org.bitcoinj.core.Transaction)11 KeyRing (bisq.common.crypto.KeyRing)10 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)10 NodeAddress (bisq.network.p2p.NodeAddress)10 P2PService (bisq.network.p2p.P2PService)10 ArrayList (java.util.ArrayList)10 AppOptionKeys (bisq.core.app.AppOptionKeys)9 AddressEntry (bisq.core.btc.AddressEntry)9 WalletsSetup (bisq.core.btc.wallet.WalletsSetup)9 OpenOfferManager (bisq.core.offer.OpenOfferManager)9 IOException (java.io.IOException)8