Skip to content
All library documents

Market-by-Price and Order-by-Order Limit Order Books

Article Quant Q&A · Author: xyzt

Summary

The document distinguishes market-by-order (MBO) data from market-by-price (MBP) data. MBO records individual orders, while MBP aggregates displayed quantities by price. Exchanges maintain order-level books internally, but traders build the representation supported by their market-data feed or vendor; the distinction is therefore about available data granularity rather than whether an asset is an equity or future.

For an MBP book, the example stores bid and ask quantities in price-ordered maps. An update replaces the size at a price, and a zero size removes that level. Integer price ticks support precise price keys, while ordered maps make it straightforward to find the best quote and inspect deeper levels. The author describes this structure as simple and fast, but gives no benchmark methodology. MBO management is said to be somewhat more involved, with no implementation details in the excerpt.

Key ideas

  • MBO represents individual orders, whereas MBP aggregates orders at each price level.
  • The market-data feed determines which book representation a consumer can construct.
  • An MBP update replaces a price level's size or removes the level when its size reaches zero.
  • Integer tick prices and ordered maps support best-price lookup and traversal through deeper levels.

Tags

Full text
# Building Limit OrderBooks methods (order-based) or (level-based)


# Building Limit OrderBooks methods (order-based) or (level-based)












I'm trying to implement a code to build limit order books. While doing some research I have seen two methods mainly, order-based for equities and level-based for futures. I could not understand why there are two methods. Why doesn't level-based methods fit for equities? or vice versa... Thanks

## Answer by Serg (score 3)

https://quant.stackexchange.com/a/54732

The only true order book is the order book which consists of orders, i.e. order-by-order or market-by-order (MBO) full-depth order book. It's the order book managed internally by absolutely all exchanges (stocks, futures, crypto/digital, etc). The market-by-price (MBP) is an aggregated view of the order book. You manage the type of order book, corresponding to the type of market data provided by the exchange, and depending on type of data delivered to you by your data vendor. For instance, CME futures exchange does provide MBO data and it can be used undamaged on retail trading platforms, for instance, with Bookmap

Managing a market-by-price order book is trivial:

```
public class OrderBookMarketByPrice {

    public final TreeMap<Integer, Integer> asks = new TreeMap<>((a, b) -> a - b);
    public final TreeMap<Integer, Integer> bids = new TreeMap<>((a, b) -> b - a);

    @Override
    public void quote(long t, boolean isBuy, int price, int size) {
        TreeMap<Integer, Integer> queue = (isBuy ? bids : asks);
        @SuppressWarnings("unused")
        Integer prevSize = size == 0 ? queue.remove(price) : queue.put(price, size); 
    }
}
```

This can easily process 10+ million updates per second on a regular laptop. Here, you delete the price level if its size is zero. The price is an integer because it represents the number of minimum price increments. The two TreeMap objects allow navigating from the best bid or best ask and deeper into each side. Managing an order-by-order order book is just slightly more complex

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.