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 listOct 9, 2025 14:58Yuriy LyfenkoYuriy LyfenkoError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Sep 4, 2026 18:58Tomislav Tunkovic18.71CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 4, 2026 19:00014,917,3342,465,0002,465,00020,480No answer to stdout. Died or killed?
2Sep 4, 2026 19:00015,198,8992,067,0003,157,0002,125,824line 29: expected liquidate 5 -54131 2714690 got liquidate 5 0 2660559stderr
3Sep 4, 2026 19:00016,628,7432,047,0003,081,0002,125,824line 1: expected liquidate 8 -42234 6324209 got liquidate 1 -1376091 6514529stderr
4Oct 9, 2025 15:016,078104,432,39774,014,0005,000,0002,314,240
5Oct 9, 2025 15:016,382115,399,76179,969,0002,998,0002,473,984
6Oct 9, 2025 15:006,409113,234,67878,299,0005,019,0002,277,376
7Oct 9, 2025 15:006,469110,145,79779,088,0005,005,0002,289,664
8Oct 8, 2025 20:296,596114,825,03080,757,0004,985,0002,379,776
9Oct 8, 2025 20:296,681113,333,34584,851,0001,996,0002,265,088
10Oct 9, 2025 15:016,774114,412,82084,056,0004,002,0002,437,120
11Oct 9, 2025 15:016,854114,746,71685,098,0004,004,0002,502,656
12Oct 9, 2025 14:586,904115,613,03784,762,0004,986,0002,301,952
13Oct 8, 2025 20:297,024117,508,64687,299,0004,013,0002,486,272
14Oct 9, 2025 15:007,096119,997,71888,233,0004,010,0002,482,176
15Oct 9, 2025 15:007,112117,292,18686,426,0006,029,0002,351,104
16Oct 8, 2025 20:297,137125,016,11085,801,0006,983,0002,498,560
17Oct 9, 2025 15:007,229120,046,10089,983,0003,999,0002,269,184
18Oct 9, 2025 15:007,238125,782,17090,087,0004,003,0002,510,848
19Oct 9, 2025 15:017,248126,079,70489,216,0005,012,0002,449,408
20Oct 9, 2025 15:007,373125,560,33890,858,0004,992,0002,457,600
21Oct 8, 2025 20:297,375125,021,25891,883,0003,994,0002,514,944
22Oct 9, 2025 14:587,381127,412,33790,956,0004,997,0002,510,848
23Oct 9, 2025 15:017,396120,803,91791,139,0005,007,0002,338,816
24Oct 9, 2025 15:017,399121,196,47094,185,0002,003,0002,494,464
25Oct 9, 2025 15:007,889129,270,90698,539,0004,022,0002,465,792
26Oct 9, 2025 15:017,952130,160,81398,354,0005,018,0002,416,640
27Oct 9, 2025 15:007,990137,139,74799,877,0003,995,0002,490,368
28Oct 8, 2025 20:298,076131,880,85599,983,0004,999,0002,396,160
29Oct 9, 2025 14:588,077129,536,585101,996,0002,999,0002,392,064
30Oct 8, 2025 20:298,098133,822,589100,263,0005,013,0002,392,064
31Oct 9, 2025 15:018,236132,796,749104,063,0003,001,0002,461,696
32Oct 8, 2025 20:298,662138,765,297107,585,0005,027,0002,437,120
33Oct 8, 2025 20:299,663156,715,696121,594,0004,019,0002,433,024