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 listApr 17, 2026 00:17olliecrowolliecrowScore: 5,513Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 17, 2026 00:174,88989,821,31259,519,0004,035,0002,510,848
2Apr 19, 2026 05:564,91294,252,84254,873,0008,979,0002,494,464
3Apr 19, 2026 05:564,91396,233,79557,880,0005,987,0002,437,120
4Apr 19, 2026 05:564,93592,231,34560,147,0004,009,0002,277,376
5Apr 17, 2026 00:174,95790,037,44259,410,0005,034,0002,330,624
6Apr 17, 2026 00:175,11192,487,93763,420,0003,020,0002,359,296
7Apr 19, 2026 05:565,18395,037,45965,366,0002,011,0002,396,160
8Apr 19, 2026 05:565,25894,731,56661,313,0007,036,0002,510,848
9Apr 19, 2026 05:555,30794,975,59164,989,0003,999,0002,453,504
10Apr 19, 2026 05:565,501103,790,57567,483,0004,028,0002,379,776
11Apr 19, 2026 05:565,51399,280,45366,618,0005,046,0002,285,568
12Apr 17, 2026 00:175,665103,279,59369,615,0004,035,0002,273,280
13Apr 19, 2026 05:555,805105,474,92871,440,0004,024,0002,514,944
14Apr 19, 2026 05:565,829101,587,52869,796,0005,982,0002,449,408
15Apr 19, 2026 05:555,853105,814,69368,079,0008,009,0002,494,464
16Apr 17, 2026 00:175,911105,372,34870,856,0005,987,0002,461,696
17Apr 17, 2026 00:175,951106,087,93873,341,0004,018,0002,506,752
18Apr 17, 2026 00:175,969103,791,72573,571,0004,031,0002,465,792
19Apr 17, 2026 00:176,343111,719,72073,408,0009,050,0002,392,064
20Apr 19, 2026 05:566,465110,574,44380,049,0004,002,0002,506,752
21Apr 17, 2026 00:176,561116,460,20279,270,0006,020,0002,351,104