Skip to content

Claude Sonnet 5.5 (effort default (no --effort flag) · thinking on) on Limit order book matching engine with self-trade prevention, FOK and modify priority

AClaude Sonnet 5.5default · thinking on · Claude Code 2.1.299 (headless -p) · cloud · 2026-10-20 · by @bobsiopener

Trust 80%Fully autonomoussuccess · first try
Estimated cost
$0.12
Wall time
43s
Human step-ins
0
Outcome
Pass

Compare with other models on this task →

Summary

Exact prompt

# Limit order book matching engine `input.json` has `events` (a list, processed in order, index = position) and `bbo_every` k. Write `solve.py` (Python 3 standard library only); `python solve.py input.json answer.json`. Fresh inputs are generated, including one with **60,000 events that must finish within 20 seconds** (other runs: 30 s). Prices and quantities are integers (ticks/lots); all arithmetic is exact. ## Events - `{"op": "new", "id", "side": "B"|"S", "type": "LMT"|"MKT", "qty", "px" (LMT only), "tif": "GTC"|"IOC"|"FOK" (LMT only, default GTC), "owner" (default ""), "stp": "cancel_resting"|"cancel_incoming" (default cancel_resting), "post_only" (default false)}` - `{"op": "cancel", "id"}` - `{"op": "modify", "id", "qty"?, "px"?}` (a missing field keeps the current value; `qty` is the new *remaining* quantity) - anything else: reject `bad_op`. ## Rules 1. A reject is recorded as `{"event": index, "id": event's id or null, "reason"}` and the event has no other effect. 2. New-order validation, first failure wins: `bad_id` (id not a non-empty string), `duplicate_id` (id already used by ANY earlier new event, including rejected ones once they passed `bad_id`), `bad_side`, `bad_type`, `bad_qty` (not a positive integer; booleans and floats are invalid), `bad_price` (LMT only: not a positive integer), `bad_tif` (LMT only). For MKT orders `px` and `tif` are ignored and the order behaves as IOC. 3. Then, in order: a `post_only` LMT that would cross the opposite best is rejected `post_only_would_cross`; a MKT order with an empty opposite side is rejected `no_liquidity`; a FOK order is rejected `fok_unfilled` if the fill check (rule 8) fails. 4. Matching: an incoming order trades against the opposite side in price-time priority (best price first; within a price, earlier arrival first) while it has quantity left and the best opposite price is acceptable (buy: ask <= limit; sell: bid >= limit; MKT: any). Each trade executes at the **resting** order's price for min(both remaining). 5. Self-trade prevention (same `owner` on both sides), using the **incoming** order's `stp`: `cancel_resting` removes that resting order (no trade) and matching continues; `cancel_incoming` cancels the incoming order's remaining quantity at that point (trades already done stand; it never rests). 6. After matching, a GTC LMT remainder rests on the book (as a new arrival). IOC/FOK/MKT remainders are discarded. 7. Trades: `{"seq": 1, 2, ..., "buy_id", "sell_id", "px", "qty", "aggressor": side of the incoming order}`. 8. FOK fill check: walk the opposite resting orders in priority order over acceptable prices; skip orders of the same owner if `stp` is `cancel_resting`; **stop** at the first same-owner order if `stp` is `cancel_incoming`. Pass if the summed quantity of the walked other-owner orders >= qty. 9. `cancel`: if the id is not a live resting order, reject `unknown_order`; otherwise remove it. 10. `modify`: not live -> `unknown_order`. New qty must be an integer >= 0 and new px a positive integer, else `bad_modify`. qty 0 -> remove the order. Same price and new qty <= current remaining -> update in place, **keeping time priority**. Otherwise (price change or qty increase) the order **loses priority**: it is taken off the book and re-entered as an incoming GTC LMT with the same id, owner and stp (no post-only, no duplicate-id check, no FOK), which may trade (rule 4-5) and rests last in time at its price. 11. After every k-th event (event index i with (i+1) % k == 0), append `[best_bid, best_ask]` to `bbo` (null for an empty side). ## answer.json `{"trades": [...], "rejects": [...], "bbo": [...], "book": {"bids": [[px, total_remaining, order_count], ...], "asks": [...]}` (top 5 price levels, bids high to low, asks low to high) `, "positions": {owner: net bought minus sold}, "cash": {owner: sum of sell px*qty minus buy px*qty}` (owners that traded, sorted by name) `, "volume": total traded qty, "vwap": volume-weighted price rounded to 4 decimals or null, "resting_orders": live resting orders at the end}` ## Scoring Hidden checks (partial credit = fraction passed; all must pass): `validation_rejects` (the rule-2/9/10 reasons in order), `all_rejects`, `first_50_trades`, `all_trades`, `bbo_path`, `final_book_and_counts`, `positions_cash_vwap` on the given input; `fresh_run_1`, `fresh_run_2` (every key) on fresh inputs; `big_input_60k_events_20s` (every key, 20-second limit). vwap within 0.0001, everything else exact.

One misplaced priority (modify), STP mode, or FOK-walk rule shifts every later trade and BBO; a list-based book times out on 60k events. Original benchmark task written for usecaserank.com (not based on a specific public post). Headless, offline run on a reproducible fixture. Each run's notes say how its cost was measured (estimates are marked).

Success criteria: 1. validation_rejects 2. all_rejects 3. first_50_trades 4. all_trades 5. bbo_path 6. final_book_and_counts 7. positions_cash_vwap 8. fresh_run_1 9. fresh_run_2 10. big_input_60k_events_20s

Setup notes: Use Case Scout batch 12 case m02-order-book-matching (offline, synthetic fixture). Prepared with batch12/prepare.sh; hidden key/checker kept outside the agent's work dir (temp dir during the run). Prompt = TASK.md verbatim. Scored with the case's scorer: `python score.py WORKDIR KEYDIR` (python3, run from the case dir). Tools: Read/Write/Edit/Glob/Grep/Bash, web disabled. Single run, no retries. 1-min load average at scoring 0.18 (8 cores). Claude Code's own reported cost for claude-sonnet-5.5: $0.117536. Score: 10/10. Cost is an ESTIMATE: measured tokens x pricing.json list price (Claude Pro subscription, nothing billed); input_tokens include cache reads and writes. Single run.

Estimated cost List-price estimate; not actually billed.

Metrics

Estimated cost
$0.12
Wall time
43s
Human step-ins
0
Turns
4
Model usage
ModelInput tokOutput tokCost
AClaude Sonnet 5.5anthropic/claude-sonnet-5.5effort default (no --effort flag) · thinking on89,5445,553$0.12

Reproduce this run

  1. Use the use case prompt on the use case page.
  2. Same setup: Claude Sonnet 5.5 (anthropic/claude-sonnet-5.5, effort default (no --effort flag) · thinking on) via Claude Code 2.1.299 (headless -p), cloud.
  3. It counts as a success only if it meets every success criterion: 1. validation_rejects 2. all_rejects 3. first_50_trades 4. all_trades 5. bbo_path 6. final_book_and_counts 7. positions_cash_vwap 8. fresh_run_1 9. fresh_run_2 10. big_input_60k_events_20s
  4. Log model, tokens, wall time, human step-ins and the evidence log, then submit it as a reproduction. A different model? Submit a head-to-head rerun.

How runs are scored: Methodology.

Was this useful?

⇄ Rerun on another model

Automated checks

Trust 80% comes from these checks (how Trust % works).

Evidence log
[
 {
  "duration_api_ms": 42372,
  "stop_reason": "end_turn",
  "session_id": "[REDACTED]",
  "total_cost_usd": 0.11753569999999999,
  "usage": {
   "input_tokens": 8,
   "cache_creation_input_tokens": 13599,
   "cache_read_input_tokens": 75937,
   "output_tokens": 5553,
   "output_tokens_details": {
    "thinking_tokens": 1709
   },
   "server_tool_use": {
    "web_search_requests": 0,
    "web_fetch_requests": 0
   },
   "service_tier": "standard",
   "cache_creation": {
    "ephemeral_1h_input_tokens": 13599,
    "ephemeral_5m_input_tokens": 0
   },
   "inference_geo": "global",
   "iterations": [
    {
     "input_tokens": 2,
     "output_tokens": 453,
     "cache_read_input_tokens": 22388,
     "cache_creation_input_tokens": 3750,
     "cache_creation": {
      "ephemeral_5m_input_tokens": 0,
      "ephemeral_1h_input_tokens": 3750
     },
     "type": "message"
    }
   ],
   "speed": "standard",
   "fallback_credit": null
  },
  "modelUsage": {
   "claude-sonnet-5-5": {
    "inputTokens": 8,
    "outputTokens": 5553,
    "cacheReadInputTokens": 75937,
    "cacheCreationInputTokens": 13599,
    "webSearchRequests": 0,
    "costUSD": 0.11753569999999999,
    "contextWindow": 1000000,
    "maxOutputTokens": 128000,
    "thinkingTokens": 1709,
    "canonicalModel": "claude-sonnet-5-5",
    "provider": "firstParty",
    "costBasis": "list"
   }
  },
  "permission_denials": [],
  "terminal_reason": "completed",
  "fast_mode_state": "off",
  "fast_mode_disabled_reason": "sdk_opt_in_required",
  "subagent_stats": {
   "spawned": 0,
   "requested": {
    "background": 0,
    "foreground": 0,
    "unset": 0
   },
   "started_in_background": 0,
   "max_depth": 0,
   "spawned_by_subagents": 0,
   "completed": 0,
   "failed": 0,
   "killed": {
    "parent": 0,
    "user": 0,
    "system": 0
   },
   "refused": {
    "depth_limit": 0,
    "concurrency_limit": 0,
    "budget": 0
   },
   "by_type": {}
  },
  "safety_stops": 0,
  "is_error": false,
  "num_turns": 4,
  "subtype": "success",
  "api_error_status": null,
  "result": "`solve.py` is written and runs on the given input in about 0.02 s. I haven't checked it against any expected output, so I can't say whether the hidden checks pass.\n\nOn the 600-event `input.json` it produced 142 trades, a final book, positions for owners A\u2013E, a VWAP of 996.4463 and 95 resting orders. I haven't run a 60,000-event input. The design is cheap per event: price levels are kept in sorted lists with a queue per level, so I expect it to be well inside 20 seconds.\n\nI read one ambiguous point literally. The default owner `\"\"` counts as an owner, so two orders that both omit `owner` would trigger self-trade prevention. In this input only A\u2013E appear in `positions`, so no unowned order traded.\n\nTwo other guesses:\n- **Reject `id`:** a reject's `id` is the event's raw `id` field, or null if it has none. That includes a bad id like `5` or `\"\"`.\n- **Unknown ops:** events with an unrecognised `op` get `bad_op`. This input has `replace` and `amend` events, and they are rejected that way.",
  "ttft_ms": 14566,
  "type": "result",
  "duration_ms": 42763,
  "uuid": "[REDACTED]",
  "ttft_stream_ms": 3703,
  "time_to_request_ms": 230,
  "first_content_frame_ms": 3704,
  "queued_turn_count": 0,
  "result_index": 0
 }
]

Get new runs and ranking changes weekly