/** * Gets the amount. * <p> * This returns the value of the money as a {@code BigDecimal}. * The scale will be the scale of this money. * * @return the amount, never null */ public BigDecimal getAmount() { return money.getAmount(); }
@Override protected Object[] toConvertedColumns(BigMoney value) { return new Object[] { value.getCurrencyUnit(), value.getAmount() }; }
@Override protected Object[] toConvertedColumns(BigMoney value) { return new Object[] { value.getCurrencyUnit(), value.getAmount() }; }
/** * Converts a price in decimal form to a properly scaled int-String for Mt Gox * * @param price * @return */ public static String getPriceString(BigMoney price) { if (!(price.getCurrencyUnit().toString().equals("JPY") || price.getCurrencyUnit().toString().equals("SEK"))) { return price.getAmount().multiply(new BigDecimal(MtGoxUtils.PRICE_INT_2_DECIMAL_FACTOR)).stripTrailingZeros().toPlainString(); } else { // JPY, SEK return price.getAmount().multiply(new BigDecimal(MtGoxUtils.JPY_SEK_PRICE_INT_2_DECIMAL_FACTOR)).stripTrailingZeros().toPlainString(); } }
private void writeBigMoney(ObjectOutput out, BigMoney obj) throws IOException { writeCurrency(out, obj.getCurrencyUnit()); byte[] bytes = obj.getAmount().unscaledValue().toByteArray(); out.writeInt(bytes.length); out.write(bytes); out.writeInt(obj.getScale()); }
public synchronized BigMoney getHighestBid() throws WalletNotFoundException{ BigMoney highFactor = BigMoney.of(baseCurrency,0.01); synchronized (lastTickMap) { BigMoney basePrice = lastTickMap.get(baseCurrency).getLast(); for(CurrencyUnit currency : lastTickMap.keySet()) { BigMoney testPrice = lastTickMap.get(currency).getBid(); 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(highFactor.getAmount()) > 0 ) { highFactor = factor; } } } return highFactor; }
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; }
/** * Returns a copy of this monetary value with the amount in the same currency subtracted * retaining the scale by rounding the result. * <p> * The scale of the result will be the same as the scale of this instance. * For example,'USD 25.95' minus 'USD 3.029' gives 'USD 22.92 with most rounding modes. * <p> * This instance is immutable and unaffected by this method. * * @param moneyToSubtract the monetary value to add, not null * @param roundingMode the rounding mode to use to adjust the scale, not null * @return the new instance with the input amount subtracted, never null */ public BigMoney minusRetainScale(BigMoneyProvider moneyToSubtract, RoundingMode roundingMode) { BigMoney toSubtract = checkCurrencyEqual(moneyToSubtract); return minusRetainScale(toSubtract.getAmount(), roundingMode); }
/** * Returns a copy of this monetary value with the amount in the same currency added * retaining the scale by rounding the result. * <p> * The scale of the result will be the same as the scale of this instance. * For example,'USD 25.95' plus 'USD 3.021' gives 'USD 28.97' with most rounding modes. * <p> * This instance is immutable and unaffected by this method. * * @param moneyToAdd the monetary value to add, not null * @param roundingMode the rounding mode to use to adjust the scale, not null * @return the new instance with the input amount added, never null */ public BigMoney plusRetainScale(BigMoneyProvider moneyToAdd, RoundingMode roundingMode) { BigMoney toAdd = checkCurrencyEqual(moneyToAdd); return plusRetainScale(toAdd.getAmount(), roundingMode); }
/** * Returns a copy of this monetary value with the amount added. * <p> * This adds the specified amount to this monetary amount, returning a new object. * The amount added must be in the same currency. * <p> * No precision is lost in the result. * The scale of the result will be the maximum of the two scales. * For example, 'USD 25.95' plus 'USD 3.021' gives 'USD 28.971'. * <p> * This instance is immutable and unaffected by this method. * * @param moneyToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null * @throws CurrencyMismatchException if the currencies differ */ public BigMoney plus(BigMoneyProvider moneyToAdd) { BigMoney toAdd = checkCurrencyEqual(moneyToAdd); return plus(toAdd.getAmount()); }
/** * Returns a copy of this monetary value with the amount subtracted. * <p> * This subtracts the specified amount from this monetary amount, returning a new object. * The amount subtracted must be in the same currency. * <p> * No precision is lost in the result. * The scale of the result will be the maximum of the two scales. * For example,'USD 25.95' minus 'USD 3.021' gives 'USD 22.929'. * <p> * This instance is immutable and unaffected by this method. * * @param moneyToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null * @throws CurrencyMismatchException if the currencies differ */ public BigMoney minus(BigMoneyProvider moneyToSubtract) { BigMoney toSubtract = checkCurrencyEqual(moneyToSubtract); return minus(toSubtract.getAmount()); }
@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(); }
if (rates.containsKey(currency)) { if ((rates.get(currency).size() >= 2)) { startRate=rates.get(currency).get(0).getAmount(); endRate=rates.get(currency).get(rates.get(currency).size() - 1).getAmount(); profitPercent = profitBTC.getAmount().divide(equivBTCStartBal.getAmount(),16,RoundingMode.HALF_EVEN); String profitToDisplay = percentFormat.format(profitPercent); log.info("Equivalent BTC Start Balance: "+equivBTCStartBal.withScale(8,RoundingMode.HALF_EVEN).toString()+" Equivalent BTC Current Balance: "+equivBTCEndBal.withScale(8,RoundingMode.HALF_EVEN).toString());
@Override public String placeLimitOrder(LimitOrder limitOrder) { BitcoinCentralMyOrder myOrder = bitcoincentral.placeLimitOrder(credentials, new TradeOrderRequestWrapper(limitOrder.getTradableAmount(), getCategory(limitOrder.getType()), limitOrder .getTransactionCurrency(), limitOrder.getLimitPrice().getAmount(), BitcoinCentralTradeRequest.Type.limit_order)); log.debug("myOrder = {}", myOrder); return Integer.toString(myOrder.getId()); }
String str = money.getAmount().toPlainString(); char zeroChar = activeStyle.getZeroCharacter(); if (zeroChar != '0') {
@Override public String placeLimitOrder(LimitOrder limitOrder) { NewOrderResult ord = bitfloor.newOrder(exchangeSpecification.getApiKey(), bodyDigest, exchangeSpecification.getPassword(), Bitfloor.Version.v1, nextNonce(), limitOrder.getTradableAmount(), limitOrder.getLimitPrice().getAmount(), limitOrder.getType() == BID ? BitfloorOrder.Side.buy : BitfloorOrder.Side.sell, Product.BTCUSD); return ord.getId(); }
BigDecimal oneDivFrom = BigDecimal.ONE.divide(lastTickAskFrom.getAmount(),16,RoundingMode.HALF_EVEN); BigDecimal oneDivTo = BigDecimal.ONE.divide(lastTickBidTo.getAmount(),16,RoundingMode.HALF_EVEN); BigMoney qtyTo = qtyFromBTC.convertedTo(to.getCurrencyUnit(),lastTickBidTo.getAmount()); BigMoney qtyToBTC = qtyTo.convertedTo(CurrencyUnit.of("BTC"),oneDivTo); MarketOrder buyOrder = new MarketOrder(OrderType.BID,qtyFromBTC.getAmount(),"BTC",from.getCurrencyUnit().toString()); MarketOrder sellOrder = new MarketOrder(OrderType.ASK,qtyToBTC.getAmount(),"BTC",to.getCurrencyUnit().toString());
@Override public String placeLimitOrder(LimitOrder limitOrder) { verify(limitOrder); Assert.notNull(limitOrder.getLimitPrice().getAmount(), "getLimitPrice().getAmount() cannot be null"); Assert.notNull(limitOrder.getLimitPrice().getCurrencyUnit(), "getLimitPrice().getCurrencyUnit() cannot be null"); String tradableIdentifier = limitOrder.getTradableIdentifier(); String currency = limitOrder.getLimitPrice().getCurrencyUnit().toString(); String type = limitOrder.getType().equals(OrderType.BID) ? "bid" : "ask"; // need to convert to MtGox "amount" BigDecimal amount = limitOrder.getTradableAmount().multiply(new BigDecimal(MtGoxUtils.BTC_VOLUME_AND_AMOUNT_INT_2_DECIMAL_FACTOR)); // need to convert to MtGox "Price" String price = MtGoxUtils.getPriceString(limitOrder.getLimitPrice()); MtGoxGenericResponse mtGoxSuccess = mtGoxV1.placeOrder(exchangeSpecification.getApiKey(), paramsDigest, getNonce(), tradableIdentifier, currency, type, amount, price); return mtGoxSuccess.getReturnString(); }
@Override public String placeLimitOrder(LimitOrder limitOrder) throws IOException { verify(limitOrder); Assert.notNull(limitOrder.getLimitPrice().getAmount(), "getLimitPrice().getAmount() cannot be null"); Assert.notNull(limitOrder.getLimitPrice().getCurrencyUnit(), "getLimitPrice().getCurrencyUnit() cannot be null"); String tradableIdentifier = limitOrder.getTradableIdentifier(); String currency = limitOrder.getLimitPrice().getCurrencyUnit().toString(); String type = limitOrder.getType().equals(OrderType.BID) ? "bid" : "ask"; // need to convert to MtGox "amount" BigDecimal amount = limitOrder.getTradableAmount().multiply(new BigDecimal(MtGoxUtils.BTC_VOLUME_AND_AMOUNT_INT_2_DECIMAL_FACTOR)); // need to convert to MtGox "Price" String price = MtGoxUtils.getPriceString(limitOrder.getLimitPrice()); try { MtGoxGenericResponse mtGoxGenericResponse = mtGoxV2.placeOrder(exchangeSpecification.getApiKey(), signatureCreator, MtGoxUtils.getNonce(), tradableIdentifier, currency, type, amount, price); if (mtGoxGenericResponse.getResult().equals("success")) { return mtGoxGenericResponse.getDataString(); } else if (mtGoxGenericResponse.getResult().equals("error")) { throw new ExchangeException("Error calling placeLimitOrder(): " + mtGoxGenericResponse.getError()); } else { throw new ExchangeException("Error calling placeLimitOrder(): Unexpected result!"); } } catch (MtGoxException e) { throw new ExchangeException("Error calling placeLimitOrder(): " + e.getError()); } }