Back to problems

Sort trade executions into a canonical order

Algorithm · Jane Street · Medium

An upstream execution feed emits trade records that may arrive in an arbitrary order. Each record is a dictionary with fields trade_id (string), symbol (string), ts (integer timestamp in milliseconds), price (integer tick price), qty (positive integer), and side (either "B" or "S"). The feed can also redeliver a trade: the same trade_id may appear more than once. Treat every later occurrence of an already seen trade_id as a replay. Scan the input from left to right, keep the…

Checking your access…