Take the 2-minute tour ×
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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