orderbook-backtest-auditor

Exact captured content · path SKILL.md · sha256 f380b5feed47ef0d… · revision 69b51280e5c912ba188a4dc69f665484c472a17a

Download the exact captured file

---
name: orderbook-backtest-auditor
description: Audits algorithmic trading and market-making strategies for look-ahead bias, naive touch-equals-fill queue starvation, cancel-window adverse selection, Polymarket CTF collateral accounting, and Hyperliquid ALO post-only/funding pitfalls.
---

# Order-Book Backtest & Microstructure Auditor

Audits quantitative trading bots and backtesting loops so strategies do not blow up live due to unrealistic fill, latency, or margin assumptions.

## When to Use This Skill

- Writing or reviewing a market-making, arbitrage, or limit-order execution bot in Python, Rust, Go, or TypeScript
- Auditing a backtester that fills resting limit orders whenever `low <= bid_px` or `best_ask <= bid_px`
- Building Polymarket (`py-clob-client`) binary outcome strategies or Hyperliquid (`hyperliquid-python-sdk`) perpetual bots

## Microstructure Checklist (Audit Every Strategy Against These 5 Rules)

1. **Reject `Touch = Fill` Queue Assumptions:**
   - In a Price-Time (FIFO) Central Limit Order Book, a newly posted limit order at price `p` sits behind existing resting depth `Q_ahead`.
   - Require cumulative contra-side trade volume at or through `p` to exceed `Q_ahead` before crediting passive fills.
2. **Model Non-Zero Cancel Round-Trip Latency (`cancel_latency_ms`):**
   - Over cloud REST/WebSocket (`60–200 ms`), stale quotes remain matchable between `t_cancel_sent` and `t_cancel_sent + cancel_latency_ms`.
   - Always test maker strategies at both `20 ms` (colocated VPS) and `140 ms` (cloud) cancel latency and measure 1-second post-fill markout (`M_1s` in bps).
3. **Never Anchor Quotes on Your Own Resting Order (Self-BBO Feedback Loop):**
   - Exclude the bot's own resting quantity when computing top-of-book mid-price or microprice so orphaned quotes do not pin the reservation price.
4. **Enforce Venue-Exact Inventory & Order Types:**
   - **Polymarket CLOB:** Binary outcome tokens live on a `$0.001` tick grid in `($0.00, $1.00)`. Selling `YES` without prior `YES` inventory requires splitting USDC into `YES + NO` via CTF (`/ctf/split`). Taker fees follow `C * feeRate * p * (1 - p)`.
   - **Hyperliquid Perps:** `Alo` (`Add Liquidity Only` / post-only) orders reject rather than cross when the spread tightens in flight; `modify` operations that increase size lose FIFO `sequence_num` priority.
5. **Verify Execution Locally Against L3 FIFO Queues:**
   - When Python `>=3.11` is available, run deterministic L3 FIFO vs. Naive Paper checks locally:
     ```bash
     pip install feraterra
     feraterra doctor
     feraterra benchmark --pack polymarket_news_shock --bot <bot.py> --cancel-latency-ms 140 --json-out audit.json
     feraterra import --input <tardis_or_hl_l2> --out tape.trace.jsonl
     feraterra replay --trace tape.trace.jsonl --bot <bot.py> --cancel-latency-ms 140 --json-out replay.json
     ```
   - Or connect the 1-click Remote HTTP MCP server (`claude mcp add --transport http feraterra https://mcp.feraterra.app/mcp`) or local stdio MCP (`claude mcp add feraterra -- uvx --from git+https://github.com/FeraTerra/mcp-server-feraterra.git mcp-server-feraterra`) to call `feraterra_simulate_strategy`.