C++17 HFT risk calculation system. No third-party dependencies needed.
This is only a weekend project I did in 2020. It is probably completely useless in actual trading.
- TCP server and client.
- Message serialization.
- Risk server capable of handling messages over TCP.
- Risk client capable of sending messages to the risk server over TCP.
- Trade state stored in hash tables (
std::unordered_map
). - Rather than computing three net sums over all existing orders each time the net position is requested, the sums are updated into
InstrumentState
for each instrument each time the state of the server changes.
- Message protocol
struct
s are not packed. It was easier to test the system this way. Encoding and decoding of packedstruct
s can be implemented later as an optimization to minimize network bandwidth usage.
Please see server.log
and client.log
for example program output.
mkdir build
cd build
cmake ..
make -j8
Start the risk server, serving at 127.0.0.1:7001
with max buy position 20 and max sell position 15:
./bin/risk-server 127.0.0.1 7001 20 15
In a second terminal, send some messages with the client to the server at 127.0.0.1:7001
by running:
./bin/test 127.0.0.1 7001
Verify that your output matches client.log
for the client and server.log
for the server.
- Debian 10 (buster)
- CMake 3.13.4
- clang 7.0.1-8.
- Apple M1, Big Sur 11.4
- CMake 3.20.3
- clang 12.0.5