Market Data Feed Parser
Medium-Hard ● Live C++ Rust Java PythonThe Problem
Parse 500,000 market data messages across 8 symbols from multiple exchanges. Maintain real-time order books for each symbol, output top-of-book snapshots, and compute VWAP and spread statistics.
Handle different message types: add orders, remove orders, fills, and trades. Ensure accurate order book state and efficient data processing.
Evaluation Criteria
Correctness (60%)
Order book state must be accurate for all symbols. Top-of-book snapshots correct. VWAP and spread calculations accurate to 4 decimal places.
Performance (40%)
Wall-clock time on 500K market data messages. Memory usage for maintaining 8 order books.
Input Format
- First line
N Swhere N = number of messages, S = number of distinct symbols.- Each message line
- comma-separated, first field is the type tag:
A,ts,order_id,B|S,price_cents,qty- Add order to the book. price_cents is an integer (price * 100).M,ts,order_id,new_qty- Modify an existing order's quantity. If new_qty is 0, treat as cancel.X,ts,order_id- Cancel an order.T,ts,price_cents,qty,buy_order_id,sell_order_id- Trade execution between two existing orders. Decrement both sides; remove either if quantity hits zero.
Output Format & Sample
Sample input (first 8 lines, full file linked below):
50 5 A,1000042005,1001,B,9986,892 A,1000047802,1002,B,9987,179 A,1000094827,1003,B,9972,206 A,1000140680,1004,B,9952,22 M,1000163321,1004,35 M,1000168585,1003,138 A,1000171688,1005,B,9986,147 ... (more)
Expected output for that sample (first 8 lines):
1000163321,9987,179,0,0 1000247346,9987,179,10026,4740 1000379513,9987,179,10026,4740 1000553814,9991,752,10002,8 1000720991,9991,752,10002,8 1000770422,9991,752,10002,8 1000896737,9991,752,10002,8 1001089220,9992,79,10002,8 ... (more)
↓ download full sample input | ↓ download expected output
Test your solution locally:
./your_solution < input.txt | diff - output.txt
Common Pitfalls
- Prices are in cents. Don't divide by 100 internally - 32-bit integer math is faster.
- Multiple symbols share an order id space. Track which symbol each order_id belongs to; messages don't always carry the symbol.
- Output is per-symbol top-of-book snapshots plus VWAP/spread stats. The exact output format the grader expects is shown in the sample output. Match it character-for-character (whitespace included).
- 500K messages, 8 symbols. Use
std::unordered_mapor equivalent for order lookups; per-symbol order books should use sorted maps (price -> queue of orders).
Performance Tier Thresholds (applied by the grader)
| Language | Gold | Silver | Bronze | Tier 4 |
|---|---|---|---|---|
| C++ | <400ms | <1500ms | <8000ms | else PASS |
| Rust | <400ms | <1500ms | <8000ms | else PASS |
| Java | <800ms | <3000ms | <15000ms | else PASS |
| Python | <3000ms | <10000ms | <50000ms | else PASS |
Submission Rules
- Single-file solutions only. All code must be in one file.
- Your program must read from stdin and write to stdout.
- Java class must be named Solution.
- No network access, no filesystem access beyond stdin/stdout.
- Time limit: 120 seconds. Memory limit: 2 GB.