#fintech #simulation #market-simulator #exchange-simulator

bin+lib matching_engine

A matching engine that matches orders using FIFO or Prorata matching algoritm.Refer https://corporatefinanceinstitute.com/resources/career-map/sell-side/capital-markets/matching-orders/

9 releases

0.1.8 Oct 9, 2023
0.1.7 Oct 9, 2023

#69 in Finance

Download history 3/week @ 2024-02-21 3/week @ 2024-02-28 1/week @ 2024-03-06 4/week @ 2024-03-13 20/week @ 2024-03-27 39/week @ 2024-04-03

59 downloads per month

MIT/Apache

130KB
1.5K SLoC

A simple market simulator project with the following features

Module matching_engine is the back end engine that has all the matching functionalities with a CLI.

Matching Engine

The matching engine exposes the API required to create an order book and to match the order book to produce executions or Fills. A typical use case will be to create the order book fro a file containing orders, one order per line as given below and then use the matching engine to run the matching algorithm as so. Please refer to the CLI section for the order format.


use matching_engine::common::utils::{create_order_book, read_input};
use matching_engine::matchers::fifo_matcher::FIFOMatcher;
use matching_engine::matchers::matcher::Matcher;

let input = read_input("test_data/orders.txt");
let mut order_book = create_order_book(input);
//create a matcher
let mut matcher = FIFOMatcher;// or Prorata Matcher // match the order book with the matcher to produce executions let mut fills = matcher.match_order_book(&mut order_book);

The api is published at https://crates.io/crates/matching_engine

CLI:

The codebase also contains a CLI interface which can be executed as follows

execute cargo run -- -h or

matching_engine -h for complete usage help

Examples:

For the order file below

id1 IBM 300 602.5 Buy
id2 IBM 300 602.5 Sell
id3 IBM 100 602.5 Buy
id4 IBM 100 602.5 Sell
id5 IBM 300 602 Buy
id6 IBM 300 601.9 Buy
id4 IBM 100 602.1 Sell

executing cargo run -- prorata_test_data/orders.txt will produce the following output

if we executed the command using ProrataMatcher as such

executing cargo run -- prorata_test_data/orders.txt PRO will produce the following output

Dependencies

~6–17MB
~189K SLoC