Market Data Feed Parser

MEDIUM-HARD • Live C++ Rust Java Python
500K
MESSAGES
8
SYMBOLS
4
MSG TYPES

Problem Description

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.

Tier System & Performance Targets

LANGUAGEGOLDSILVERBRONZE
C++ / Rust< 400ms< 1500ms< 8000ms
Java< 800ms< 3000ms< 16000ms
Python< 4000ms< 15000ms< 60000ms

Evaluation Criteria

Correctness: Order book state must be accurate for all symbols. Top-of-book snapshots correct. VWAP and spread calculations accurate to 4 decimal places.

Performance: Wall-clock time on 500K market data messages. Memory usage for maintaining 8 order books.

Input Format

Read from stdin. Each line contains a market data message:

SYMBOL ACTION PRICE QUANTITY

Where:

Output Format

For each snapshot point, output one line per symbol:

SYMBOL BID_PRICE BID_SIZE ASK_PRICE ASK_SIZE VWAP SPREAD

Example

Input

AAPL ADD_ORDER 150.00 100
AAPL ADD_ORDER 150.50 50
MSFT ADD_ORDER 300.00 200
AAPL FILL 150.00 50

Output

AAPL 150.0000 50 150.5000 50 150.2500 0.5000
MSFT 300.0000 200 300.5000 100 300.2500 0.5000

Submission Rules

Starter Templates

C++
#include <cstdio>
#include <cstring>
#include <unordered_map>
#include <map>

struct Order {
    char side;
    int64_t price;
    int32_t quantity;
};

int main() {
    // Read from stdin
    // Maintain order books per symbol
    // Output snapshots
    return 0;
}
Python
from collections import defaultdict
import sys

order_books = defaultdict(lambda: {'bids': {}, 'asks': {}})

for line in sys.stdin:
    parts = line.strip().split()
    symbol, action = parts[0], parts[1]
    price, qty = float(parts[2]), int(parts[3])
    # Process message
    # Update order book
    # Output snapshots at intervals
Rust
use std::collections::HashMap;
use std::io::{self, BufRead, Write, BufWriter};

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    let mut out = BufWriter::new(stdout.lock());

    let mut order_books: HashMap<String, Vec<(i64, i32)>> = HashMap::new();

    for line in stdin.lock().lines() {
        let line = line.unwrap();
        // Parse message
        // Update order book
        // Output snapshots
    }
}
Java
import java.util.*;
import java.io.*;

public class Solution {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Map<String, TreeMap<Long, Long>> bids = new HashMap<>();
        Map<String, TreeMap<Long, Long>> asks = new HashMap<>();

        String line;
        while ((line = br.readLine()) != null) {
            // Parse message
            // Update order book
            // Output snapshots
        }
    }
}

Submit Your Solution

Supported formats: .cpp, .py, .rs, .java, or raw text