@Override protected BigMoney fromConvertedColumns(Object[] convertedColumns) { CurrencyUnit currencyUnitPart = (CurrencyUnit) convertedColumns[0]; BigDecimal amountPart = (BigDecimal) convertedColumns[1]; BigMoney money = BigMoney.of(currencyUnitPart, amountPart); return money; }
@Override protected BigMoney fromConvertedColumns(Object[] convertedColumns) { CurrencyUnit currencyUnitPart = (CurrencyUnit) convertedColumns[0]; BigDecimal amountPart = (BigDecimal) convertedColumns[1]; BigMoney money = BigMoney.of(currencyUnitPart, amountPart); return money; }
/** * Obtains an instance of {@code BigMoney} representing zero. * <p> * The scale of the money will be zero. * For example, {@code zero(USD)} creates the instance {@code USD 0}. * * @param currency the currency, not null * @return the instance representing zero, never null */ public static BigMoney zero(CurrencyUnit currency) { return BigMoney.of(currency, BigDecimal.ZERO); }
@Override public BigMoney fromNonNullValue(BigDecimal val) { return BigMoney.of(currencyUnit, val); }
/** * Obtains an instance of {@code BigMoney} representing zero at a specific scale. * <p> * For example, {@code zero(USD, 2)} creates the instance {@code USD 0.00}. * * @param currency the currency, not null * @param scale the scale to use, zero or positive * @return the instance representing zero, never null * @throws IllegalArgumentException if the scale is negative */ public static BigMoney zero(CurrencyUnit currency, int scale) { return BigMoney.of(currency, BigDecimal.valueOf(0, scale)); }
/** * Returns a copy of this monetary value with the amount negated. * <p> * This instance is immutable and unaffected by this method. * * @return the new instance with the amount negated, never null */ public BigMoney negated() { if (isZero()) { return this; } return BigMoney.of(currency, amount.negate()); }
private static LimitOrder createOrder(String tradableIdentifier, String currency, List<BigDecimal> priceAndAmount, Order.OrderType orderType) { return new LimitOrder(orderType, priceAndAmount.get(1), tradableIdentifier, currency, BigMoney.of(CurrencyUnit.USD, priceAndAmount.get(0))); }
/** * 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())); }
/** * Converts the context to a {@code BigMoney}. * * @return the monetary value, never null * @throws MoneyFormatException if either the currency or amount is missing */ public BigMoney toBigMoney() { if (currency == null) { throw new MoneyFormatException("Cannot convert to BigMoney as no currency found"); } if (amount == null) { throw new MoneyFormatException("Cannot convert to BigMoney as no amount found"); } return BigMoney.of(currency, amount); }
/** * Obtains an instance of {@code Money} representing zero. * <p> * For example, {@code zero(USD)} creates the instance {@code USD 0.00}. * * @param currency the currency, not null * @return the instance representing zero, never null */ public static Money zero(CurrencyUnit currency) { MoneyUtils.checkNotNull(currency, "Currency must not be null"); BigDecimal bd = BigDecimal.valueOf(0, currency.getDecimalPlaces()); return new Money(BigMoney.of(currency, bd)); }
/** * Adapts a BitcoinCentralAccountInfo to a AccountInfo */ public static AccountInfo adaptAccountInfo(BitcoinCentralAccountInfo accountInfo, String userName) { Wallet eurWallet = new Wallet("EUR", BigMoney.of(CurrencyUnit.EUR, accountInfo.getEur())); Wallet btcWallet = Wallet.createInstance("BTC", accountInfo.getBtc()); Wallet usdWallet = new Wallet("GBP", BigMoney.of(CurrencyUnit.CAD, accountInfo.getGbp())); Wallet inrWallet = new Wallet("USD", BigMoney.of(CurrencyUnit.getInstance("INR"), accountInfo.getUsd())); return new AccountInfo(userName, Arrays.asList(btcWallet, usdWallet, eurWallet, inrWallet)); }
/** * Adapts a Transaction[] to a Trades Object */ public static Trades adaptTrades(BitfloorTransaction[] transactions, String currency, String tradableIdentifier) { List<Trade> trades = new ArrayList<Trade>(); for (BitfloorTransaction tx : transactions) { trades.add(new Trade(null, tx.getAmount(), tradableIdentifier, currency, BigMoney.of(CurrencyUnit.of(currency), tx.getPrice()), tx.getTimestamp())); } return new Trades(trades); }
/** * Compares this monetary value to another. * The compared values must be in the same currency. * * @param other the other monetary value, not null * @return -1 if this is less than , 0 if equal, 1 if greater than * @throws CurrencyMismatchException if the currencies differ */ @Override public int compareTo(BigMoneyProvider other) { BigMoney otherMoney = of(other); if (currency.equals(otherMoney.currency) == false) { throw new CurrencyMismatchException(getCurrencyUnit(), otherMoney.getCurrencyUnit()); } return amount.compareTo(otherMoney.amount); }
/** * Adapts a BitfloorBalance to a AccountInfo * * @param bitfloorBalance@return */ public static AccountInfo adaptAccountInfo(BitfloorBalance[] bitfloorBalance, String userName) { // Adapt to XChange DTOs List<Wallet> wallets = new ArrayList<Wallet>(); for (BitfloorBalance balance : bitfloorBalance) { wallets.add(new Wallet(balance.getCurrency(), BigMoney.of(CurrencyUnit.getInstance(balance.getCurrency()), balance.getAmount()))); } return new AccountInfo(userName, wallets); }
@Override public BigDecimal toNonNullValue(BigMoney value) { if (!currencyUnit.equals(value.getCurrencyUnit())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit()); } return BigMoney.of(value).getAmount(); }
public synchronized BigMoney getLowestAsk() throws WalletNotFoundException { BigMoney lowFactor = BigMoney.of(baseCurrency,100); synchronized (lastTickMap) { BigMoney basePrice = lastTickMap.get(baseCurrency).getLast(); for(CurrencyUnit currency : lastTickMap.keySet()) { BigMoney testPrice = lastTickMap.get(currency).getAsk(); BigMoney factor = basePrice.isSameCurrency(testPrice) ? basePrice.dividedBy(testPrice.getAmount(),RoundingMode.HALF_EVEN) : basePrice.convertedTo(currency,BigDecimal.ONE.divide(testPrice.getAmount(),16,RoundingMode.HALF_EVEN)); if(factor.getAmount().compareTo(lowFactor.getAmount()) < 0 ) { lowFactor = factor; } } } return lowFactor; }
/** * Validates that the currency of this money and the specified money match. * * @param moneyProvider the money to check, not null * @throws CurrencyMismatchException if the currencies differ */ private BigMoney checkCurrencyEqual(BigMoneyProvider moneyProvider) { BigMoney money = of(moneyProvider); if (isSameCurrency(money) == false) { throw new CurrencyMismatchException(getCurrencyUnit(), money.getCurrencyUnit()); } return money; }
public static List<LimitOrder> adaptActive(BitcoinCentralMyOrder[] accountTradeOrders) { List<LimitOrder> orders = new ArrayList<LimitOrder>(); for (BitcoinCentralMyOrder order : accountTradeOrders) { if (order.isPendingExecution()) { orders.add(new LimitOrder(order.getCategory().type, order.getAmount(), "BTC", order.getCurrency(), Integer.toString(order.getId()), BigMoney.of(CurrencyUnit.getInstance(order.getCurrency()), order.getPpc()))); } } return orders; } }
/** * Obtains an instance of {@code Money} from a provider, rounding as necessary. * <p> * This allows you to create an instance from any class that implements the * provider, such as {@code BigMoney}. * The rounding mode is used to adjust the scale to the scale of the currency. * * @param moneyProvider the money to convert, not null * @param roundingMode the rounding mode to use, not null * @return the new instance, never null * @throws ArithmeticException if the rounding fails */ public static Money of(BigMoneyProvider moneyProvider, RoundingMode roundingMode) { MoneyUtils.checkNotNull(moneyProvider, "BigMoneyProvider must not be null"); MoneyUtils.checkNotNull(roundingMode, "RoundingMode must not be null"); return new Money(BigMoney.of(moneyProvider).withCurrencyScale(roundingMode)); }
@Override public OpenOrders getOpenOrders() { BitfloorOrder[] openOrders = bitfloor.getOpenOrders(exchangeSpecification.getApiKey(), bodyDigest, exchangeSpecification.getPassword(), Bitfloor.Version.v1, nextNonce()); List<LimitOrder> orders = new ArrayList<LimitOrder>(); for (BitfloorOrder oo : openOrders) { orders.add(new LimitOrder(oo.getSide() == BitfloorOrder.Side.buy ? BID : ASK, oo.getSize(), "BTC", "USD", oo.getId(), BigMoney.of(CurrencyUnit.USD, oo.getPrice()))); } return new OpenOrders(orders); }