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 listSep 4, 2026 10:18Victor MerckléVictor MerckléError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Sep 5, 2026 01:59Tomislav Tunkovic10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 5, 2026 03:37011,680,6591,573,0001,546,0002,146,304line 4: expected liquidate 6 -27531 2454606 got liquidate 6 0 2427075stderr
2Sep 5, 2026 03:37012,250,0491,684,0001,666,0002,203,648line 2: expected liquidate 3 -2093 1797289 got liquidate 3 0 1795196stderr
3Sep 5, 2026 03:37013,191,6151,698,0001,587,0002,146,304line 2: expected liquidate 9 163 174899 got liquidate 9 0 174736stderr
4Sep 4, 2026 10:2086719,667,79410,096,0001,180,0002,142,208stderr
5Sep 4, 2026 10:2088519,929,24710,211,0001,304,0002,142,208stderr
6Sep 4, 2026 10:2089220,024,60710,335,0001,270,0002,142,208stderr
7Sep 4, 2026 10:2094222,158,73611,086,0001,161,0002,142,208stderr
8Sep 4, 2026 10:2094720,718,57111,157,0001,155,0002,142,208stderr
9Sep 4, 2026 10:2095320,834,89711,104,0001,286,0002,142,208stderr
10Sep 4, 2026 10:2098821,302,29211,538,0001,309,0002,142,208stderr
11Sep 4, 2026 10:201,00321,437,51110,981,0002,062,0002,191,360stderr
12Sep 4, 2026 10:201,07322,426,13112,639,0001,315,0002,142,208stderr