Cross-Margin Liquidation Engine yenw0d

Simulate a cross-margin derivatives engine: process trades, track account equity, and liquidate undercollateralized accounts as fast as possible.

Accounts are funded with a USD deposit and trade instruments whose prices change over time. When a price update causes an account’s equity to fall below 1% of its total position notional, the account must be liquidated.

Definitions

  • Account equity = balance + Σ(size_i * price_i) - Σ(total_paid_i)
  • Total position notional = Σ(|size_i| * price_i)
  • Total paid for instrument i = signed sum of trade_size * price_at_trade_time across all trades
  • Margin rule: liquidate if equity < total_notional / 100 after any price update

Input

One command per line on STDIN:

  • a <balance> – create account with USD balance (IDs start at 0, incrementing)
  • p <instrument_idx> <price> – set/update instrument price (0-indexed)
  • t <account_idx> <instrument_idx> <size> – trade size (signed) at current price
  • Final line: <account_idx> – query this account and terminate

Output

On each price update, liquidate all accounts violating the margin rule. For each liquidation, print:

liquidate <account_id> <equity> <position_notional>

Liquidation order: largest total position notional first, then account ID descending as tie-breaker. Liquidated accounts have their balance and positions cleared.

For the final query, print <equity> <notional> for the requested account.

Constraints

  • Accounts: <= 100,000
  • Instruments: <= 1,000
  • Price range: 100 to 1,000,000
  • Trade size range: 1 to 10,000

Example

a 100
p 0 100
t 0 0 10
p 0 90
0

Output:

liquidate 0 0 900
0 0
Back to listFeb 21, 2026 17:01olliecrowolliecrowScore: 11,121Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Feb 21, 2026 15:149,931156,326,840120,091,0009,006,0002,314,240
2Feb 21, 2026 15:1410,471160,824,695128,121,0008,007,0002,502,656
3Feb 21, 2026 17:0110,511162,441,931130,610,0006,028,0002,441,216
4Feb 21, 2026 15:0910,631166,437,418132,191,0006,008,0002,469,888
5Feb 21, 2026 15:3710,736168,618,458134,542,0005,020,0002,396,160
6Feb 21, 2026 15:0910,766167,327,994131,960,0007,997,0002,383,872
7Feb 21, 2026 15:0911,121170,202,489138,544,0006,023,0002,506,752
8Feb 21, 2026 15:3711,369174,693,741138,810,0008,987,0002,269,184
9Feb 21, 2026 15:1411,926178,272,617149,043,0006,001,0002,424,832
10Feb 21, 2026 15:3711,985182,874,683149,811,0005,992,0002,482,176
11Feb 21, 2026 17:0112,234183,492,125150,035,0009,002,0002,514,944
12Feb 21, 2026 17:0112,910198,443,228160,841,0006,993,0002,531,328