The program reads the input line by line from stdin.
Each line is exactly one of the following message types:
- Trade print — a trade that occurred on the exchange
print <timestamp> <security> <quantity> <price>
- Volume check — request to report the total traded quantity of a security in the preceding minute, and its latest price
volume-check <timestamp> <security>
- Order — request to trade shares subject to participation limits
order <timestamp> <security> <client> <goal> <participation_rate>
Fields (space-delimited):
timestamp: seconds since market open (non-negative integer). Timestamps are monotonically non-decreasing.security: security symbol (alphabetic string).quantity: number of shares traded (positive integer).price: trade price (positive integer).client: client name (alphabetic string).goal: total number of shares to trade (positive integer).participation_rate: max percent of the security’s trailing 1-minute volume (computed without this order) that this order may constitute (positive integer).
An order is:
- filled when its
goalquantity has been traded, - active from its timestamp until it is filled or expires after one minute (T to T+60, exclusive of T+60),
- at most one active order per (client, security) at any time.
Output
For each volume-check for security S at time T, emit exactly one line:
traded-volume T S <volume> <price>
Where:
<volume>is the sum of quantities in allprintmessages whose timestamps are in (T-60, T]. If none, output0.<price>is the price of the most recent print forSat or beforeT. If none, output0.
A volume-check response must be printed immediately before reading the next input line.
For each order on security S at time T, emit a sequence of prints you execute:
print T' S <quantity> <price>
Subject to all constraints below (maximize filled shares as soon as possible):
- Monotone timestamps: your emitted timestamps must not go backwards relative to observed exchange activity; in particular,
T' ≥ T. - Expiry: all your prints must satisfy
T' < T + 60. - Participation limit: for the trailing minute ending at each T’, \frac{\text{(your emitted volume within that minute)}}{\text{(all *other* trades’volume within that minute)}} \le \text{participation_rate \%} The denominator uses observed exchange prints only (i.e., excludes the order you are executing).
- Positive integer quantities: each emitted print has positive integer
<quantity>, and the sum over the sequence must not exceedgoal. - Price: each emitted print must use the latest observed price of
S(from the most recent exchangeprintat or beforeT'). If no price exists, you cannot print.
Notes:
- As earlier exchange prints roll out of the 60-second window, your instantaneous participation ratio may appear to spike; that’s okay — the limit is evaluated at emission time.
- Always trade as much as possible as soon as possible while respecting the constraints above.
简要总结
实现一个交易所流事件模拟器,逐行读取三类消息:成交 print、查询 volume-check、以及带 1 分钟参与率限制 的客户 order。
volume-check(T, S)需要立刻输出:该证券在(T-60, T]的总成交量,以及 最近一次 成交价(没有则 0)。order要在T…T+60内,按 不回退时间、使用最新外部成交价 、 严格满足参与率上限 的前提,尽量快、尽量多地下自有print指令完成goal,每次数量为正整数,总量不超过goal。参与率分母只看 外部真实成交,不含你的订单执行量。
VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括 Voleon、Google、Amazon、Citadel、SIG 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备 Tiktok 或类似工程向公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。