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 listAug 21, 2026 20:58Andrew EpsteinAndrew EpsteinError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Sep 4, 2026 18:34Tomislav Tunkovic40.92CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 4, 2026 18:36011,947,48901,913,0002,125,824line 9: expected liquidate 12 -39710 5397560 got liquidate 4 -146352177443 146373544681stderr
2Sep 4, 2026 18:36013,359,02401,951,0002,125,824line 11: expected liquidate 11 -79394 5627922 got liquidate 11 -62640427157 62645975685stderr
3Sep 4, 2026 18:36011,908,52001,902,0002,125,824line 3: expected liquidate 7 87936 14229962 got liquidate 4 -95824205304 95832748544stderr
4Aug 21, 2026 20:592,84447,618,00434,710,0002,271,0002,117,632stderr
5Aug 21, 2026 20:592,86948,484,72835,027,0002,271,0002,121,728stderr
6Aug 21, 2026 20:592,93648,910,31935,904,0002,272,0002,121,728stderr
7Aug 21, 2026 20:592,96848,464,22736,327,0002,269,0002,121,728stderr
8Aug 21, 2026 20:592,99449,586,54436,603,0002,326,0002,121,728stderr
9Aug 21, 2026 20:593,00249,015,56636,713,0002,317,0002,121,728stderr
10Aug 21, 2026 20:593,08650,815,64237,885,0002,234,0002,121,728stderr
11Aug 21, 2026 20:593,11252,494,79538,120,0002,337,0002,121,728stderr
12Aug 21, 2026 20:593,14250,771,59738,756,0002,101,0002,121,728stderr