public static BigDecimal of(final BigDecimal amount, final Currency currency) { final CurrencyUnit currencyUnit = CurrencyUnit.getInstance(currency.toString()); return amount.setScale(currencyUnit.getDecimalPlaces(), ROUNDING_METHOD); } }
public String parseAmountInDollars(BigDecimal exchangeRate) { return coinbaseTransaction.getAmount().getAmount().abs() .multiply(exchangeRate) .setScale(2, RoundingMode.CEILING) .toPlainString(); }
public void sendPayment(Author author, BigDecimal amount, String url) throws TransferFailedException { try { String note = "Commit payment:\n__" + author.getUsername() + "__ " + url; Transaction transaction = new Transaction(); transaction.setTo(author.getEmail()); transaction.setAmount(Money.of(CurrencyUnit.of("BTC"), amount, RoundingMode.DOWN)); transaction.setNotes(note); Transaction response = coinbase.sendMoney(transaction); if (response.getStatus() != Transaction.Status.COMPLETE) { throw new TransferFailedException(); } } catch (CoinbaseException | IOException e) { throw new TransferFailedException(e); } }
@Override protected BigMoney fromConvertedColumns(Object[] convertedColumns) { CurrencyUnit currencyUnitPart = (CurrencyUnit) convertedColumns[0]; Long amountMajorPart = (Long) convertedColumns[1]; BigMoney theMoney = BigMoney.ofMajor(currencyUnitPart, amountMajorPart); if (theMoney.getScale() < currencyUnitPart.getDecimalPlaces()) { theMoney = theMoney.withCurrencyScale(); } return theMoney; }
/** * Checks if this instance and the specified instance have the same currency. * * @param money the money to check, not null * @return true if they have the same currency */ public boolean isSameCurrency(BigMoneyProvider money) { return (currency.equals(of(money).getCurrencyUnit())); }
public String getSendLimitCurrency() { if (_sendLimitAmount != null) { return _sendLimitAmount.getCurrencyUnit().getCurrencyCode(); } else { return null; } } }
@Override protected Value<String> toDatastore(final BigMoney value) { return StringValue.of(value.toString()); } }
@Override protected Value<String> toDatastore(final Money value) { return StringValue.of(value.toString()); } }
@Override protected BigMoney toPojo(final Value<String> value) { return BigMoney.parse(value.get()); }
@Override protected Money toPojo(final Value<String> value) { return Money.parse(value.get()); }
/** * Checks if the monetary value is zero, treating null as zero. * <p> * This method accepts any implementation of {@code BigMoneyProvider}. * * @param moneyProvider the money to check, null returns zero * @return true if the money is null or zero */ public static boolean isZero(BigMoneyProvider moneyProvider) { return (moneyProvider == null || moneyProvider.toBigMoney().isZero()); }
/** * Checks if the monetary value is positive and non-zero, treating null as zero. * <p> * This method accepts any implementation of {@code BigMoneyProvider}. * * @param moneyProvider the money to check, null returns false * @return true if the money is non-null and positive */ public static boolean isPositive(BigMoneyProvider moneyProvider) { return (moneyProvider != null && moneyProvider.toBigMoney().isPositive()); }
/** * Checks if the monetary value is positive or zero, treating null as zero. * <p> * This method accepts any implementation of {@code BigMoneyProvider}. * * @param moneyProvider the money to check, null returns true * @return true if the money is null, zero or positive */ public static boolean isPositiveOrZero(BigMoneyProvider moneyProvider) { return (moneyProvider == null || moneyProvider.toBigMoney().isPositiveOrZero()); }
/** * Checks if the monetary value is negative or zero, treating null as zero. * <p> * This method accepts any implementation of {@code BigMoneyProvider}. * * @param moneyProvider the money to check, null returns true * @return true if the money is null, zero or negative */ public static boolean isNegativeOrZero(BigMoneyProvider moneyProvider) { return (moneyProvider == null || moneyProvider.toBigMoney().isNegativeOrZero()); }
/** * Checks if the monetary value is negative and non-zero, treating null as zero. * <p> * This method accepts any implementation of {@code BigMoneyProvider}. * * @param moneyProvider the money to check, null returns false * @return true if the money is non-null and negative */ public static boolean isNegative(BigMoneyProvider moneyProvider) { return (moneyProvider != null && moneyProvider.toBigMoney().isNegative()); }
private boolean isSentTransaction(com.coinbase.api.entity.Transaction coinbaseTransaction) { BigDecimal amount = coinbaseTransaction.getAmount().getAmount(); return amount.compareTo(new BigDecimal(0.0)) < 0; }
@Override public BigMoney fromNonNullValue(Long value) { BigMoney theMoney = BigMoney.ofMajor(currencyUnit, value); if (theMoney.getScale() < currencyUnit.getDecimalPlaces()) { theMoney = theMoney.withCurrencyScale(); } return theMoney; }
public BigDecimal getAccountBalance() throws IOException, CoinbaseException { List<Account> accounts = coinbase.getAccounts().getAccounts(); Account primary = null; for (Account account : accounts) { if (account.isPrimary()) { primary = account; break; } } if (primary != null) return coinbase.getBalance(primary.getId()).getAmount(); else return new BigDecimal(0.0); } }
@Override protected BigMoney fromConvertedColumns(Object[] convertedColumns) { CurrencyUnit currencyUnitPart = (CurrencyUnit) convertedColumns[0]; Long amountMajorPart = (Long) convertedColumns[1]; BigMoney theMoney = BigMoney.ofMajor(currencyUnitPart, amountMajorPart); if (theMoney.getScale() < currencyUnitPart.getDecimalPlaces()) { theMoney = theMoney.withCurrencyScale(); } return theMoney; }