Skip to content

A simple multithreaded matching engine to handle LIMIT orders.

Notifications You must be signed in to change notification settings

nadSTC/pub_matching_engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Matching Engine

A simple matching engine built in C++.

Features

✅ FIFO algorithm
✅ Multi-threaded
✅ LIMIT order support
✅ Stores order fills
✅ Wash trading protection

Installation

  1. Get the code on your local machine.
  2. Compile: g++ -std=c++17 -stdlib=libc++ -o matching_engine matching_engine.cpp.
  3. Run: ./matching_engine

Usage

Account

  • 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>
    

Order

  • create

    This command creates and order for the account specified.

    • account_name must exist.
    • quantity must be an int.
    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>
    

Transactions

Enter the command transactions <num_transactions> to display the latest <num_transactions> that were settled by the matching engine.

  Enter Command: transactions 10

State

Enter the command state to display all accounts and their holdings as well as the state of the order book.

  Enter Command: state

Exit

Enter the command exit to close all threads and exit elegantly.

  Enter Command: exit

Disclaimer

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.

About

A simple multithreaded matching engine to handle LIMIT orders.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages