/** @see #makeMercadoBitcoinOrderId(org.knowm.xchange.currency.CurrencyPair, String) */ public static String makeMercadoBitcoinOrderId(LimitOrder limitOrder) { return makeMercadoBitcoinOrderId(limitOrder.getCurrencyPair(), limitOrder.getId()); }
@Override public Collection<Order> getOrder(String... orderIds) throws IOException { List<String> orderIdList = Arrays.asList(orderIds); OpenOrders openOrders = getOpenOrders(); List<Order> returnValue = openOrders .getOpenOrders() .stream() .filter(f -> orderIdList.contains(f.getId())) .collect(Collectors.toList()); returnValue.addAll( orderIdList .stream() .filter( f -> !returnValue.stream().filter(a -> a.getId().equals(f)).findFirst().isPresent()) .map( f -> { try { return PoloniexAdapters.adaptUserTradesToOrderStatus(f, returnOrderTrades(f)); } catch (IOException e) { LOG.error("Unable to find status for Poloniex order id: " + f, e); } return null; }) .filter(f -> f != null) .collect(Collectors.toList())); return returnValue; }
limitOrders .stream() .filter(order -> order.getId().equals(id)) .findAny() .ifPresent(limitOrder -> results.put(limitOrder, requestResults.get(id))));
String existingOrderId = openOrdersList.get(0).getId();
/** * Modify or cancel/replace an existing limit order * * @implNote Some exchanges have API methods that allow to modify an order or cancel an existing * one and create a new one in one request. * <p>Based on exchange API there are 3 ways, how this function works: * <ol> * <li>Exchange supports existing order modify operation. Then function returns {@code * limitOrder} order ID. * <li>Exchange supports order cancel/replace by one request. Then function returns new * order ID. * <li>Exchange doesn't support any of these operations. Then function performs * cancel/replace by two separate requests, and returns new order ID (default behavior) * </ol> * * @param limitOrder Order's data to change * @return Order ID * @throws ExchangeException Indication that the exchange reported some kind of error with the * request or response * @throws NotAvailableFromExchangeException Indication that the exchange does not support the * requested function or data * @throws NotYetImplementedForExchangeException Indication that the exchange supports the * requested function or data, but it has not yet been implemented * @throws IOException Indication that a networking error occurred while fetching JSON data */ default String changeOrder(LimitOrder limitOrder) throws IOException { cancelOrder(limitOrder.getId()); return placeLimitOrder(limitOrder); }
/** * Find and match an order with id in orders * * @param orders * @param order * @param id * @return */ public static boolean findLimitOrder(List<LimitOrder> orders, LimitOrder order, String id) { boolean found = false; for (LimitOrder openOrder : orders) { if (openOrder.getId().equalsIgnoreCase(id)) { if (order.getCurrencyPair().equals(openOrder.getCurrencyPair()) && (order.getOriginalAmount().compareTo(openOrder.getOriginalAmount()) == 0) && (order.getLimitPrice().compareTo(openOrder.getLimitPrice()) == 0)) { found = true; } } } return found; }
private static LimitOrder withAmount(LimitOrder limitOrder, BigDecimal tradeableAmount) { OrderType type = limitOrder.getType(); CurrencyPair currencyPair = limitOrder.getCurrencyPair(); String id = limitOrder.getId(); Date date = limitOrder.getTimestamp(); BigDecimal limit = limitOrder.getLimitPrice(); return new LimitOrder(type, tradeableAmount, currencyPair, id, date, limit); }
/** * Huobi currently doesn't have trade history API. We simulate it by using the orders history. * * @param order * @return */ private static UserTrade adaptTrade(LimitOrder order) { BigDecimal feeAmount = order .getCumulativeAmount() .multiply(order.getLimitPrice()) .multiply(fee) .setScale(8, RoundingMode.DOWN); return new UserTrade( order.getType(), order.getCumulativeAmount(), order.getCurrencyPair(), order.getLimitPrice(), order.getTimestamp(), null, // Trade id order.getId(), // Original order id feeAmount, order.getCurrencyPair().counter); }
@Override public String changeOrder(LimitOrder limitOrder) throws ExchangeException { BitmexPrivateOrder order = replaceOrder( new BitmexReplaceOrderParameters.Builder() .setClOrdId(limitOrder.getId()) .setOrderQuantity(limitOrder.getOriginalAmount()) .setPrice(limitOrder.getLimitPrice()) .build()); return order.getId(); }
@Override public String placeLimitOrder(LimitOrder limitOrder) throws ExchangeException { String symbol = BitmexAdapters.adaptCurrencyPairToSymbol(limitOrder.getCurrencyPair()); Builder b = new BitmexPlaceOrderParameters.Builder(symbol) .setOrderQuantity(limitOrder.getOriginalAmount()) .setPrice(limitOrder.getLimitPrice()) .setSide(fromOrderType(limitOrder.getType())) .setClOrdId(limitOrder.getId()); if (limitOrder.hasFlag(BitmexOrderFlags.POST)) { b.addExecutionInstruction(BitmexExecutionInstruction.PARTICIPATE_DO_NOT_INITIATE); } return placeOrder(b.build()).getId(); }
public BankeraOrder placeBankeraLimitOrder(LimitOrder limitOrder) throws IOException { try { BankeraExchange bankeraExchange = (BankeraExchange) exchange; String auth = "Bearer " + bankeraExchange.getToken().getAccessToken(); String market = getMarketNameFromPair(limitOrder.getCurrencyPair()); return bankeraAuthenticated.placeOrder( auth, new CreateOrderRequest( market, (limitOrder.getType() == Order.OrderType.BID ? CreateOrderRequest.Side.BUY.getSide() : CreateOrderRequest.Side.SELL.getSide()), limitOrder.getOriginalAmount(), limitOrder.getLimitPrice(), limitOrder.getId(), exchange.getNonceFactory().createValue())); } catch (BankeraException e) { throw BankeraAdapters.adaptError(e); } }
@Override public Collection<Order> getOrder(String... orderIds) throws IOException { List<String> orderIdList = Arrays.asList(orderIds); OpenOrders openOrders = getOpenOrders(); List<Order> returnValue = openOrders.getOpenOrders().stream() .filter(f -> orderIdList.contains(f.getId())) .collect(Collectors.toList()); returnValue.addAll( orderIdList.stream() .filter( f -> !returnValue.stream().filter(a -> a.getId().equals(f)).findFirst().isPresent()) .map( f -> { try { return PoloniexAdapters.adaptUserTradesToOrderStatus(f, returnOrderTrades(f)); } catch (IOException e) { LOG.error("Unable to find status for Poloniex order id: " + f, e); } return null; }) .filter(f -> f != null) .collect(Collectors.toList())); return returnValue; }
(id, result) -> limitOrders.stream() .filter(order -> order.getId().equals(id)) .findAny() .ifPresent(limitOrder -> results.put(limitOrder, requestResults.get(id))));
public void getOpenOrders() throws IOException { OpenOrders openOrders = tradeService.getOpenOrders(); log.info("open orders: {}", openOrders); openOrders.getOpenOrders().stream().forEach( o -> log.info("{} {} {} {} {}@{}", o.getCurrencyPair(), o.getId(), o.getTimestamp(), o.getType(), o.getTradableAmount(), o.getLimitPrice())); }
/** * Modify or cancel/replace an existing limit order * * @implNote Some exchanges have API methods that allow to modify an order or cancel an existing * one and create a new one in one request. * <p>Based on exchange API there are 3 ways, how this function works: * <ol> * <li>Exchange supports existing order modify operation. Then function returns {@code * limitOrder} order ID. * <li>Exchange supports order cancel/replace by one request. Then function returns new * order ID. * <li>Exchange doesn't support any of these operations. Then function performs * cancel/replace by two separate requests, and returns new order ID (default behavior) * </ol> * * @param limitOrder Order's data to change * @return Order ID * @throws ExchangeException Indication that the exchange reported some kind of error with the * request or response * @throws NotAvailableFromExchangeException Indication that the exchange does not support the * requested function or data * @throws NotYetImplementedForExchangeException Indication that the exchange supports the * requested function or data, but it has not yet been implemented * @throws IOException Indication that a networking error occurred while fetching JSON data */ default String changeOrder(LimitOrder limitOrder) throws IOException { cancelOrder(limitOrder.getId()); return placeLimitOrder(limitOrder); }
@Transient public boolean update(LimitOrder limitOrder) { try { this.setRemoteKey(limitOrder.getId()); this.setTimeReceived(new Instant(limitOrder.getTimestamp())); long vol = limitOrder.getOriginalAmount().divide(BigDecimal.valueOf(market.getPriceBasis())).longValue(); this.volume = new DiscreteAmount(vol, market.getPriceBasis()); this.volumeCount = new AtomicLong(volume.toBasis(market.getVolumeBasis(), Remainder.DISCARD).getCount()); this.unfilledVolumeCount = new AtomicLong(this.volumeCount.get()); return true; } catch (Error e) { e.printStackTrace(); return false; } // parentOrder.addChild(this); // this.setParentOrder(parentOrder); }
private static LimitOrder withAmount(LimitOrder limitOrder, BigDecimal tradeableAmount) { OrderType type = limitOrder.getType(); CurrencyPair currencyPair = limitOrder.getCurrencyPair(); String id = limitOrder.getId(); Date date = limitOrder.getTimestamp(); BigDecimal limit = limitOrder.getLimitPrice(); return new LimitOrder(type, tradeableAmount, currencyPair, id, date, limit); }
this.market = market.findOrCreate(exchange, listing); this.setRemoteKey(limitOrder.getId()); long vol = limitOrder.getOriginalAmount().divide(BigDecimal.valueOf(market.getPriceBasis())).longValue();
@Override public String changeOrder(LimitOrder limitOrder) throws ExchangeException { BitmexPrivateOrder order = replaceOrder( new BitmexReplaceOrderParameters.Builder() .setClOrdId(limitOrder.getId()) .setOrderQuantity(limitOrder.getOriginalAmount()) .setPrice(limitOrder.getLimitPrice()) .build()); return order.getId(); }
@Override public String placeLimitOrder(LimitOrder limitOrder) throws ExchangeException { String symbol = BitmexAdapters.adaptCurrencyPairToSymbol(limitOrder.getCurrencyPair()); Builder b = new BitmexPlaceOrderParameters.Builder(symbol) .setOrderQuantity(limitOrder.getOriginalAmount()) .setPrice(limitOrder.getLimitPrice()) .setSide(fromOrderType(limitOrder.getType())) .setClOrdId(limitOrder.getId()); if (limitOrder.hasFlag(BitmexOrderFlags.POST)) { b.addExecutionInstruction(BitmexExecutionInstruction.PARTICIPATE_DO_NOT_INITIATE); } return placeOrder(b.build()).getId(); }