OrderBook DB Design

Python's OrderedDict can serve as a foundation for a scalable OrderBook. You would want one ordered dictionary for each price-level so that orders will match according to price/time priority.


  • we have to be careful and execute only in the order in which the orders were received

Market data is usually modeled in a time series fashion, hence it is naturally ordered by a timestamp which goes up to as far as a picosecond precision at the moment.

Depending on what tech you rely on, if you don't mind to pay for it, I would go with OneTick, that is a time series DB that already has a built in order book with a book depth / price levels, CEP and much more.

In case you'd like to build it yourself ( or rely on free products ), take a look at OpenTSDB which is an open source, time series DB with a LGPLv3+ license. It'd be slower than OneTick of course, but since you just need thousands (OneTick handles billions) depending on your speed requirements it may work.

As to the OrderBook data model it would depend on how exactly are you going to use the book: e.g. do you care about multiple price levels? Top of the book? Do you need to match bids/asks to the actual orders, etc..

But you can start with designing a schema that would record OrderBook events such as:

enter image description here

The example is from LMAX Protocol Reference Guide

Tags:

Finance

Orders