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 listJun 29, 2026 01:12Victor MerckléVictor MerckléError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Sep 4, 2026 20:55Tomislav Tunkovic10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 4, 2026 21:0209,884,52801,645,0002,154,496line 1: expected liquidate 5 69860 9665196 got liquidate 16 -178265 6016885
2Sep 4, 2026 21:0209,820,38501,635,0002,170,880line 2: expected liquidate 6 -26208 4919040 got liquidate 4 198601 19897375
3Sep 4, 2026 21:02012,743,81901,927,00065,536Exit with code 2: unexpected fault address 0x41744be88 fatal error: fault [signal SIGSEGV: segmentation violation code=0x1 addr=0x41744be88 pc=0x10000458] goroutine 1 gp=0x291db3bc21e0 m=0 mp=0x527f60 [running, locked to thread]: runtime.throw({0x48e3...stderr
4Jun 29, 2026 01:141,46729,086,47416,853,0002,223,0002,150,400
5Jun 29, 2026 01:141,47428,977,91816,783,0002,391,0002,150,400
6Jun 29, 2026 01:141,47727,048,22417,021,0002,188,0002,150,400
7Jun 29, 2026 01:141,48829,080,11017,114,0002,241,0002,150,400
8Jun 29, 2026 01:141,49429,262,36617,188,0002,246,0002,150,400
9Jun 29, 2026 01:141,54529,799,66717,801,0002,292,0002,150,400
10Jun 29, 2026 01:141,56030,297,85117,981,0002,310,0002,150,400
11Jun 29, 2026 01:141,58730,631,38018,375,0002,264,0002,150,400
12Jun 29, 2026 01:141,61131,290,09118,584,0002,366,0002,150,400