/** * Given a new LimitOrder, it will replace a matching limit order in the orderbook if one is * found, or add the new LimitOrder if one is not. timeStamp will be updated if the new timestamp * is non-null and in the future. * * @param limitOrder the new LimitOrder */ public void update(LimitOrder limitOrder) { update(getOrders(limitOrder.getType()), limitOrder); updateDate(limitOrder.getTimestamp()); }
/** * Given an OrderBookUpdate, it will replace a matching limit order in the orderbook if one is * found, or add a new if one is not. timeStamp will be updated if the new timestamp is non-null * and in the future. * * @param orderBookUpdate the new OrderBookUpdate */ public void update(OrderBookUpdate orderBookUpdate) { LimitOrder limitOrder = orderBookUpdate.getLimitOrder(); List<LimitOrder> limitOrders = getOrders(limitOrder.getType()); int idx = Collections.binarySearch(limitOrders, limitOrder); if (idx >= 0) { limitOrders.remove(idx); } else { idx = -idx - 1; } if (orderBookUpdate.getTotalVolume().compareTo(BigDecimal.ZERO) != 0) { LimitOrder updatedOrder = withAmount(limitOrder, orderBookUpdate.getTotalVolume()); limitOrders.add(idx, updatedOrder); } updateDate(limitOrder.getTimestamp()); }
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); }
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())); }
@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); }
/** * Given a new LimitOrder, it will replace a matching limit order in the orderbook if one is * found, or add the new LimitOrder if one is not. timeStamp will be updated if the new timestamp * is non-null and in the future. * * @param limitOrder the new LimitOrder */ public void update(LimitOrder limitOrder) { update(getOrders(limitOrder.getType()), limitOrder); updateDate(limitOrder.getTimestamp()); }
/** * Given an OrderBookUpdate, it will replace a matching limit order in the orderbook if one is * found, or add a new if one is not. timeStamp will be updated if the new timestamp is non-null * and in the future. * * @param orderBookUpdate the new OrderBookUpdate */ public void update(OrderBookUpdate orderBookUpdate) { LimitOrder limitOrder = orderBookUpdate.getLimitOrder(); List<LimitOrder> limitOrders = getOrders(limitOrder.getType()); int idx = Collections.binarySearch(limitOrders, limitOrder); if (idx >= 0) { limitOrders.remove(idx); } else { idx = -idx - 1; } if (orderBookUpdate.getTotalVolume().compareTo(BigDecimal.ZERO) != 0) { LimitOrder updatedOrder = withAmount(limitOrder, orderBookUpdate.getTotalVolume()); limitOrders.add(idx, updatedOrder); } updateDate(limitOrder.getTimestamp()); }
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); }
bid.getCurrencyPair(), bid.getLimitPrice(), bid.getTimestamp(), bid.getTradableAmount().subtract(tradeAmount) ); ask.getCurrencyPair(), ask.getLimitPrice(), ask.getTimestamp(), ask.getTradableAmount().subtract(tradeAmount) );
limitOrder.getCurrencyPair(), limitOrder.getLimitPrice(), limitOrder.getTimestamp(), BigDecimal.ZERO); this.orderBook.update(orderBookUpdate); break;