You are building an auditing module for a high-frequency trading platform. The system receives an asynchronous, out-of-order telemetry stream containing trade execution logs across multiple financial exchanges.
Your task is to reconstruct the chronological execution timeline for a specified exchange venue and find the maximum number of consecutive trade logs in a continuous execution window that satisfies strict operational risk limits.
Given an array of execution log objects logs, a target venue identifier target_venue, a maximum allowable price variance V, and a maximum cumulative slippage budget S, process the data through the following steps:
Filter: Isolate records where the venue matches target_venue.
Reconstruct: Sort the filtered records chronologically by timestamp in ascending order.
Calculate Metric: For each log, compute its individual slippage cost: slippage_cost = abs(fill_price - benchmark_price) * volume
Evaluate Window: Find the length of the longest contiguous sub-sequence of sorted logs where both conditions are met:
Price Volatility Spread: max(fill_price) - min(fill_price) <= V
Cumulative Slippage Cost: sum(slippage_cost) <= S
Return an integer representing the maximum length (count of logs) of a valid execution window. Return 0 if no valid window exists or if filtering yields no matching logs.
Input Specification
logs: An array of objects/dictionaries, where each object contains:
timestamp (integer): Epoch timestamp in seconds.
venue (string): Exchange name (e.g., "NASDAQ", "NYSE").
fill_price (integer): Executed order price.
benchmark_price (integer): Arrival reference price.
volume (integer): Executed share count.
target_venue (string): The venue to audit.
V (integer): Maximum allowed price spread within a window.
S (integer): Maximum allowed total slippage cost within a window.
Output Specification
Return an integer representing the length of the longest valid execution window.
Examples
Example 1: Multi-Venue & Out-of-Order Stream
JSON
Input:
logs = [
{"timestamp": 104, "venue": "NASDAQ", "fill_price": 105, "benchmark_price": 100, "volume": 1},
{"timestamp": 101, "venue": "NYSE", "fill_price": 200, "benchmark_price": 200, "volume": 10},
{"timestamp": 102, "venue": "NASDAQ", "fill_price": 101, "benchmark_price": 100, "volume": 2},
{"timestamp": 101, "venue": "NASDAQ", "fill_price": 100, "benchmark_price": 100, "volume": 1},
{"timestamp": 103, "venue": "NASDAQ", "fill_price": 103, "benchmark_price": 100, "volume": 1}
]
target_venue = "NASDAQ"
V = 3
S = 5
Output: 3
Explanation:
Filtered & Sorted NASDAQ logs:
ts: 101 | fill_price: 100 | slippage = 0
ts: 102 | fill_price: 101 | slippage = 2
ts: 103 | fill_price: 103 | slippage = 3
ts: 104 | fill_price: 105 | slippage = 5
Window [101..103] has max price spread 103 - 100 = 3 <= 3 and total slippage 0 + 2 + 3 = 5 <= 5. Length is 3. Adding log 104 breaches both V and S.

