use of io.bisq.core.payment.PaymentAccount in project bisq-api by mrosseel.
the class BisqProxy method addPaymentAccount.
public PaymentAccount addPaymentAccount(PaymentAccount paymentAccount) {
user.addPaymentAccount(paymentAccount);
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
if (singleTradeCurrency != null) {
if (singleTradeCurrency instanceof FiatCurrency)
preferences.addFiatCurrency((FiatCurrency) singleTradeCurrency);
else
preferences.addCryptoCurrency((CryptoCurrency) singleTradeCurrency);
} else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) {
if (tradeCurrencies.contains(CurrencyUtil.getDefaultTradeCurrency()))
paymentAccount.setSelectedTradeCurrency(CurrencyUtil.getDefaultTradeCurrency());
else
paymentAccount.setSelectedTradeCurrency(tradeCurrencies.get(0));
tradeCurrencies.forEach(tradeCurrency -> {
if (tradeCurrency instanceof FiatCurrency)
preferences.addFiatCurrency((FiatCurrency) tradeCurrency);
else
preferences.addCryptoCurrency((CryptoCurrency) tradeCurrency);
});
}
accountAgeWitnessService.publishMyAccountAgeWitness(paymentAccount.getPaymentAccountPayload());
return paymentAccount;
}
use of io.bisq.core.payment.PaymentAccount 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, String amount, boolean useSavingsWallet) {
final CompletableFuture<Trade> futureResult = new CompletableFuture<>();
final Offer offer;
try {
offer = getOffer(offerId);
} catch (NotFoundException e) {
return failFuture(futureResult, e);
}
// 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(Long.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;
}
use of io.bisq.core.payment.PaymentAccount in project bisq-api by mrosseel.
the class BisqProxy method removePaymentAccount.
public void removePaymentAccount(String id) {
final PaymentAccount paymentAccount = user.getPaymentAccount(id);
if (null == paymentAccount) {
throw new NotFoundException("Payment account not found: " + id);
}
user.removePaymentAccount(paymentAccount);
}
Aggregations