enewhuis / liquibook

Modern C++ order matching engine
Other
1.14k stars 375 forks source link

Liquibook

Open source order matching engine

Liquibook provides the low-level components that make up an order matching engine.

Order matching is the process of accepting buy and sell orders for a security (or other fungible asset) and matching them to allow trading between parties who are otherwise unknown to each other.

An order matching engine is the heart of every financial exchange, and may be used in many other circumstances including trading non-financial assets, serving as a test-bed for trading algorithms, etc.

A typical Liquibook-based application might look something like this: Market Application

In addition to the order matching process itself, Liquibook can be configured to maintain an "depth book" that records the number of open orders and total quantity represented by those orders at individual price levels.

Example of an depth book

Order properties supported by Liquibook.

Liquibook is aware of the following order properties.

The only required properties are side, quantity and price. Default values are available for the other properties.

The application can define addtional properties on the order object as necessary. These properties will have no impact on the behavior of Liquibook.

Operations on Orders

In addition to submitting orders, traders may also submit requests to cancel or modify existing orders. (Modify is also know as cancel/replace) The requests may succeed or fail depending on previous trades executed against the order.

Notifications returned to the application.

Liquibook will notify the application when significant events occur to allow the application to actually execute the trades identified by Liquibook, and to allow the application to publish market data for use by traders.

The notifications generated include:

Performance

As always, the results of this type of performance test can vary depending on the hardware and operating system on which you run the test, so use these numbers as a rough order-of-magnitude estimate of the type of performance your application can expect from Liquibook.

Works with Your Design

Example

This repository contains two complete example programs. These programs can be used to evaluate Liquibook to see if it meets your needs. They can also be used as models for your application or even incorporated directly into your application thanks to the liberal license under which Liquibook is distributed.

The examples are:

Building Liquibook

The good news is you don't need to build Liquibook. The core of Liquibook is a header-only library, so you can simply add Liquibook/src to your include path then #include <book/order_book.h> to your source, and Liquibook will be available to be used in your application.

However, this repository includes tests and example programs for Liquibook. These programs need to be compiled and built in order to run them. The remainder of this section describes how to do this.

Dependencies

Liquibook has no runtime dependencies. It will run in any environment that can run C++ programs.

To build the Liquibook test and example programs from source you need to create makefiles (for linux, et al.) or Project and Solution files for Windows Visual Studio.

Liquibook uses MPC to create these platform-dependent files from a common build definition:

If you wish to build the unit tests for Liquibook, you will also need the boost test library:

One of the example programs (publish and subscribe to market data) uses QuickFAST to encode and decode market data messages. If you wish to run this example you need QuickFAST:

Submodule Note

The Assertive test framework was used in previous versions, but it is no longer needed.
If you have imported this submodule to support previous versions, you may delete the liquibook/test/unit/assertiv directory.

Getting ready to build the tests and example programs.

Boost Test

If you want to run the Liquibook unit tests (highly recommended!) you should install and/or build boost test before trying to build Liquibook. Boost test is used in the multifile-test mode rather than simple header-only mode so the compiled boost test library must be available.

Please follow the instructions on the boost web site for building/installing the library in your environment. When you are done you should export the $BOOST_ROOT environment varialble.

Because of the many boost build options, please check to be sure that the include files and library files are in the expected locations. MPC expects to find:

If you prefer not to install boost you can edit the liquibook.features file to change the appropriate line to say boost=0 This will disable building the unit tests.

QuickFAST

The publish and subscribe example program uses QuickFAST. If you want to run this example program, please see the QuickFAST web site to download and build this library.

Set the environment variable $QUICKFAST_ROOT to point to the location where you installed and build QuickFAST.

Before running MPC you should also edit the file liquibook.features to set the value QuickFAST=1

If you do not plan to run this example program, set the environment variable QUICKFAST_ROOT to liquibook/noQuickFAST.

Building Liquibook on Linux

The env.sh script uses the readlink program which is present on most Linux/Unix systems. If you don't have readlink, set the $LIQUIBOOK_ROOT environment variable the directory containing liquibook before running env.sh

Open a shell and type:

$ cd liquibook
$ . ./env.sh
$ $MPC_ROOT/mwc.pl -type make liquibook.mwc
$ make depend
$ make all

Output from build

Building Liquibook examples and test programs with Visual Studio

Use the following commands to set up the build environment and create Visual Studio project and solution files. Note if you are using MinGW or other linux-on-Windows techniques, follow the Linux instructions; however, OCI does not normally test this.

> cd liquibook
> copy winenv.bat w.bat #optional if you want to keep the original
                        # note that single character batch file names are ignored in 
                        # .getignore so the customized
                        # file will not be checked into the git repository (a good thing.)
> edit w.bat            # edit is your choice of text editor
                        # follow the instructions in the file itself.
> w.bat                 # sets and verifies environment variables
> mpc.bat               # generate the visual studio solution and project files.

Then:

For any platform

Liquibook should work on any platform with a modern C++ compiler (supporting at least C++11.)

The MPC program used to create the build files and the Boost library used in the tests and some of the examples support a wide variety of platforms.

See the MPC documentation for details about using MPC in your enviornment.

See the Boost website for details about using Boost in your environment.