OrderBookJava is a terminal-based implementation of an electronic order book for trading systems, written in Java. It provides fast and efficient operations for adding, removing, and executing buy and sell orders with O(1) time complexity.
-
Types of Orders:
- Limit Order
- Market Order
-
Order Management:
- Add new buy or sell orders.
- Execute trades based on available orders.
-
Matching Logic:
- Automates the matching of compatible buy and sell orders based on price and quantity.
- Ensures trades are executed efficiently and accurately.
-
Optimized Performance:
- Implements data structures to achieve O(1) time complexity for core operations.
-
Core Classes:
OrderBook
: Manages the main operations for the order book, including adding, removing, and matching orders.Order
: Represents a single order with details like order type (buy/sell), price, and quantity.OrderBookApp
: Starting point of the program.
-
Flow:
- Orders are added to the system.
- The matching logic identifies compatible buy and sell orders.
- Matched orders are executed and removed from the order book.
- Java Development Kit (JDK): Version 11 or higher.
-
Clone the repository:
git clone https://github.com/pran9v/OrderBookJava.git cd OrderBookJava
-
Open the project in your preferred IDE.
-
Build the project:
- For IntelliJ/Eclipse: Import the project as a Maven project and let the dependencies resolve.
- Using the terminal:
mvn clean install
-
Run the application:
java -jar target/OrderBookJava.jar
- Add orders:
- Provide order details via the terminal input.
- View matched orders:
- Orders matching the criteria are displayed and executed.
- Monitor the order book:
- Unmatched orders remain in the system for future execution.