/** * 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(); } }
public static String getAsString(Money money) { if (money == null) { return null; } return money.getAmount().toString() + " " + money.getCurrencyUnit().toString(); }
log.debug("BTC/"+from.getCurrencyUnit().toString()+" is "+oneDivFrom.toString()); log.debug("Last ticker Bid price was "+lastTickBidTo.toString()); log.debug("BTC/"+to.getCurrencyUnit().toString()+" is "+oneDivTo.toString()); 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()); } }