public String parseAmountInDollars(BigDecimal exchangeRate) { return coinbaseTransaction.getAmount().getAmount().abs() .multiply(exchangeRate) .setScale(2, RoundingMode.CEILING) .toPlainString(); }
private boolean isSentTransaction(com.coinbase.api.entity.Transaction coinbaseTransaction) { BigDecimal amount = coinbaseTransaction.getAmount().getAmount(); return amount.compareTo(new BigDecimal(0.0)) < 0; }
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 Object[] toConvertedColumns(Money value) { return new Object[] { value.getCurrencyUnit(), value.getAmount() }; }
@Override protected Object[] toConvertedColumns(Money value) { return new Object[] { value.getCurrencyUnit(), value.getAmount() }; }
@Override public void update(Account account) { String sql = "update ACCOUNT_OBJECTIVE " + "set SAVINGS = ?"; for (Objective objective : account.getObjectives()) { jdbcTemplate.update(sql, objective.getSavings().getAmount()); } } }
public static String getAsString(Money money) { if (money == null) { return null; } return money.getAmount().toString() + " " + money.getCurrencyUnit().toString(); }
@Override public PaybackConfirmation save(AccountIncome income, Purchase purchase) { String sql = "insert into PAYBACK (NUMBER, AMOUNT, DATE, ACCOUNT_NUMBER, MERCHANT_NUMBER, TRANSACTION_AMOUNT, TRANSACTION_DATE) " + "values (?, ?, ?, ?, ?, ?, ?)"; String number = nextConfirmationNumber(); jdbcTemplate.update(sql, number, income.getAmount().getAmount(), new Date(now().toDate().getTime()), income.getAccountNumber(), purchase.getMerchantNumber(), purchase.getAmount().getAmount(), new Date(purchase.getDate().toDate().getTime())); return new PaybackConfirmation(number, income); }
@Override public PaybackConfirmation save(AccountIncome income, Purchase purchase) { String sql = "insert into PAYBACK (NUMBER, AMOUNT, DATE, ACCOUNT_NUMBER, MERCHANT_NUMBER, TRANSACTION_AMOUNT, TRANSACTION_DATE) " + "values (?, ?, ?, ?, ?, ?, ?)"; String number = nextConfirmationNumber(); jdbcTemplate.update(sql, number, income.getAmount().getAmount(), new Date(now().toDate().getTime()), income.getAccountNumber(), purchase.getMerchantNumber(), purchase.getAmount().getAmount(), new Date(purchase.getDate().toDate().getTime())); return new PaybackConfirmation(number, income); }
@Override public BigDecimal toNonNullValue(Money value) { if (!currencyUnit.equals(value.getCurrencyUnit())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit()); } return value.getAmount(); }
@JsonProperty @JsonDeserialize(using=MoneyDeserializer.class) public void setAmount(Money amount) { _amount = amount; if (amount != null) { setAmountString(amount.getAmount().toPlainString()); setAmountCurrencyIso(amount.getCurrencyUnit().getCurrencyCode()); } else { setAmountString(null); setAmountCurrencyIso(null); } }
@JsonProperty @JsonDeserialize(using=MoneyDeserializer.class) public void setAmount(Money amount) { _amount = amount; if (amount != null) { setAmountString(amount.getAmount().toPlainString()); setAmountCurrencyIso(amount.getCurrencyUnit().getCurrencyCode()); } else { setAmountString(null); setAmountCurrencyIso(null); } }
@Override public Object getPropertyValue(Object component, int propertyIndex) throws HibernateException { if (component == null) { return null; } final Money money = (Money) component; switch (propertyIndex) { case 0: return money.getAmount(); case 1: return money.getCurrencyUnit().getCurrencyCode(); default: throw new HibernateException("Invalid property index [" + propertyIndex + "]"); } }
public void setPrice(Money price) { _price = price; if (price != null) { setPriceString(price.getAmount().toPlainString()); setPriceCurrencyIso(price.getCurrencyUnit().getCurrencyCode()); } else { setPriceString(null); setPriceCurrencyIso(null); } } }
public void setPrice(Money price) { _price = price; if (price != null) { setPriceString(price.getAmount().toPlainString()); setPriceCurrencyIso(price.getCurrencyUnit().getCurrencyCode()); } else { setPriceString(null); setPriceCurrencyIso(null); } } }
@Override public Transfer sell(Money amount, String paymentMethodId, Boolean commit) throws CoinbaseException, IOException { URL sellsUrl; try { sellsUrl = new URL(_baseApiUrl, "sells"); } catch (MalformedURLException ex) { throw new AssertionError(ex); } Request request = newAccountSpecificRequest(); request.setQty(amount.getAmount().doubleValue()); request.setPaymentMethodId(paymentMethodId); request.setCurrency(amount.getCurrencyUnit().getCurrencyCode()); request.setCommit(commit); return post(sellsUrl, request, TransferResponse.class).getTransfer(); }
@Override public Transfer buy(Money amount, String paymentMethodId, Boolean commit) throws CoinbaseException, IOException { URL buysUrl; try { buysUrl = new URL(_baseApiUrl, "buys"); } catch (MalformedURLException ex) { throw new AssertionError(ex); } Request request = newAccountSpecificRequest(); request.setQty(amount.getAmount().doubleValue()); request.setPaymentMethodId(paymentMethodId); request.setCurrency(amount.getCurrencyUnit().getCurrencyCode()); request.setCommit(commit); return post(buysUrl, request, TransferResponse.class).getTransfer(); }
@Override public Transfer sell(Money amount, String paymentMethodId, Boolean commit) throws CoinbaseException, IOException { URL sellsUrl; try { sellsUrl = new URL(_baseApiUrl, "sells"); } catch (MalformedURLException ex) { throw new AssertionError(ex); } Request request = newAccountSpecificRequest(); request.setQty(amount.getAmount().doubleValue()); request.setPaymentMethodId(paymentMethodId); request.setCurrency(amount.getCurrencyUnit().getCurrencyCode()); request.setCommit(commit); return post(sellsUrl, request, TransferResponse.class).getTransfer(); }
@Override public Transfer buy(Money amount, String paymentMethodId, Boolean commit) throws CoinbaseException, IOException { URL buysUrl; try { buysUrl = new URL(_baseApiUrl, "buys"); } catch (MalformedURLException ex) { throw new AssertionError(ex); } Request request = newAccountSpecificRequest(); request.setQty(amount.getAmount().doubleValue()); request.setPaymentMethodId(paymentMethodId); request.setCurrency(amount.getCurrencyUnit().getCurrencyCode()); request.setCommit(commit); return post(buysUrl, request, TransferResponse.class).getTransfer(); }
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { if (value == null) { BigDecimalType.INSTANCE.set(st, null, index, session); StringType.INSTANCE.set(st, null, index + 1, session); } else { Money money = (Money) value; BigDecimalType.INSTANCE.set(st, money.getAmount(), index, session); StringType.INSTANCE.set(st, money.getCurrencyUnit().getCurrencyCode(), index + 1, session); } }