Playing around with Kotlin - building an in-memory order management system for cryptocurrency trading. Handles order placement, cancellation, and real-time summary views across multiple price levels.
- Multi-coin support - BITCOIN, ETHEREUM, LITECOIN, XPX
- Two-sided order book - Separate BUY/SELL books with proper price ordering (highest bids first, lowest offers first)
- Price level aggregation - Orders at same price consolidated into single summary entry
- Top-of-book view - Summary limited to top 10 price levels per side
interface LiveOrderBoardAPI {
fun placeOrder(userId: String, coinType: CoinType, quantity: Double, price: Double, direction: Direction): String
fun deleteOrder(orderId: String)
fun getSummary(coinType: CoinType): Collection<OrderSummary>
}- TreeMap for price-ordered levels (descending for bids, ascending for offers)
- LinkedHashMap for orders at each price level (maintains insertion order)
- Per-coin Market objects isolate order books by instrument
mvn test- Not thread-safe (single-threaded use only)
- No persistence (in-memory only)
- Basic validation via
requirestatements - Could optimize quantity tracking at price level