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
Mar 12, 2026 16:33JarnoJarnoRUSTrust-1.94.0Success84,115
Mar 12, 2026 16:30JarnoJarnoRUSTrust-1.94.0Success82,269+4.96 RP
Mar 12, 2026 16:24JarnoJarnoRUSTrust-1.94.0Success85,769+23.64 RP
Mar 12, 2026 16:16JarnoJarnoRUSTrust-1.94.0Success107,585+15.48 RP
Mar 12, 2026 16:12JarnoJarnoRUSTrust-1.94.0Success137,511
Mar 12, 2026 16:11JarnoJarnoRUSTrust-1.94.0Success142,901
Mar 12, 2026 16:09JarnoJarnoRUSTrust-1.94.0Success132,745
Mar 12, 2026 16:01JarnoJarnoRUSTrust-1.94.0Success129,077+18.70 RP
Mar 12, 2026 05:26olliecrowolliecrowCPPclang++18.1.3Success6,531+121.12 RP
Mar 12, 2026 04:55olliecrowolliecrowRUSTrust-1.94.0Success8,192
Mar 12, 2026 04:39olliecrowolliecrowCPPclang++18.1.3Success7,092+71.71 RP
Mar 12, 2026 04:25olliecrowolliecrowRUSTrust-1.94.0Success7,472+113.59 RP
Mar 12, 2026 04:00olliecrowolliecrowRUSTrust-1.94.0Success8,484
Mar 12, 2026 03:51olliecrowolliecrowRUSTrust-1.94.0Error
Mar 12, 2026 03:40olliecrowolliecrowCPPclang++18.1.3Success8,165+205.79 RP
Mar 12, 2026 02:53olliecrowolliecrowCPPclang++18.1.3Success10,897
Mar 12, 2026 02:44olliecrowolliecrowRUSTrust-1.94.0Success11,864
Mar 12, 2026 02:39olliecrowolliecrowRUSTrust-1.94.0Success10,449
Mar 11, 2026 13:18JarnoJarnoRUSTrust-1.94.0Success170,146+0.12 RP
Mar 11, 2026 09:33JarnoJarnoRUSTrust-1.90.0Success170,504+6.24 RP
Mar 10, 2026 15:02KeefeKeefeCPPg++13.3.0Success112,449
Mar 10, 2026 04:58olliecrowolliecrowCPPclang++18.1.3Success10,973
Mar 3, 2026 13:26NoSIMD_C#NoSIMD_C#RUSTrust-1.93.1Success208,689+47.92 RP
Feb 21, 2026 18:05olliecrowolliecrowCPPclang++18.1.3Success10,836
Feb 21, 2026 18:00olliecrowolliecrowCPPclang++18.1.3Success9,814+28.56 RP
Feb 21, 2026 17:42olliecrowolliecrowCPPclang++18.1.3Success10,097+0.29 RP
Feb 21, 2026 17:34olliecrowolliecrowCPPclang++18.1.3Success10,100+54.30 RP
Feb 21, 2026 17:01olliecrowolliecrowCPPclang++18.1.3Success11,121
Feb 21, 2026 16:58olliecrowolliecrowCPPclang++18.1.3Success10,944
Feb 21, 2026 16:44olliecrowolliecrowCPPclang++18.1.3Success12,107
Feb 21, 2026 16:40olliecrowolliecrowCPPclang++18.1.3Success11,572
Feb 21, 2026 16:39olliecrowolliecrowCPPclang++18.1.3Success11,676
Feb 21, 2026 16:31olliecrowolliecrowCPPclang++18.1.3Success22,398
Feb 21, 2026 16:26olliecrowolliecrowCPPclang++18.1.3Success12,102
Feb 21, 2026 16:21olliecrowolliecrowCPPclang++18.1.3Success11,579
Feb 21, 2026 16:18olliecrowolliecrowCPPclang++18.1.3Success12,044
Feb 21, 2026 16:13olliecrowolliecrowCPPg++13.3.0Success14,259
Feb 21, 2026 16:11olliecrowolliecrowCPPclang++18.1.3Success12,843
Feb 21, 2026 16:06olliecrowolliecrowCPPclang++18.1.3Success49,217
Feb 21, 2026 15:58olliecrowolliecrowCPPclang++18.1.3Success12,298
Feb 21, 2026 15:47olliecrowolliecrowCPPclang++18.1.3Success10,871
Feb 21, 2026 15:38olliecrowolliecrowCPPclang++18.1.3Success11,778
Feb 21, 2026 15:38olliecrowolliecrowCPPclang++18.1.3Success10,960
Feb 21, 2026 15:34olliecrowolliecrowCPPg++13.3.0Success13,752
Feb 21, 2026 15:30olliecrowolliecrowCPPclang++18.1.3Success12,099
Feb 21, 2026 15:19olliecrowolliecrowCPPclang++18.1.3Success11,476
Feb 21, 2026 15:16olliecrowolliecrowCPPg++13.3.0Success15,046
Feb 21, 2026 15:12olliecrowolliecrowCPPclang++18.1.3Error
Feb 21, 2026 15:01olliecrowolliecrowCPPclang++18.1.3Success10,808
Feb 21, 2026 15:00olliecrowolliecrowCPPclang++18.1.3Success11,296
Feb 21, 2026 14:55olliecrowolliecrowCPPg++13.3.0Success12,698
Feb 21, 2026 14:44olliecrowolliecrowCPPg++13.3.0Success13,946
Feb 21, 2026 07:18olliecrowolliecrowCPPclang++18.1.3Success12,111
Feb 21, 2026 07:06olliecrowolliecrowCPPclang++18.1.3Success11,193
Feb 21, 2026 06:41olliecrowolliecrowCPPclang++18.1.3Success11,982
Feb 21, 2026 05:55olliecrowolliecrowCPPclang++18.1.3Success11,648
Feb 21, 2026 05:37olliecrowolliecrowCPPclang++18.1.3Success11,945
Feb 21, 2026 05:31olliecrowolliecrowCPPclang++18.1.3Success12,021
Feb 21, 2026 05:22olliecrowolliecrowCPPclang++18.1.3Success11,324
Feb 21, 2026 05:15olliecrowolliecrowCPPclang++18.1.3Success11,523
Feb 21, 2026 05:10olliecrowolliecrowCPPclang++18.1.3Success10,815
Feb 21, 2026 04:54olliecrowolliecrowCPPclang++18.1.3Success11,551
Feb 21, 2026 04:28olliecrowolliecrowCPPclang++18.1.3Success10,959
Feb 21, 2026 04:22olliecrowolliecrowCPPclang++18.1.3Success10,933
Feb 21, 2026 04:07olliecrowolliecrowCPPclang++18.1.3Success12,333
Feb 21, 2026 03:55olliecrowolliecrowCPPclang++18.1.3Success11,255
Feb 21, 2026 03:48olliecrowolliecrowCPPclang++18.1.3Success11,364
Feb 21, 2026 03:43olliecrowolliecrowCPPclang++18.1.3Success11,500
Feb 21, 2026 03:34olliecrowolliecrowCPPg++13.3.0Success11,728
Feb 21, 2026 03:23olliecrowolliecrowCPPclang++18.1.3Success10,686+63.36 RP
Feb 21, 2026 03:14olliecrowolliecrowCPPclang++18.1.3Success11,484
Feb 21, 2026 03:09olliecrowolliecrowCPPclang++18.1.3Success11,462+19.64 RP
Feb 21, 2026 03:04olliecrowolliecrowCPPclang++18.1.3Success11,726+18.50 RP
Feb 21, 2026 02:52olliecrowolliecrowCPPclang++18.1.3Success35,685
Feb 21, 2026 02:47olliecrowolliecrowCPPclang++18.1.3Success37,584
Feb 21, 2026 02:43olliecrowolliecrowCPPclang++18.1.3Success34,570
Feb 21, 2026 02:38olliecrowolliecrowCPPclang++18.1.3Success34,478
Feb 21, 2026 02:35olliecrowolliecrowCPPclang++18.1.3Success32,906
Feb 21, 2026 02:31olliecrowolliecrowCPPclang++18.1.3Success40,349
Feb 21, 2026 02:24olliecrowolliecrowCPPclang++18.1.3Success36,770
Feb 21, 2026 02:22olliecrowolliecrowCPPclang++18.1.3Success36,710
Feb 21, 2026 02:15olliecrowolliecrowCPPclang++18.1.3Success37,747
Feb 21, 2026 02:05olliecrowolliecrowCPPclang++18.1.3Success11,986+20.57 RP
Feb 21, 2026 02:02olliecrowolliecrowCPPclang++18.1.3Success12,289+6.05 RP
Feb 19, 2026 05:29Josu San MartinJosu San MartinCPPg++13.3.0Success3,488
Feb 19, 2026 05:23Josu San MartinJosu San MartinCPPg++13.3.0Success3,478
Feb 19, 2026 05:17Josu San MartinJosu San MartinRUSTrust-1.93.1Success3,638
Feb 19, 2026 05:06Josu San MartinJosu San MartinCPPg++13.3.0Success3,505
Feb 19, 2026 04:34Josu San MartinJosu San MartinRUSTrust-1.93.1Success3,562
Feb 19, 2026 04:33Josu San MartinJosu San MartinCPPg++13.3.0Success3,803
Feb 19, 2026 04:30Josu San MartinJosu San MartinRUSTrust-1.93.1Success3,436
Feb 19, 2026 04:29Josu San MartinJosu San MartinCPPg++13.3.0Success3,838
Feb 19, 2026 03:06Josu San MartinJosu San MartinRUSTrust-1.93.1Success4,003
Feb 19, 2026 03:05Josu San MartinJosu San MartinCPPg++13.3.0Success3,814
Feb 19, 2026 03:02Josu San MartinJosu San MartinRUSTrust-1.93.1Success3,606
Feb 19, 2026 03:01Josu San MartinJosu San MartinCPPg++13.3.0Success3,421
Feb 19, 2026 01:19Josu San MartinJosu San MartinCPPg++13.3.0Success3,696
Feb 19, 2026 01:18Josu San MartinJosu San MartinRUSTrust-1.93.1Success4,028
Feb 19, 2026 01:17Josu San MartinJosu San MartinRUSTrust-1.93.1Success4,244
Feb 19, 2026 01:02Josu San MartinJosu San MartinRUSTrust-1.93.1Success4,396