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 14, 2026 09:34Victor MerckléVictor MerckléError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Sep 16, 2026 00:04Josu San Martin10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 16, 2026 00:04011,351,70702,266,0002,121,728line 0: expected liquidate 17 -500976 401900 got liquidate 17 5418 908294stderr
2Sep 16, 2026 00:04010,699,79602,122,0002,121,728line 0: expected liquidate 7 -306217 270800 got liquidate 7 5203 582220stderr
3Sep 16, 2026 00:04010,742,45302,173,0002,121,728line 0: expected liquidate 17 -413494 360800 got liquidate 17 5034 779328stderr
4Sep 14, 2026 09:3597321,280,53211,476,0001,175,0002,117,632stderr
5Sep 14, 2026 09:351,00421,649,45411,860,0001,193,0002,117,632stderr
6Sep 14, 2026 09:351,01021,798,55711,960,0001,176,0002,117,632stderr
7Sep 14, 2026 09:351,02021,900,06812,212,0001,056,0002,117,632stderr
8Sep 14, 2026 09:351,02821,962,77312,208,0001,156,0002,117,632stderr
9Sep 14, 2026 09:351,03522,063,69512,145,0001,313,0002,117,632stderr
10Sep 14, 2026 09:351,05222,441,96812,456,0001,230,0002,117,632stderr
11Sep 14, 2026 09:351,09822,857,00413,037,0001,240,0002,117,632stderr
12Sep 14, 2026 09:351,13423,562,45413,674,0001,071,0002,117,632stderr