The Trading Order Book is a JavaScript class designed to manage the submission and matching of buy and sell orders in a simplified trading system. It provides basic functionalities for maintaining an order book and matching orders based on their side (buy or sell) and price.
- Node.js and npm: Ensure that Node.js and npm are installed on your machine.
- Grenache Setup: Ensure that Grenache DHT is gloabally installed.
npm i -g grenache-grape
-
Clone the repository:
git clone https://github.com/AYU97/trading-orderBook.git
-
Navigate to the project directory:
cd trading-orderBook
-
Install dependencies:
npm install
To start two grape server:
grape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
To start the server:
npm run server
To start the client:
npm run client
- I have added mutliple comments in the order book to make it more easy to understand.
- This is a basic implementation of order book.
- Order is always an array. Even if it is a single order, I am converting it into an array for consistency
- Each order has properties including side (buy or sell), price, and quantity.
- The order book matches orders based on their side and price.
- When matching orders, the quantity to match is calculated as the minimum of the quantities of the existing and new orders.
- Fully matched existing orders are removed from the order book.
- The order book maintains the order of orders as they are submitted.
- Enhancing the order matching algorithm to support more complex matching criteria, like limit orders, market orders
- Could be in the form of adding validation checks on orders
- Error handling could be improved in terms of any edge conditions that may come during order submission or matching