Assume a class LimitOrderBook which represents a limit order book in a trading system.

To be able to represent the limit order book a data handler reads a feed which adds data to the representation of the limit order book using the following three methods:

  • public OrderReference add(Order order)
  • public boolean cancel(OrderReference orderReference)
  • public void execute(...)

These three methods alter the state of the limit order book. These three are more or less given, they're all needed to implement the LOB representation.

In addition to those three required "state altering" methods a typical LOB representation also provides a number of query methods that the trading models can call. One obvious example of such a method would be getBestBid(...).

What are the most important query methods a general LOB should provide? Or more specifically, in the LOB's you've built, what query methods did you include? Why?


1 Answer 1


There is no need to complicate things:

d = getBdepth();
d = getOdepth();
// for the calls below pos == 0 means the best bid/offer
p = getB(int pos); // bid price at pos
p = getO(int pos); // offer price at pos
q = getBq(int pos); // bid quantity at pos
q = getOq(int pos);// offer quantity at pos

Note that the above API is not the best choice if your LimitOrderBook instance is updated in background. But as long as you update its state within the same thread that does strategy calculations you're safe. In case of asynchronous updates things complicate a bit - you'll need two classes. The first one will have all the methods you describe plus one for getting a static snapshot of the order book at current time:

public LimitOrderBookSnapshot getSnapshot();

The LimitOrderBookSnapshot instance is made by synchronously copying data that underlie your LimitOrderBook instance. LimitOrderBookSnapshot API is made of the six calls I described at the top of this post.

Also note that in real solution you need to remember the time of getting a snapshot - if you won't you may end up using quotes that were not available at the moment of obtaining the order book data.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.