• Stars
    star
    754
  • Rank 60,205 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created over 7 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

High performance components for building Trading Platform such as ultra fast matching engine, order book processor

CppTrader

Linux (clang) Linux (gcc)
MacOS
Windows (Cygwin) Windows (MSYS2) Windows (MinGW) Windows (Visual Studio)

C++ Trader is a set of components for building high performance Trading Platform:

  • Ultra fast matching engine
  • Order book processor
  • NASDAQ ITCH handler

CppTrader API reference

Contents

Features

  • Cross platform (Linux, MacOS, Windows)
  • Benchmarks
  • Examples
  • Tests
  • Doxygen API documentation
  • Continuous integration (Travis CI, AppVeyor)

Requirements

Optional:

How to build?

Linux: install required packages

sudo apt-get install -y binutils-dev uuid-dev

Install gil (git links) tool

pip3 install gil

Setup repository

git clone https://github.com/chronoxor/CppTrader.git
cd CppTrader
gil update

Linux

cd build
./unix.sh

MacOS

cd build
./unix.sh

Windows (Cygwin)

cd build
unix.bat

Windows (MSYS2)

cd build
unix.bat

Windows (MinGW)

cd build
mingw.bat

Windows (Visual Studio)

cd build
vs.bat

Performance

Here comes several micro-benchmarks for trading components.

Benchmark environment is the following:

CPU architecutre: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
CPU logical cores: 8
CPU physical cores: 4
CPU clock speed: 3.998 GHz
CPU Hyper-Threading: enabled
RAM total: 31.962 GiB
RAM free: 21.623 GiB

OS version: Microsoft Windows 8 Enterprise Edition (build 9200), 64-bit
OS bits: 64-bit
Process bits: 64-bit
Process configuaraion: release

NASDAQ ITCH handler

Benchmark measures the performance of the NASDAQ ITCH handler. It shows how fast it can parse and handle ITCH messages from the input stream.

Sample ITCH file could be downloaded from ftp://emi.nasdaq.com/ITCH

ITCH processing...Done!

Errors: 0

Processing time: 6.831 s
Total ITCH messages: 283238832
ITCH message latency: 24 ns
ITCH message throughput: 41460256 msg/s

Market manager

Benchmark measures the performance of the Market manager. It shows how fast it can handle orders operations (add, reduce, modify, delete, execute) and build an order book.

Sample ITCH file could be downloaded from ftp://emi.nasdaq.com/ITCH

ITCH processing...Done!

Errors: 0

Processing time: 1:27.616 m
Total ITCH messages: 283238832
ITCH message latency: 309 ns
ITCH message throughput: 3232727 msg/s
Total market updates: 631217516
Market update latency: 138 ns
Market update throughput: 7204359 upd/s

Market statistics:
Max symbols: 8371
Max order books: 8371
Max order book levels: 2422
Max order book orders: 2975
Max orders: 1647972

Order statistics:
Add order operations: 152865456
Update order operations: 7037619
Delete order operations: 152865456
Execute order operations: 5663712

Market manager (optimized version)

This is an optimized version of the Market manager. Optimization tricks are the following:

  • Symbols and order books are stored in fixed size pre-allocated arrays.
  • Orders are stored in the pre-allocated array instead of HashMap. This gives O(1) for all orders operations with no overhead (get, insert, update, delete).
  • Orders linked list is not maintained for price levels, just orders count.
  • Price levels are stored in sorted arrays instead of Red-Black trees. The sort order keeps best prices (best bid / best ask) at the end of arrays which gives good CPU cache locality and near to O(1) search time for orders with close to market prices, but has a penalty for orders with far from market prices!
  • Price levels are taken from the pool, which is implemented using a pre-allocated array with O(1) for create and delete each price level.

Sample ITCH file could be downloaded from ftp://emi.nasdaq.com/ITCH

ITCH processing...Done!

Errors: 0

Processing time: 34.150 s
Total ITCH messages: 283238832
ITCH message latency: 120 ns
ITCH message throughput: 8293747 msg/s
Total market updates: 631217516
Market update latency: 54 ns
Market update throughput: 18483195 upd/s

Market statistics:
Max symbols: 8371
Max order books: 8371
Max order book levels: 38
Max orders: 1647972

Order statistics:
Add order operations: 152865456
Update order operations: 7037619
Delete order operations: 152865456
Execute order operations: 5663712

Market manager (aggressive optimized version)

This is a very aggressive optimized version of the Market manager. It shows values of latency and throughput close to optimal with the cost of some more optimization tricks which might be hard to keep in real trading platforms:

  • Symbols are not maintained
  • Orders and price limits structures are optimized to be optimal. Most of useful filds are removed.
  • Price values are stored as signed 32-bit integer values. Positive values for bids and negative values for asks.
  • Market handler is not used. No way to receive notifications from the Market manager.

Sample ITCH file could be downloaded from ftp://emi.nasdaq.com/ITCH

ITCH processing...Done!

Errors: 0
Processing time: 29.047 s
Total ITCH messages: 283238832
ITCH messages latency: 102 ns
ITCH messages throughput: 9751044 msg/s

More Repositories

1

NetCoreServer

Ultra fast and low latency asynchronous socket server & client C# .NET Core library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
C#
2,490
star
2

CppServer

Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
C++
1,334
star
3

FastBinaryEncoding

Fast Binary Encoding is ultra fast and universal serialization solution for C++, C#, Go, Java, JavaScript, Kotlin, Python, Ruby, Swift
C++
820
star
4

CppCommon

Cross-platform C++ common library for Linux, OSX, Windows, Cygwin, MinGW
C++
286
star
5

CppBenchmark

Performance benchmark framework for C++ with nanoseconds measure precision
C++
258
star
6

CppLogging

Ultra fast and low latency C++ Logging library with flexible configuration and high throughput in multithreaded environment
C++
150
star
7

CppSerialization

Performance comparison of the most popular C++ serialization protocols such as Cap'n'Proto, FastBinaryEncoding, Flatbuffers, Protobuf, JSON
C++
134
star
8

CSharpServer

Ultra fast and low latency asynchronous socket server & client C# library with support TCP, SSL, UDP protocols and 10K connections problem solution
C#
108
star
9

gil

Gil is a git links tool to manage complex recursive repositories dependencies with cross references and cycles
Python
63
star
10

CppTemplate

Cross-platform template C++ project configured to build for Linux (gcc/clang), MacOS, Windows (Cygwin, MinGW, MSYS2, Visual Studio) with GitHub Action continuous integration
C++
36
star
11

CppSecurity

C++ Security Library
C++
33
star
12

TrueTemplate

FAR Manager editor plugin for edit and compile source files
C++
15
star
13

CppBuildScripts

C++ Build Scripts
Batchfile
14
star
14

CppCMakeScripts

C++ CMake Scripts
CMake
13
star
15

Depth

Depth C++ library
C++
8
star
16

NDepth

Depth .NET library
C#
5
star
17

projects

Projects repository and local workspace update script
Shell
3
star
18

OpenSSL

OpenSSL 64-bit binaries for MinGW and Visual Studio
Roff
2
star