Author: Matthew Bernardi
Academic Year: 2024/2025
Course: Reti e Laboratorio (LAB2425)
CROSS (an exChange oRder bOokS Service) is a simplified centralized exchange system for cryptocurrency trading, focusing on BTC/USD pairs. It emulates the core mechanisms behind order matching, execution, and market dynamics—similar to what real-world platforms like Binance or Coinbase use.
The project consists of a multi-threaded server and an interactive client, communicating via TCP and UDP, designed entirely in Java. Orders supported include Market, Limit, and Stop Orders, which are processed following a price/time priority matching algorithm.
- Market Orders: Executed immediately at the best available price. If conditions aren't met, the order is rejected.
- Limit Orders: Executed only if price conditions are satisfied; otherwise queued for future matching.
- Stop Orders: Turn into Market Orders once a defined stop condition is met.
- Register/Login/Logout
- Place Market, Limit, and Stop Orders (both Ask and Bid)
- Cancel pending orders
- Request price history (with daily OHLC data)
- Real-time notifications via UDP on order executions
- Handle multiple clients concurrently using a thread pool
- Maintain persistent storage of users and executed orders (in JSON format)
- Match orders fairly and efficiently
- Send asynchronous UDP notifications on trade executions
- Periodically check and execute pending Stop Orders
You can compile and run the server/client using the provided bash scripts:
./server.sh # Launch server
./client.sh # Launch clientConcurrentSkipListSet<Order>: for open ask and bid orders, ordered by price and timestampConcurrentLinkedQueue<User>: stores all registered usersConcurrentLinkedQueue<Order>: history of executed ordersConcurrentLinkedQueue<Order>: pending stop ordersLinkedBlockingQueue<Runnable>: server-side task queue
Synchronization is ensured using Java's synchronized blocks when accessing shared structures or writing to files.
-
Client:
ClientMain: Main thread, handles CLI interaction and TCP messagesClientUDP: Listens for server-side asynchronous notifications
-
Server:
ServerMain: Accepts new TCP connectionsServerTask: Handles one client per threadServerUDP: Sends UDP notifications, shared among ServerTasks
The config/ folder contains the main configuration files and the client.sh and server.sh execution bash scripts, meanwhile the src/ folder contains the source code files.