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 8, 2026 13:06Victor MerckléVictor MerckléError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Sep 15, 2026 23:45Josu San Martin10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 15, 2026 23:45011,560,76602,844,0002,146,304line 0: expected liquidate 1 -561845 399500 got liquidate 1 5445 966790stderr
2Sep 15, 2026 23:45012,110,66502,967,0002,203,648line 0: expected liquidate 10 -384757 317200 got liquidate 10 5399 707356stderr
3Sep 15, 2026 23:45011,470,45102,968,0002,162,688line 0: expected liquidate 0 -491592 410600 got liquidate 0 5234 907426stderr
4Sep 8, 2026 13:0887721,483,74010,127,0001,279,0002,142,208stderr
5Sep 8, 2026 13:0890231,766,47710,504,0001,226,0002,146,304stderr
6Sep 8, 2026 13:0894922,949,08711,021,0001,328,0002,142,208stderr
7Sep 8, 2026 13:0898223,316,89211,515,0001,256,0002,142,208stderr
8Sep 8, 2026 13:0898421,539,72011,540,0001,264,0002,142,208stderr
9Sep 8, 2026 13:0899422,849,92111,619,0001,304,0002,142,208stderr
10Sep 8, 2026 13:081,00723,398,45711,825,0001,270,0002,142,208stderr
11Sep 8, 2026 13:081,01223,248,04811,846,0001,318,0002,142,208stderr
12Sep 8, 2026 13:081,09640,013,79312,129,0002,121,0002,146,304stderr