Skip to content

snavale2/Stock-Trading-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Name: Shubham Navale Email: snavale@binghamton.edu

Stock Trading Engine

A multi-threaded stock trading simulation engine that processes buy and sell orders for multiple stock tickers in real-time.

Directory Structure

Stock-Trading-Engine/
├── src/
│   ├── Main.java              # Application entry point
│   ├── TradingSimulation.java # Core simulation logic
│   ├── StockExchange.java     # Order matching engine
│   ├── OrderBook.java         # Manages orders per ticker
│   ├── Order.java             # Order entity class
│   ├── Logger.java            # Logging utility
│   └── config.properties      # Configuration settings
├── bin/                       # Compiled class files
└── .vscode/                   # VSCode configuration

Configuration Setup

Before running the project, configure the simulation parameters in src/config.properties:

# Number of stock symbols to simulate
totalTickers=1024

# Number of concurrent order-processing threads
threadPoolSize=5

# Total orders to generate (leave blank for infinite)
totalOrders=

Building and Running

Navigate to the project root directory (Stock-Trading-Engine) in your terminal and execute the following commands:

  1. Create the bin directory (if it doesn't exist):
mkdir bin
  1. Compile all Java files:
javac -d bin src/*.java
  1. Run the application:
  • For normal mode:
java -cp bin Main
  • For test mode:
java -cp bin Main --test

Output Format

trading_output.txt

Records all orders and trades in the following format:

Orders:

TYPE    | TICKER    | SHARES | PRICE
BUY     | STOCK1     | 100    | 150.50
SELL    | STOCK1     | 50     | 151.00

Trades:

TRADE   | TICKER    | SHARES | PRICE   | Buy: X | Sell: Y

Example:

TRADE   | STOCK1     | 50     | 150.75  | Buy: 50 | Sell: 0

In this example:

  • 50 shares were traded
  • Buy order has 50 shares remaining
  • Sell order has 0 shares remaining

trading_error.log

Contains error messages and stack traces for debugging purposes.

About

A real-time stock trading engine built in Java that reliably matches Buy and Sell orders under concurrent load. By using lock-free data structures, the system avoids traditional synchronization bottlenecks, enabling higher throughput and predictable performance in multi-threaded environments. Orders are matched using price-priority logic with O(n)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages