Skip to content

About

A simulation of a real-world Trading Order Management System built in Java and Spring Boot. The system accepts buy and sell orders via a REST API, matches them using a price and time priority algorithm, and tracks each trader's portfolio in real time.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

82 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trading Order Management System (OMS)

Overview

A simulation of a real-world Trading Order Management System built in Java and Spring Boot. The system accepts buy and sell orders via a REST API, matches them using a price and time priority algorithm, and tracks each trader's portfolio in real time. Built as a personal project to gain hands-on experience with the kind of backend systems used in investment banking.

Features

  • Matching Engine: matches sell and buy orders using a price-time priority algorithm
  • Order types: limit orders, market orders, stop orders
  • Portfolio tracking: a portfolio for each trader with their current balances
  • Tests: unit tests using JUnit 5 covering full fills, partial fills, and no-match scenarios

Tech Stack

  • Java 21
  • Spring Boot 3.1.5
  • JUnit 5
  • Maven

Architecture

The system is split into 3 main layers:

  1. The domain layer that contains the Order class hierarchy, OrderBook, MatchingEngine and Portfolio.
  2. The service layer that wraps the engine and manages portfolio state.
  3. The controller layer exposes REST endpoints via Spring Boot.

Getting Started

Prerequisites

  • Java 21
  • Maven
  • Docker

Running the app

git clone https://github.com/Leena26/trading-oms.git cd trading-oms docker-compose up -d mvn spring-boot:run

Running the tests

mvn test

API Endpoints

Method Endpoint Description
POST /orders Submit a buy or sell order
GET /portfolio/{traderId} View a trader's holdings and cash balance
DELETE /orders/{orderId} Cancel an order

Example Usage

curl -X POST http://localhost:8080/orders -H "Content-Type: application/json" -d "{"orderType":"LIMIT","traderId":"trader-1""symbol":"AAPL","quantity":100,"limitPrice":50.0,"buy":true}" [] curl -X POST http://localhost:8080/orders -H "Content-Type: application/json" -d "{"orderType":"LIMIT","traderId":"trader-2""symbol":"AAPL","quantity":100,"limitPrice":50.0,"buy":false}" [{"tradeId":"0794ceff-d128-4244-91f4-c46d46d83e93","buyOrderId":"9238eb70-d40f-4ef7-8117-b048bcb840c2","sellOrderId":"82e75158-583a-4d1e-b1c3-4763601fe2d1","symbol":"AAPL","executedPrice":50.0,"quantity":100}] curl -X POST http://localhost:8080/orders -H "Content-Type: application/json" -d "{"orderType":"STOP","traderId":"trader-1","symbol":"AAPL","quantity":100,"stopPrice":45.0,"buy":false}" [] curl http://localhost:8080/portfolio/trader-1 {"holdings":{"AAPL":100},"cashBalance":95000.0} curl http://localhost:8080/portfolio/trader-2 {"holdings":{},"cashBalance":105000.0}

What I learned

This project taught me the importance of Maven in running tests and ensuring the right packages were referenced. I also learnt how to engage with REST APIs and Spring Boot. The matching algorithm also showed me how a trading OMS inherently works and the overall logic behind the system. I also gained an understanding of how price-time priority matching works, the same algorithm used by exchanges like the London Stock Exchange, and how order state transitions from PENDING to PARTIALLY_FILLED to FILLED.

About

A simulation of a real-world Trading Order Management System built in Java and Spring Boot. The system accepts buy and sell orders via a REST API, matches them using a price and time priority algorithm, and tracks each trader's portfolio in real time.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages