public static List<LimitOrder> adaptOrders( CurrencyPair currencyPair, Map<String, Object> orderBookData, Order.OrderType type) { List<LimitOrder> orders = new ArrayList<>(); for (List<String> orderData : (List<List<String>>) orderBookData.get(type.equals(Order.OrderType.ASK) ? "ask" : "bid")) { BigDecimal price = new BigDecimal(orderData.get(0)); BigDecimal quantity = new BigDecimal(orderData.get(1)); orders.add(new LimitOrder(type, quantity, currencyPair, null, null, price)); } return orders; }
public String submitTrade( CurrencyPair currencyPair, LimitOrder.OrderType type, BigDecimal price, BigDecimal amount) throws IOException { String rawType = type.equals(Order.OrderType.BID) ? "Buy" : "Sell"; CryptopiaBaseResponse<Map> response = cryptopia.submitTrade( signatureCreator, new Cryptopia.SubmitTradeRequest(currencyPair.toString(), rawType, price, amount)); List<Integer> filled = (List<Integer>) response.getData().get("FilledOrders"); if (filled.isEmpty()) { return response.getData().get("OrderId").toString(); } else { // if it fills instantly we don't get an orderId, so instead we return the 1st fillId... far // from perfect because there could be many return filled.get(0).toString(); } }
@Override public String placeMarketOrder(MarketOrder marketOrder) throws IOException { String marketOrderType = null; String price = null; String amount = null; long orderId = -1L; String symbol = OkCoinAdapters.adaptSymbol(marketOrder.getCurrencyPair()); if (marketOrder.getType().equals(OrderType.BID)) { marketOrderType = "buy_market"; price = marketOrder.getOriginalAmount().toPlainString(); orderId = placeMarketOrderBuy(symbol, marketOrderType, price).getOrderId(); } else { marketOrderType = "sell_market"; amount = marketOrder.getOriginalAmount().toPlainString(); orderId = placeMarketOrderSell(symbol, marketOrderType, amount).getOrderId(); } return String.valueOf(orderId); }
public String placeBittrexLimitOrder(LimitOrder limitOrder) throws IOException { return (OrderType.BID.equals(limitOrder.getType()) ? bittrexAuthenticated.buylimit( apiKey, signatureCreator, exchange.getNonceFactory(), BittrexUtils.toPairString(limitOrder.getCurrencyPair()), limitOrder.getOriginalAmount().toPlainString(), limitOrder.getLimitPrice().toPlainString()) : bittrexAuthenticated.selllimit( apiKey, signatureCreator, exchange.getNonceFactory(), BittrexUtils.toPairString(limitOrder.getCurrencyPair()), limitOrder.getOriginalAmount().toPlainString(), limitOrder.getLimitPrice().toPlainString())) .getResult() .getUuid(); }
public String makeMarketOrder(MarketOrder order) throws IOException { LivecoinOrderResponse response; if (order.getType().equals(Order.OrderType.BID)) { response = service.buyWithMarketOrder( apiKey, signatureCreator, order.getCurrencyPair().toString(), order.getOriginalAmount()); } else { response = service.sellWithMarketOrder( apiKey, signatureCreator, order.getCurrencyPair().toString(), order.getOriginalAmount()); } return response.getOrderId(); }
@Override public String placeLimitOrder(LimitOrder limitOrder) throws IOException { // Validation Assert.notNull(limitOrder.getLimitPrice(), "getLimitPrice() cannot be null"); Assert.notNull(limitOrder.getOriginalAmount(), "getOriginalAmount() cannot be null"); if (limitOrder.getOriginalAmount().scale() > 8) { throw new IllegalArgumentException("originalAmount scale exceeds max"); } if (limitOrder.getLimitPrice().scale() > ANXUtils.getMaxPriceScale(limitOrder.getCurrencyPair())) { throw new IllegalArgumentException("price scale exceeds max"); } String type = limitOrder.getType().equals(OrderType.BID) ? "bid" : "ask"; BigDecimal amount = limitOrder.getOriginalAmount(); BigDecimal price = limitOrder.getLimitPrice(); return placeANXLimitOrder(limitOrder.getCurrencyPair(), type, amount, price).getDataString(); }
public BaseYoBitResponse trade(LimitOrder limitOrder) throws IOException { String market = YoBitAdapters.adaptCcyPairToUrlFormat(limitOrder.getCurrencyPair()); String direction = limitOrder.getType().equals(Order.OrderType.BID) ? "buy" : "sell"; BaseYoBitResponse response = service.trade( exchange.getExchangeSpecification().getApiKey(), signatureCreator, "Trade", exchange.getNonceFactory(), market, direction, limitOrder.getLimitPrice(), limitOrder.getOriginalAmount()); if (!response.success) throw new ExchangeException("failed to get place order"); return response; }
@Override public String placeLimitOrder(LimitOrder order) throws IOException { try { CoingiPlaceLimitOrderRequest request = new CoingiPlaceLimitOrderRequest() .setCurrencyPair(CoingiAdapters.adaptCurrency(order.getCurrencyPair())) .setOrderType(order.getType().equals(BID) ? 0 : 1) .setPrice(order.getLimitPrice()) .setVolume(order.getRemainingAmount()); return placeCoingiLimitOrder(request).getResult(); } catch (CoingiException e) { throw CoingiErrorAdapter.adapt(e); } }
@Override public String placeLimitOrder(LimitOrder order) throws IOException, CryptonitException { CryptonitAuthenticatedV2.Side side = order.getType().equals(BID) ? CryptonitAuthenticatedV2.Side.buy : CryptonitAuthenticatedV2.Side.sell; CryptonitOrder CryptonitOrder = placeCryptonitOrder( order.getCurrencyPair(), side, order.getOriginalAmount(), order.getLimitPrice()); if (CryptonitOrder.getErrorMessage() != null) { throw new ExchangeException(CryptonitOrder.getErrorMessage()); } return Integer.toString(CryptonitOrder.getId()); }
@Override public String placeLimitOrder(LimitOrder order) throws IOException, BitstampException { BitstampAuthenticatedV2.Side side = order.getType().equals(BID) ? BitstampAuthenticatedV2.Side.buy : BitstampAuthenticatedV2.Side.sell; BitstampOrder bitstampOrder = placeBitstampOrder( order.getCurrencyPair(), side, order.getOriginalAmount(), order.getLimitPrice()); if (bitstampOrder.getErrorMessage() != null) { throw new ExchangeException(bitstampOrder.getErrorMessage()); } return Long.toString(bitstampOrder.getId()); }
public static BTCTurkOrderTypes adaptOrderType(OrderType type) { return type.equals(OrderType.ASK) ? BTCTurkOrderTypes.Buy : BTCTurkOrderTypes.Sell; }
public static String convertByType(OrderType orderType) { return OrderType.BID.equals(orderType) ? IConstants.BUY : IConstants.SELL; } }
@Override public String placeMarketOrder(MarketOrder order) throws IOException, CryptonitException { CryptonitAuthenticatedV2.Side side = order.getType().equals(BID) ? CryptonitAuthenticatedV2.Side.buy : CryptonitAuthenticatedV2.Side.sell; CryptonitOrder CryptonitOrder = placeCryptonitMarketOrder(order.getCurrencyPair(), side, order.getOriginalAmount()); if (CryptonitOrder.getErrorMessage() != null) { throw new ExchangeException(CryptonitOrder.getErrorMessage()); } return Integer.toString(CryptonitOrder.getId()); }
public CoinoneTradeResponse placeLimitOrderRaw(LimitOrder limitOrder) throws CoinoneException, IOException { CoinoneTradeRequest request = new CoinoneTradeRequest( apiKey, exchange.getNonceFactory().createValue(), limitOrder.getLimitPrice(), limitOrder.getOriginalAmount(), limitOrder.getCurrencyPair().base); if (limitOrder.getType().equals(OrderType.ASK)) { return coinone.limitSell(payloadCreator, signatureCreator, request); } else { return coinone.limitBuy(payloadCreator, signatureCreator, request); } }
public UpbitOrderResponse limitOrder(LimitOrder limitOrder) throws IOException { UpbitOrderRequest upbitOrderRequest = new UpbitOrderRequest(); String marketId = limitOrder.getCurrencyPair().counter + "-" + limitOrder.getCurrencyPair().base; upbitOrderRequest.setMarketId(marketId); upbitOrderRequest.setOrderType(limitOrder.getType().name().toLowerCase()); upbitOrderRequest.setVolume(limitOrder.getOriginalAmount().toString()); upbitOrderRequest.setPrice(limitOrder.getLimitPrice().toString()); upbitOrderRequest.setSide(limitOrder.getType().equals(Order.OrderType.ASK) ? "ask" : "bid"); upbitOrderRequest.setOrderType("limit"); return upbit.limitOrder(this.signatureCreator, upbitOrderRequest); }
@Override public String placeMarketOrder(MarketOrder marketOrder) throws ExchangeException, IOException { final CoinbaseTransfer transfer = marketOrder.getType().equals(OrderType.BID) ? super.buy(marketOrder.getOriginalAmount()) : super.sell(marketOrder.getOriginalAmount()); return transfer.getId(); }
@Override public String placeLimitOrder(LimitOrder limitOrder) throws IOException { String type = limitOrder.getType().equals(Order.OrderType.BID) ? "buy" : "sell"; return placeOrder( type, limitOrder.getLimitPrice(), limitOrder.getCurrencyPair(), limitOrder.getOriginalAmount()); }
@Override public String placeMarketOrder(MarketOrder marketOrder) throws IOException { String type = marketOrder.getType().equals(Order.OrderType.BID) ? "market_buy" : "market_sell"; return placeOrder( type, BigDecimal.ZERO, marketOrder.getCurrencyPair(), marketOrder.getOriginalAmount()); }
@Override public String placeMarketOrder(MarketOrder order) throws IOException, BitstampException { BitstampAuthenticatedV2.Side side = order.getType().equals(BID) ? BitstampAuthenticatedV2.Side.buy : BitstampAuthenticatedV2.Side.sell; BitstampOrder bitstampOrder = placeBitstampMarketOrder(order.getCurrencyPair(), side, order.getOriginalAmount()); if (bitstampOrder.getErrorMessage() != null) { throw new ExchangeException(bitstampOrder.getErrorMessage()); } return Long.toString(bitstampOrder.getId()); }