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 listMar 12, 2026 05:26olliecrowolliecrowScore: 6,531Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Mar 13, 2026 21:175,27198,642,78859,459,0009,070,0002,408,448
2Mar 12, 2026 05:265,43499,900,36164,591,0006,055,0002,289,664
3Mar 13, 2026 21:175,54599,109,48962,073,00010,011,0002,523,136
4Mar 13, 2026 21:265,605100,578,65262,885,0009,981,0002,269,184
5Mar 13, 2026 21:175,68698,340,79464,923,0008,989,0002,457,600
6Mar 13, 2026 21:145,835107,336,61473,853,0001,996,0002,297,856
7Mar 13, 2026 21:215,911105,016,10071,848,0004,989,0002,412,544
8Mar 13, 2026 21:175,971101,237,09570,561,0007,056,0002,420,736
9Mar 13, 2026 21:145,999100,662,09471,986,0005,998,0002,519,040
10Mar 12, 2026 05:266,105104,091,43171,325,0008,036,0002,355,200
11Mar 13, 2026 21:146,218109,433,66372,852,0007,983,0002,502,656
12Mar 13, 2026 21:176,220104,134,13072,879,0007,986,0002,338,816
13Mar 12, 2026 05:266,229108,837,37873,979,0006,998,0002,441,216
14Mar 13, 2026 21:146,269104,899,47470,430,00011,067,0002,482,176
15Mar 13, 2026 21:226,353107,976,19975,534,0007,049,0002,404,352
16Mar 12, 2026 05:266,356112,883,46373,555,0009,068,0002,371,584
17Mar 13, 2026 21:446,473107,470,10579,142,0005,009,0002,457,600
18Mar 13, 2026 21:446,490112,496,20875,335,0009,040,0002,293,760
19Mar 13, 2026 21:146,512109,714,39479,613,0005,038,0002,363,392
20Mar 13, 2026 21:446,531109,184,32471,920,00012,985,0002,404,352
21Mar 13, 2026 21:226,582110,858,42974,493,00011,073,0002,289,664
22Mar 13, 2026 21:146,603115,236,49577,853,0007,984,0002,387,968
23Mar 13, 2026 21:146,625111,506,52279,121,0007,010,0002,473,984
24Mar 13, 2026 21:146,723118,357,75977,357,00010,046,0002,433,024
25Mar 13, 2026 21:216,746114,923,87380,639,0007,055,0002,469,888
26Mar 13, 2026 21:266,802114,663,50380,392,0008,039,0002,396,160
27Mar 13, 2026 21:216,834117,399,92080,852,0007,985,0002,404,352
28Mar 12, 2026 05:266,887112,524,02481,486,0008,048,0002,428,928
29Mar 12, 2026 05:266,912115,242,85883,870,0005,990,0002,441,216
30Mar 12, 2026 05:266,917112,185,69383,923,0005,994,0002,461,696
31Mar 13, 2026 21:147,000118,370,49582,995,0007,999,0002,453,504
32Mar 13, 2026 21:177,009117,543,33383,111,0008,010,0002,473,984
33Mar 12, 2026 05:267,093118,600,27885,190,0007,015,0002,482,176
34Mar 13, 2026 21:177,141120,068,54888,839,0003,992,0002,379,776
35Mar 12, 2026 05:267,195118,686,33287,496,0006,034,0002,527,232
36Mar 13, 2026 21:177,388126,781,31688,046,0008,004,0002,502,656
37Mar 13, 2026 21:267,644126,472,38794,357,0005,018,0002,473,984
38Mar 13, 2026 21:178,177132,984,11799,283,0007,020,0002,330,624
39Mar 13, 2026 21:229,453150,230,206115,894,0006,993,0002,510,848