A simple matching engine built in C++.
✅ FIFO algorithm
✅ Multi-threaded
✅ LIMIT order support
✅ Stores order fills
✅ Wash trading protection
- Get the code on your local machine.
- Compile:
g++ -std=c++17 -stdlib=libc++ -o matching_engine matching_engine.cpp
. - Run:
./matching_engine
-
create
This command creates a new account of name
account_name
.Enter Command: account <account_name> create
-
delete
This command deletes an account of name
account_name
.Enter Command: account <account_name> delete
-
query
This command queries the wallet balances of an account of name
account_name
.Enter Command: account <account_name> query
-
transactions
This command displays the latest
<num_transactions>
transactions for the account specified.Enter Command: account <account_name> transactions <num_transactions>
-
fund
This command funds the account specified with
<amount>
in $USD.Enter Command: account <account_name> fund <funding_amount>
-
withdraw
This command mimics withdrawing funds of
<withdraw_amount>
from the wallet balance of the account specified.Enter Command: account <account_name> withdraw <withdraw_amount>
-
create
This command creates and order for the account specified.
account_name
must exist.quantity
must be anint
.
Enter Command: order <account_name> create <buy/sell> <quantity> <price>
-
cancel
This command cancels an order by
order_id
for the specified account.Enter Command: order <account_name> cancel <order_id>
Enter the command transactions <num_transactions>
to display the latest <num_transactions>
that were settled by the matching engine.
Enter Command: transactions 10
Enter the command state
to display all accounts and their holdings as well as the state of the order book.
Enter Command: state
Enter the command exit
to close all threads and exit elegantly.
Enter Command: exit
The code provided is for informational and educational purposes only and does not constitute financial advice. The code is provided as-is and without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. The author of this code will not be liable for any damages, whether direct, indirect, incidental, special, or consequential, arising from the use or distribution of this code, including but not limited to loss of profits, business interruption, or any other financial loss. By using or distributing this code, you agree to hold harmless the author and any affiliated parties from any and all claims, damages, or other liabilities arising from such use or distribution. It is the responsibility of the user to assess the risks associated with the use of this code and to seek independent professional advice before making any financial decisions based on the results generated by this code.