/** * 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()); }
/** * 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()); }