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 listFeb 21, 2026 15:00olliecrowolliecrowScore: 11,296Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Feb 21, 2026 02:598,960142,821,191111,462,0005,020,0002,281,472
2Feb 21, 2026 07:269,112150,533,803109,427,0009,035,0002,416,640
3Feb 21, 2026 07:269,677159,970,225120,806,0004,991,0002,449,408
4Feb 21, 2026 02:599,908166,733,697123,812,0004,992,0002,510,848
5Feb 21, 2026 02:599,989160,969,543125,863,0003,995,0002,367,488
6Feb 21, 2026 07:2610,048155,820,768127,610,0003,014,0002,306,048
7Feb 21, 2026 02:5910,073160,209,720126,950,0003,998,0002,457,600
8Feb 21, 2026 02:5910,539162,514,292133,005,0004,000,0002,506,752
9Feb 21, 2026 02:5910,625170,273,851134,117,0004,003,0002,514,944
10Feb 21, 2026 06:1710,662164,307,575134,588,0004,017,0002,465,792
11Feb 21, 2026 07:2610,775167,797,273135,067,0005,002,0002,433,024
12Feb 21, 2026 07:2610,886167,146,621135,500,0006,022,0002,510,848
13Feb 21, 2026 15:0010,912165,484,512135,868,0005,994,0002,527,232
14Feb 21, 2026 07:2611,146170,668,573141,897,0002,997,0002,506,752
15Feb 21, 2026 02:5911,198178,015,945140,550,0005,019,0002,453,504
16Feb 21, 2026 03:2911,296175,238,277144,853,0001,997,0002,375,680
17Feb 21, 2026 14:4911,355174,142,229144,608,0003,012,0002,510,848
18Feb 21, 2026 03:2911,358171,761,494143,639,0004,017,0002,322,432
19Feb 21, 2026 06:1711,596179,655,315146,753,0003,993,0002,428,928
20Feb 21, 2026 07:2611,603179,636,276143,853,0006,992,0002,314,240
21Feb 21, 2026 14:4911,669181,639,449146,711,0004,990,0002,408,448
22Feb 21, 2026 14:4911,691177,046,075148,984,0002,999,0002,330,624
23Feb 21, 2026 07:2611,770182,596,617149,013,0004,000,0002,297,856
24Feb 21, 2026 15:0011,844185,875,300147,969,0005,998,0002,486,272
25Feb 21, 2026 02:5911,861184,014,153151,185,0003,003,0002,502,656
26Feb 21, 2026 07:2612,178190,572,186155,313,0003,006,0002,367,488
27Feb 21, 2026 06:1712,182181,901,554154,356,0004,009,0002,363,392
28Feb 21, 2026 02:5912,409189,208,280155,307,0006,011,0002,461,696
29Feb 21, 2026 03:2912,547189,782,459159,103,0004,002,0002,293,760
30Feb 21, 2026 15:0013,108196,668,651168,397,0002,004,0002,486,272