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
Feb 19, 2026 01:01Josu San MartinJosu San MartinCPPg++13.3.0Success3,687
Feb 19, 2026 01:00Josu San MartinJosu San MartinRUSTrust-1.93.1Success3,839
Feb 19, 2026 00:34Josu San MartinJosu San MartinRUSTrust-1.93.1Success4,315
Feb 19, 2026 00:30Josu San MartinJosu San MartinRUSTrust-1.93.1Success4,168
Feb 19, 2026 00:17Josu San MartinJosu San MartinRUSTrust-1.93.1Success4,017
Feb 19, 2026 00:16Josu San MartinJosu San MartinCPPg++13.3.0Success3,545
Feb 18, 2026 23:44Josu San MartinJosu San MartinRUSTrust-1.92.0Success4,340
Feb 18, 2026 07:17olliecrowolliecrowCPPclang++18.1.3Success12,381+229.29 RP
Feb 18, 2026 06:57olliecrowolliecrowCPPclang++18.1.3Success18,424
Feb 18, 2026 06:49olliecrowolliecrowCPPclang++18.1.3Success19,114
Feb 18, 2026 06:38olliecrowolliecrowCPPclang++18.1.3Success21,405
Feb 18, 2026 06:17olliecrowolliecrowCPPg++13.3.0Success18,383
Feb 18, 2026 06:07olliecrowolliecrowCPPclang++18.1.3Success19,324
Feb 18, 2026 05:56olliecrowolliecrowCPPclang++18.1.3Success20,339
Feb 18, 2026 05:48olliecrowolliecrowCPPclang++18.1.3Success20,441
Feb 18, 2026 05:27olliecrowolliecrowCPPclang++18.1.3Success17,655
Feb 18, 2026 05:21olliecrowolliecrowCPPclang++18.1.3Success18,675
Feb 18, 2026 05:15olliecrowolliecrowCPPclang++18.1.3Success18,829
Feb 18, 2026 05:07olliecrowolliecrowCPPclang++18.1.3Success22,938
Feb 18, 2026 04:58olliecrowolliecrowCPPclang++18.1.3Success18,412
Feb 18, 2026 04:53olliecrowolliecrowCPPclang++18.1.3Success22,044
Feb 18, 2026 04:45olliecrowolliecrowCPPclang++18.1.3Success19,981
Feb 18, 2026 04:39olliecrowolliecrowCPPclang++18.1.3Success17,289+38.71 RP
Feb 18, 2026 04:26olliecrowolliecrowCPPclang++18.1.3Success19,885
Feb 18, 2026 04:17olliecrowolliecrowCPPclang++18.1.3Success18,529+0.12 RP
Feb 18, 2026 04:11olliecrowolliecrowCPPclang++18.1.3Success20,498
Feb 18, 2026 04:03olliecrowolliecrowCPPclang++18.1.3Success18,533+1.10 RP
Feb 18, 2026 03:56olliecrowolliecrowCPPclang++18.1.3Success21,040
Feb 18, 2026 03:47olliecrowolliecrowCPPclang++18.1.3Success19,775
Feb 18, 2026 03:35olliecrowolliecrowCPPclang++18.1.3Success20,198
Feb 18, 2026 03:22olliecrowolliecrowCPPclang++18.1.3Success18,571+0.06 RP
Feb 18, 2026 03:15olliecrowolliecrowCPPg++13.3.0Success20,511
Feb 18, 2026 02:52olliecrowolliecrowCPPclang++18.1.3Success18,861
Feb 18, 2026 02:42olliecrowolliecrowCPPclang++18.1.3Success18,573+99.59 RP
Feb 18, 2026 02:32olliecrowolliecrowCPPclang++18.1.3Success22,788+33.71 RP
Feb 18, 2026 02:22olliecrowolliecrowCPPclang++18.1.3Success24,684+74.14 RP
Feb 18, 2026 02:16olliecrowolliecrowCPPclang++18.1.3Success30,213+27.36 RP
Feb 18, 2026 02:10olliecrowolliecrowCPPclang++18.1.3Success37,389
Feb 18, 2026 01:54olliecrowolliecrowCPPclang++18.1.3Success40,049
Feb 18, 2026 01:48olliecrowolliecrowCPPclang++18.1.3Success38,277
Feb 18, 2026 01:40olliecrowolliecrowCPPclang++18.1.3Success32,936+38.33 RP
Feb 18, 2026 01:27olliecrowolliecrowCPPclang++18.1.3Success37,695+76.22 RP
Feb 18, 2026 01:12olliecrowolliecrowCPPclang++18.1.3Success52,891+11.67 RP
Feb 18, 2026 01:08olliecrowolliecrowCPPclang++18.1.3Success56,369+2.68 RP
Feb 18, 2026 01:04olliecrowolliecrowCPPg++13.3.0Success57,232+28.47 RP
Feb 18, 2026 01:00olliecrowolliecrowCPPg++13.3.0Success68,371+10.29 RP
Feb 17, 2026 22:34olliecrowolliecrowCPPclang++18.1.3Success73,546+10.00 RP
Feb 17, 2026 22:26olliecrowolliecrowCPPclang++18.1.3Success79,382+80.93 RP
Feb 17, 2026 22:19olliecrowolliecrowCPPg++13.3.0Success222,024+2.12 RP
Feb 17, 2026 22:10olliecrowolliecrowCPPg++13.3.0Success233,008+42.92 RP
Feb 17, 2026 22:05olliecrowolliecrowCPPg++13.3.0Error
Feb 17, 2026 21:55olliecrowolliecrowCPPg++13.3.0Error
Feb 7, 2026 22:53lipapipalipapipaCPPg++13.3.0Error
Feb 7, 2026 22:53lipapipalipapipaCPPg++13.3.0Success71,639
Feb 7, 2026 22:53lipapipalipapipaCPPg++13.3.0Success104,352
Feb 7, 2026 22:53lipapipalipapipaCPPg++13.3.0Success65,701
Feb 7, 2026 22:53lipapipalipapipaCPPg++13.3.0Success81,375
Feb 7, 2026 21:32lipapipalipapipaCPPg++13.3.0Success67,617
Feb 7, 2026 21:32lipapipalipapipaCPPg++13.3.0Success63,251
Feb 7, 2026 21:31lipapipalipapipaCPPg++13.3.0Error
Feb 7, 2026 21:31lipapipalipapipaCPPg++13.3.0Success65,489
Feb 7, 2026 21:28lipapipalipapipaCPPg++13.3.0Success63,236
Feb 7, 2026 20:35lipapipalipapipaCPPg++13.3.0Error
Feb 7, 2026 19:27lipapipalipapipaCPPg++13.3.0Success39,187+198.49 RP
Feb 7, 2026 17:48lipapipalipapipaCPPg++13.3.0Success176,389+23.75 RP
Feb 7, 2026 17:34lipapipalipapipaCPPg++13.3.0Success303,538+32.94 RP
Jan 25, 2026 23:15Alexey KalmykovAlexey KalmykovCPPg++13.3.0Error
Jan 25, 2026 23:02Alexey KalmykovAlexey KalmykovCPPg++13.3.0Error
Jan 25, 2026 22:54Alexey KalmykovAlexey KalmykovCPPg++13.3.0Error
Jan 25, 2026 22:47Alexey KalmykovAlexey KalmykovCPPg++13.3.0Error
Jan 25, 2026 22:42Alexey KalmykovAlexey KalmykovCPPg++13.3.0Error
Jan 18, 2026 04:39Josu San MartinJosu San MartinCPPg++13.3.0Error
Jan 7, 2026 05:30Josu San MartinJosu San MartinGOgo1.25.5Success3,774+1'465.72 RP
Jan 1, 2026 01:14Josu San MartinJosu San MartinRUSTrust-1.92.0Success4,279
Dec 31, 2025 16:25Aniruddha DebAniruddha DebCPPg++13.3.0Error
Dec 31, 2025 15:26Aniruddha DebAniruddha DebCPPg++13.3.0Success49,994
Dec 31, 2025 15:22Aniruddha DebAniruddha DebCPPg++13.3.0Success47,419+2.82 RP
Dec 31, 2025 15:22Aniruddha DebAniruddha DebCPPg++13.3.0Error
Dec 31, 2025 15:03Josu San MartinJosu San MartinRUSTrust-1.92.0Error
Dec 31, 2025 14:55Josu San MartinJosu San MartinRUSTrust-1.92.0Success4,048
Dec 31, 2025 14:47Josu San MartinJosu San MartinRUSTrust-1.92.0Success31,539
Dec 31, 2025 14:17Aniruddha DebAniruddha DebCPPg++13.3.0Success75,535
Dec 31, 2025 14:13Aniruddha DebAniruddha DebCPPg++13.3.0Success67,438
Dec 31, 2025 14:11Aniruddha DebAniruddha DebCPPg++13.3.0Error
Dec 31, 2025 13:42Aniruddha DebAniruddha DebCPPg++13.3.0Success94,166
Dec 31, 2025 13:35Aniruddha DebAniruddha DebCPPg++13.3.0Success96,360
Dec 31, 2025 13:32Aniruddha DebAniruddha DebCPPg++13.3.0Success54,152
Dec 31, 2025 13:29Aniruddha DebAniruddha DebCPPg++13.3.0Success297,663
Dec 31, 2025 13:09Aniruddha DebAniruddha DebCPPg++13.3.0Success62,194
Dec 31, 2025 12:15Aniruddha DebAniruddha DebCPPg++13.3.0Success60,740
Dec 31, 2025 12:12Aniruddha DebAniruddha DebCPPg++13.3.0Success48,062+1.88 RP
Dec 31, 2025 10:38KeefeKeefeCPPg++13.3.0Success107,632
Dec 31, 2025 03:02Josu San MartinJosu San MartinRUSTrust-1.92.0Success4,377
Dec 31, 2025 01:07Josu San MartinJosu San MartinCPPg++13.3.0Success3,759
Dec 31, 2025 00:50yenw0dyenw0dCPPg++13.3.0Success4,042
Dec 31, 2025 00:37Josu San MartinJosu San MartinCPPg++13.3.0Success3,575
Dec 30, 2025 23:42Josu San MartinJosu San MartinCPPg++13.3.0Success3,934
Dec 30, 2025 22:49Josu San MartinJosu San MartinCPPg++13.3.0Success3,685
Dec 30, 2025 22:38Josu San MartinJosu San MartinRUSTrust-1.92.0Success4,418
Dec 30, 2025 20:42Josu San MartinJosu San MartinCPPg++13.3.0Success3,477