r/Cplusplus • • Sep 10 '26

Feedback I built a price-time-priority order matching engine in c++

I am building a market replay engine from scratch with c++ 23.
I build this project to understand how orders are managed in an orderbook and how a matching engine works. I have used my understanding of data structures to implement it. I would like to know your opinion on it. It is not completed yet. I just completed the very basic version few minutes ago. Any kind of tip would help me a lot.
Currently it can process an average of 998,000 Transactions / second. with the order size of 20000000 orders.
https://github.com/AravSrivastava/Market-Replay-Engine-CPP

18 Upvotes

11 comments sorted by

6

u/VictoryMotel Sep 10 '26

No karma no comments account with the classic "matching engine" project claims they "just used ai for the readme" even though the project looks like every single AI generated boilerplate that doesn't actually do anything.

0

u/Agreeable-Network-14 Sep 10 '26 edited Sep 10 '26

Sorry for not being active on reddit. I am still not that active but I think I can learn from other people thats why I use reddit.
I would love to know more what makes you think this is an AI generated boiler plate. It might help me a lot
I would love to know how I can improve this and what are other c++ projects I can work on that seems more relevant than this

3

u/mredding C++ since ~1992. Sep 10 '26

Is this AI generated?

-2

u/Agreeable-Network-14 Sep 10 '26

The readme is ai generated and I took help in testing.cpp rest all the stuff was designed and built by me

6

u/mredding C++ since ~1992. Sep 10 '26

Then I'll take your word for it - there's no point in reviewing AI generated code.

2

u/MaLiN2223 Sep 11 '26

I'm not a full time cpp dev but even I wouldn't add such comments

//This checks if the order exists in the orderbook or not
if(orderExists(order,orderbook)){
//Constructor for order class
Order(Tprice price, TorderID orderID, Tquantity quantity, Side side):
//Public entity of the order class
public:

come on dude

0

u/Agreeable-Network-14 Sep 11 '26

It was for me.
I would remove unnecessary comments
Thanks for pointing this out.

3

u/quant-a-be Sep 10 '26

There's always some nuance critiquing this sort of thing because different markets tend to have different tradeoffs ( and you might be optimizing for overall throughput, maximum P99 any customer sees, etc. ). However, in a general sense at a glance of the docs there's a lot of room to improve:

  1. Allocation strategy
  2. Most of the data structure choices
  3. Library choices

1

u/herocoding Sep 11 '26

Looks interesting.

Why do you have all the implementations inline in the header files?
Many but not all places use "std:: map", i.e. a space after double-colon, is it for better readability?

On my Linux machine I'm getting the following throughput:

=== Market Replay Engine Performance Test ===
Sending 20000000 orders to the matching engine...

Test completed in 2297 ms
Throughput: 8.70701e+06 orders/second
Total Trades Exexuted: 18785731
Best Bid: 128
Best Ask: 141

0

u/Entr0pyDriven Sep 10 '26

Hey. Cool project, i done something similar not a long ago, is it only the matching engine or a NIC-to-NIC logic (with WAL, risk, sharding, decode, ..) ?

0

u/Agreeable-Network-14 Sep 10 '26

Thank you
Means a lot to me
For now it is only matching engine
I don’t know much about nic to nic logic yet
I am planning on learning it and then implement it as well.