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"));
}
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);
}
}
};
}
});
}
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;
}
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 "";
}
}
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;
}
Aggregations