@Test public void bbo() { market.add(INSTRUMENT, 1, Side.BUY, 999, 100); market.add(INSTRUMENT, 2, Side.SELL, 1001, 200); assertEquals(asList(new Level(999, 100, 1001, 200)), levels(book)); Event updateAfterBid = new Update(INSTRUMENT, true); Event updateAfterAsk = new Update(INSTRUMENT, true); assertEquals(asList(updateAfterBid, updateAfterAsk), events.collect()); }
public void add(long instrument, long orderId, Side side, long price, long size) { if (orders.containsKey(orderId)) return; OrderBook book = books.get(instrument); if (book == null) return; Order order = new Order(book, side, price, size); boolean bbo = book.add(side, price, size); orders.put(orderId, order); listener.update(book, bbo); }
Market { public void add(long instrument, long orderId, Side side, long price, long size) { if (orders.containsKey(orderId)) return; OrderBook book = books.get(instrument); if (book == null) return; Order order = new Order(book, side, price, size); boolean bbo = book.add(side, price, size); orders.put(orderId, order); listener.update(book, bbo); } }
Market { public void add(long instrument, long orderId, Side side, long price, long size) { if (orders.containsKey(orderId)) return; OrderBook book = books.get(instrument); if (book == null) return; Order order = new Order(book, side, price, size); boolean bbo = book.add(side, price, size); orders.put(orderId, order); listener.update(book, bbo); } Market(MarketListener listener); }
Market { public void add(long instrument, long orderId, Side side, long price, long size) { if (orders.containsKey(orderId)) return; OrderBook book = books.get(instrument); if (book == null) return; Order order = new Order(book, side, price, size); boolean bbo = book.add(side, price, size); orders.put(orderId, order); listener.update(book, bbo); } Market(MarketListener listener); OrderBook open(long instrument); Order find(long orderId); void add(long instrument, long orderId, Side side, long price, long size); void modify(long orderId, long size); long execute(long orderId, long quantity); long execute(long orderId, long quantity, long price); long cancel(long orderId, long quantity); void delete(long orderId); }
Market { public void add(long instrument, long orderId, Side side, long price, long size) { if (orders.containsKey(orderId)) return; OrderBook book = books.get(instrument); if (book == null) return; Order order = new Order(book, side, price, size); boolean bbo = book.add(side, price, size); orders.put(orderId, order); listener.update(book, bbo); } Market(MarketListener listener); OrderBook open(long instrument); Order find(long orderId); void add(long instrument, long orderId, Side side, long price, long size); void modify(long orderId, long size); long execute(long orderId, long quantity); long execute(long orderId, long quantity, long price); long cancel(long orderId, long quantity); void delete(long orderId);  }