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
Date AuthorLanguageStatus Score
May 18, 2026 00:33M-RochatM-RochatCPPclang++18.1.3Success7,377
May 18, 2026 00:33M-RochatM-RochatCPPclang++20.1.2Success7,180
May 18, 2026 00:33M-RochatM-RochatCPPclang++17.0.6Success6,977+27.60 RP
May 18, 2026 00:31M-RochatM-RochatCPPclang++18.1.3Success7,114+142.41 RP
May 18, 2026 00:31M-RochatM-RochatCPPg++13.3.0Success7,867
May 18, 2026 00:31M-RochatM-RochatCPPg++14.2.0Success7,931
May 18, 2026 00:28M-RochatM-RochatCPPg++13.3.0Success10,746
May 18, 2026 00:28M-RochatM-RochatCPPg++13.3.0Success23,424
May 18, 2026 00:28M-RochatM-RochatCPPg++13.3.0Success14,694
May 18, 2026 00:26M-RochatM-RochatCPPg++13.3.0Success7,916+619.06 RP
May 18, 2026 00:24M-RochatM-RochatCPPg++13.3.0Success15,523+168.83 RP
May 18, 2026 00:22M-RochatM-RochatCPPg++13.3.0Success21,036+15.82 RP
May 18, 2026 00:20M-RochatM-RochatCPPg++13.3.0Success21,760+79.16 RP
May 18, 2026 00:18M-RochatM-RochatCPPg++13.3.0Success27,871
May 18, 2026 00:18M-RochatM-RochatCPPg++13.3.0Success30,016
May 18, 2026 00:16M-RochatM-RochatCPPg++13.3.0Success31,893+30.06 RP
May 18, 2026 00:16M-RochatM-RochatCPPg++13.3.0Success26,288+66.85 RP
May 18, 2026 00:14M-RochatM-RochatCPPg++13.3.0Success35,275+219.02 RP
May 17, 2026 13:24Victor MerckléVictor MerckléZIG0.16.0Success1,673+3'187.64 RP
May 17, 2026 09:29olliecrowolliecrowRUSTrust-1.94.0Success5,161
May 17, 2026 08:11M-RochatM-RochatCPPg++13.3.0Success158,850
May 17, 2026 08:03M-RochatM-RochatCPPg++13.3.0Success155,289
May 17, 2026 07:21M-RochatM-RochatCPPg++14.2.0Success201,684
May 17, 2026 06:31M-RochatM-RochatCPPg++14.2.0Success231,592
May 17, 2026 06:30M-RochatM-RochatCPPg++14.2.0Success224,454
May 17, 2026 06:30M-RochatM-RochatCPPg++14.2.0Success222,967
May 16, 2026 23:56M-RochatM-RochatCPPg++13.3.0Error
May 16, 2026 23:56M-RochatM-RochatCPPg++13.3.0Error
May 16, 2026 23:56M-RochatM-RochatCPPg++13.3.0Success156,019
May 16, 2026 20:34M-RochatM-RochatCPPg++13.3.0Success202,033
May 16, 2026 19:45M-RochatM-RochatCPPg++13.3.0Success155,130+4.02 RP
May 16, 2026 19:41M-RochatM-RochatCPPg++13.3.0Error
May 16, 2026 19:40M-RochatM-RochatCPPg++13.3.0Error
May 16, 2026 19:09M-RochatM-RochatCPPg++13.3.0Success222,088
May 16, 2026 19:06M-RochatM-RochatCPPg++13.3.0Error
May 16, 2026 19:03M-RochatM-RochatCPPg++13.3.0Error
May 16, 2026 18:12olliecrowolliecrowZIG0.14.0Success5,503
May 16, 2026 16:40M-RochatM-RochatCPPg++13.3.0Success169,176
May 16, 2026 16:37M-RochatM-RochatCPPg++13.3.0Success175,859
May 16, 2026 16:35M-RochatM-RochatCPPg++13.3.0Success165,452+16.87 RP
May 16, 2026 16:16M-RochatM-RochatCPPg++13.3.0Success229,506+9.47 RP
May 16, 2026 15:50M-RochatM-RochatCPPg++13.3.0Success555,882
May 16, 2026 13:19M-RochatM-RochatCPPg++13.3.0Success293,272+0.16 RP
May 16, 2026 13:16M-RochatM-RochatCPPg++13.3.0Success308,398
May 16, 2026 13:13M-RochatM-RochatCPPg++14.2.0Success294,632+0.15 RP
May 16, 2026 13:11M-RochatM-RochatCPPg++13.3.0Success304,807
May 16, 2026 13:08M-RochatM-RochatCPPg++13.3.0Success310,409
May 16, 2026 13:06M-RochatM-RochatCPPg++13.3.0Success299,283
May 16, 2026 13:02M-RochatM-RochatCPPg++13.3.0Success296,117
May 16, 2026 13:01M-RochatM-RochatCPPg++13.3.0Success295,981+13.21 RP
May 16, 2026 10:42olliecrowolliecrowZIG0.14.0Success5,538
May 16, 2026 00:37olliecrowolliecrowRUSTrust-1.94.0Success5,690+5.00 RP
May 15, 2026 22:32olliecrowolliecrowGOgo1.26.2Success6,312
May 15, 2026 19:28M-RochatM-RochatCPPg++13.3.0Success390,945+25.58 RP
May 15, 2026 19:27M-RochatM-RochatCPPg++13.3.0Error
May 15, 2026 19:23M-RochatM-RochatCPPg++13.3.0Error
May 14, 2026 17:11Josu San MartinJosu San MartinCSHARP9.0.13Error
May 7, 2026 14:07Victor MerckléVictor MerckléCPPclang++18.1.3Success5,829
May 7, 2026 11:36Victor MerckléVictor MerckléCPPg++14.2.0Success3,631,248
May 7, 2026 11:20Victor MerckléVictor MerckléCPPclang++18.1.3Success5,844
May 7, 2026 11:16Victor MerckléVictor MerckléCPPclang++18.1.3Success6,551
May 7, 2026 11:09Victor MerckléVictor MerckléCPPclang++18.1.3Success12,653
May 7, 2026 09:36Victor MerckléVictor MerckléCPPclang++18.1.3Success5,398
May 7, 2026 09:33Victor MerckléVictor MerckléCPPclang++18.1.3Success1,992
May 7, 2026 09:13Victor MerckléVictor MerckléCPPclang++18.1.3Error
May 7, 2026 09:11Victor MerckléVictor MerckléCPPclang++18.1.3Error
May 7, 2026 09:04Victor MerckléVictor MerckléCPPclang++18.1.3Error
May 7, 2026 08:57Victor MerckléVictor MerckléCPPclang++18.1.3Error
May 7, 2026 06:56Victor MerckléVictor MerckléCPPg++14.2.0Error
May 6, 2026 15:26Dominique GarmierDominique GarmierCPPg++10.5.0Error
May 6, 2026 15:25Dominique GarmierDominique GarmierCPPg++10.5.0Error
May 6, 2026 15:23Dominique GarmierDominique GarmierCPPg++10.5.0Success16,625
May 6, 2026 12:34olliecrowolliecrowGOgo1.26.2Success6,650
May 6, 2026 11:23olliecrowolliecrowZIG0.14.0Success6,030
May 6, 2026 10:06olliecrowolliecrowRUSTrust-1.94.0Success5,022
May 6, 2026 09:04olliecrowolliecrowGOgo1.26.2Error
May 6, 2026 08:43olliecrowolliecrowCSHARP10.0.7Success5,394
May 6, 2026 08:38olliecrowolliecrowCSHARP9.0.15Success5,590
May 6, 2026 05:01olliecrowolliecrowCSHARP10.0.7Success5,488
May 6, 2026 02:45olliecrowolliecrowRUSTrust-1.94.0Success7,433
May 6, 2026 00:35olliecrowolliecrowRUSTrust-1.94.0Success5,247
May 5, 2026 20:51olliecrowolliecrowRUSTrust-1.94.0Success5,394
May 5, 2026 18:49olliecrowolliecrowCSHARP10.0.7Success5,550
May 5, 2026 18:37olliecrowolliecrowCSHARP10.0.7Success5,540
May 5, 2026 18:30olliecrowolliecrowCSHARP9.0.15Success5,926
May 5, 2026 18:25olliecrowolliecrowCSHARP9.0.15Error
May 5, 2026 18:15olliecrowolliecrowCPPclang++18.1.3Success5,309
May 5, 2026 17:55olliecrowolliecrowCPPg++10.5.0Success5,180
May 5, 2026 17:43olliecrowolliecrowGOgo1.26.2Success6,069
May 5, 2026 17:35olliecrowolliecrowGOgo1.26.2Error
May 5, 2026 15:46olliecrowolliecrowGOgo1.26.2Error
May 5, 2026 15:41olliecrowolliecrowGOgo1.26.2Error
May 5, 2026 15:11olliecrowolliecrowCSHARP9.0.15Success5,609
May 5, 2026 13:40Victor MerckléVictor MerckléZIG0.16.0Error
May 5, 2026 13:22Victor MerckléVictor MerckléCSHARP10.0.7Error
May 5, 2026 13:06Victor MerckléVictor MerckléZIG0.16.0Error
May 5, 2026 12:47Victor MerckléVictor MerckléCSHARP10.0.7Success1,915
May 5, 2026 12:41Victor MerckléVictor MerckléZIG0.16.0Error
May 5, 2026 09:50Victor MerckléVictor MerckléCPPg++14.2.0Error
May 5, 2026 09:39Victor MerckléVictor MerckléCPPclang++18.1.3Error