/** * 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()); }
public static String hasErrors(OrderBook book) { List<LimitOrder> asks = book.getOrders(Order.OrderType.ASK); if (!Objects.equals(asks, book.getAsks())) return "Asks did not match for OrderBook"; List<LimitOrder> bids = book.getOrders(Order.OrderType.BID); if (!Objects.equals(bids, book.getBids())) return "Bids did not match for OrderBook"; LimitOrder bestAsk = null; if (!asks.isEmpty()) { bestAsk = asks.get(0); String askCheck = hasErrors(asks.iterator()); if (askCheck != null) return askCheck; } LimitOrder bestBid = null; if (!bids.isEmpty()) { bestBid = bids.get(0); String bidCheck = hasErrors(CollectionUtils.descendingIterable(bids).iterator()); if (bidCheck != null) return bidCheck; } if (bestAsk != null && bestBid != null && bestAsk.getLimitPrice().compareTo(bestBid.getLimitPrice()) <= 0) return format("Got incorrect best ask and bid %s, %s", bestAsk, bestBid); return null; }
/** * 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()); }