Skip to main content
aifinhub

Worked example

Running the shipped order-book-replay engine on the input below produces exactly this output. Continuous integration recomputes it against the engine bundle on every build, so these numbers cannot drift from the code.

Input

{
  "tool": "order-book-replay",
  "price": 0,
  "size": 0,
  "depth_bps": 10,
  "snapshots": [
    {
      "t": 0,
      "bids": [
        {
          "price": 100.01,
          "size": 200
        },
        {
          "price": 100,
          "size": 350
        },
        {
          "price": 99.99,
          "size": 500
        },
        {
          "price": 99.98,
          "size": 650
        },
        {
          "price": 99.97,
          "size": 800
        }
      ],
      "asks": [
        {
          "price": 100.03,
          "size": 180
        },
        {
          "price": 100.04,
          "size": 320
        },
        {
          "price": 100.05,
          "size": 460
        },
        {
          "price": 100.06,
          "size": 600
        },
        {
          "price": 100.07,
          "size": 740
        }
      ]
    },
    {
      "t": 500,
      "bids": [
        {
          "price": 100.01,
          "size": 250
        },
        {
          "price": 100,
          "size": 400
        },
        {
          "price": 99.99,
          "size": 550
        },
        {
          "price": 99.98,
          "size": 700
        },
        {
          "price": 99.97,
          "size": 850
        }
      ],
      "asks": [
        {
          "price": 100.03,
          "size": 220
        },
        {
          "price": 100.04,
          "size": 360
        },
        {
          "price": 100.05,
          "size": 500
        },
        {
          "price": 100.06,
          "size": 640
        },
        {
          "price": 100.07,
          "size": 780
        }
      ]
    },
    {
      "t": 1000,
      "bids": [
        {
          "price": 100.03,
          "size": 300
        },
        {
          "price": 100.02,
          "size": 450
        },
        {
          "price": 100.01,
          "size": 600
        },
        {
          "price": 100,
          "size": 750
        },
        {
          "price": 99.99,
          "size": 900
        }
      ],
      "asks": [
        {
          "price": 100.05,
          "size": 260
        },
        {
          "price": 100.06,
          "size": 400
        },
        {
          "price": 100.07,
          "size": 540
        },
        {
          "price": 100.08,
          "size": 680
        },
        {
          "price": 100.09,
          "size": 820
        }
      ]
    },
    {
      "t": 1500,
      "bids": [
        {
          "price": 100.03,
          "size": 200
        },
        {
          "price": 100.02,
          "size": 350
        },
        {
          "price": 100.01,
          "size": 500
        },
        {
          "price": 100,
          "size": 650
        },
        {
          "price": 99.99,
          "size": 800
        }
      ],
      "asks": [
        {
          "price": 100.05,
          "size": 300
        },
        {
          "price": 100.06,
          "size": 440
        },
        {
          "price": 100.07,
          "size": 580
        },
        {
          "price": 100.08,
          "size": 720
        },
        {
          "price": 100.09,
          "size": 860
        }
      ]
    },
    {
      "t": 2000,
      "bids": [
        {
          "price": 100.03,
          "size": 250
        },
        {
          "price": 100.02,
          "size": 400
        },
        {
          "price": 100.01,
          "size": 550
        },
        {
          "price": 100,
          "size": 700
        },
        {
          "price": 99.99,
          "size": 850
        }
      ],
      "asks": [
        {
          "price": 100.05,
          "size": 180
        },
        {
          "price": 100.06,
          "size": 320
        },
        {
          "price": 100.07,
          "size": 460
        },
        {
          "price": 100.08,
          "size": 600
        },
        {
          "price": 100.09,
          "size": 740
        }
      ]
    },
    {
      "t": 2500,
      "bids": [
        {
          "price": 100.04,
          "size": 300
        },
        {
          "price": 100.03,
          "size": 450
        },
        {
          "price": 100.02,
          "size": 600
        },
        {
          "price": 100.01,
          "size": 750
        },
        {
          "price": 100,
          "size": 900
        }
      ],
      "asks": [
        {
          "price": 100.06,
          "size": 220
        },
        {
          "price": 100.07,
          "size": 360
        },
        {
          "price": 100.08,
          "size": 500
        },
        {
          "price": 100.09,
          "size": 640
        },
        {
          "price": 100.1,
          "size": 780
        }
      ]
    },
    {
      "t": 3000,
      "bids": [
        {
          "price": 100.05,
          "size": 200
        },
        {
          "price": 100.04,
          "size": 350
        },
        {
          "price": 100.03,
          "size": 500
        },
        {
          "price": 100.02,
          "size": 650
        },
        {
          "price": 100.01,
          "size": 800
        }
      ],
      "asks": [
        {
          "price": 100.07,
          "size": 260
        },
        {
          "price": 100.08,
          "size": 400
        },
        {
          "price": 100.09,
          "size": 540
        },
        {
          "price": 100.1,
          "size": 680
        },
        {
          "price": 100.11,
          "size": 820
        }
      ]
    },
    {
      "t": 3500,
      "bids": [
        {
          "price": 100.06,
          "size": 250
        },
        {
          "price": 100.05,
          "size": 400
        },
        {
          "price": 100.04,
          "size": 550
        },
        {
          "price": 100.03,
          "size": 700
        },
        {
          "price": 100.02,
          "size": 850
        }
      ],
      "asks": [
        {
          "price": 100.08,
          "size": 300
        },
        {
          "price": 100.09,
          "size": 440
        },
        {
          "price": 100.1,
          "size": 580
        },
        {
          "price": 100.11,
          "size": 720
        },
        {
          "price": 100.12,
          "size": 860
        }
      ]
    },
    {
      "t": 4000,
      "bids": [
        {
          "price": 100.05,
          "size": 300
        },
        {
          "price": 100.04,
          "size": 450
        },
        {
          "price": 100.03,
          "size": 600
        },
        {
          "price": 100.02,
          "size": 750
        },
        {
          "price": 100.01,
          "size": 900
        }
      ],
      "asks": [
        {
          "price": 100.07,
          "size": 180
        },
        {
          "price": 100.08,
          "size": 320
        },
        {
          "price": 100.09,
          "size": 460
        },
        {
          "price": 100.1,
          "size": 600
        },
        {
          "price": 100.11,
          "size": 740
        }
      ]
    },
    {
      "t": 4500,
      "bids": [
        {
          "price": 100.06,
          "size": 200
        },
        {
          "price": 100.05,
          "size": 350
        },
        {
          "price": 100.04,
          "size": 500
        },
        {
          "price": 100.03,
          "size": 650
        },
        {
          "price": 100.02,
          "size": 800
        }
      ],
      "asks": [
        {
          "price": 100.08,
          "size": 220
        },
        {
          "price": 100.09,
          "size": 360
        },
        {
          "price": 100.1,
          "size": 500
        },
        {
          "price": 100.11,
          "size": 640
        },
        {
          "price": 100.12,
          "size": 780
        }
      ]
    },
    {
      "t": 5000,
      "bids": [
        {
          "price": 100.06,
          "size": 250
        },
        {
          "price": 100.05,
          "size": 400
        },
        {
          "price": 100.04,
          "size": 550
        },
        {
          "price": 100.03,
          "size": 700
        },
        {
          "price": 100.02,
          "size": 850
        }
      ],
      "asks": [
        {
          "price": 100.08,
          "size": 260
        },
        {
          "price": 100.09,
          "size": 400
        },
        {
          "price": 100.1,
          "size": 540
        },
        {
          "price": 100.11,
          "size": 680
        },
        {
          "price": 100.12,
          "size": 820
        }
      ]
    },
    {
      "t": 5500,
      "bids": [
        {
          "price": 100.04,
          "size": 300
        },
        {
          "price": 100.03,
          "size": 450
        },
        {
          "price": 100.02,
          "size": 600
        },
        {
          "price": 100.01,
          "size": 750
        },
        {
          "price": 100,
          "size": 900
        }
      ],
      "asks": [
        {
          "price": 100.06,
          "size": 300
        },
        {
          "price": 100.07,
          "size": 440
        },
        {
          "price": 100.08,
          "size": 580
        },
        {
          "price": 100.09,
          "size": 720
        },
        {
          "price": 100.1,
          "size": 860
        }
      ]
    }
  ]
}

Output

{
  "count": 12,
  "depthBps": 10,
  "snapshots": [
    {
      "index": 0,
      "t": 0,
      "bestBid": 100.01,
      "bestAsk": 100.03,
      "mid": 100.02000000000001,
      "spread": 0.01999999999999602,
      "spreadBps": 1.9996000799836051,
      "bidTopSize": 200,
      "askTopSize": 180,
      "topImbalance": 0.05263157894736842,
      "bidDepth": 2500,
      "askDepth": 2300,
      "bookImbalance": 0.041666666666666664
    },
    {
      "index": 1,
      "t": 500,
      "bestBid": 100.01,
      "bestAsk": 100.03,
      "mid": 100.02000000000001,
      "spread": 0.01999999999999602,
      "spreadBps": 1.9996000799836051,
      "bidTopSize": 250,
      "askTopSize": 220,
      "topImbalance": 0.06382978723404255,
      "bidDepth": 2750,
      "askDepth": 2500,
      "bookImbalance": 0.047619047619047616
    },
    {
      "index": 2,
      "t": 1000,
      "bestBid": 100.03,
      "bestAsk": 100.05,
      "mid": 100.03999999999999,
      "spread": 0.01999999999999602,
      "spreadBps": 1.9992003198716535,
      "bidTopSize": 300,
      "askTopSize": 260,
      "topImbalance": 0.07142857142857142,
      "bidDepth": 3000,
      "askDepth": 2700,
      "bookImbalance": 0.05263157894736842
    },
    {
      "index": 3,
      "t": 1500,
      "bestBid": 100.03,
      "bestAsk": 100.05,
      "mid": 100.03999999999999,
      "spread": 0.01999999999999602,
      "spreadBps": 1.9992003198716535,
      "bidTopSize": 200,
      "askTopSize": 300,
      "topImbalance": -0.2,
      "bidDepth": 2500,
      "askDepth": 2900,
      "bookImbalance": -0.07407407407407407
    },
    {
      "index": 4,
      "t": 2000,
      "bestBid": 100.03,
      "bestAsk": 100.05,
      "mid": 100.03999999999999,
      "spread": 0.01999999999999602,
      "spreadBps": 1.9992003198716535,
      "bidTopSize": 250,
      "askTopSize": 180,
      "topImbalance": 0.16279069767441862,
      "bidDepth": 2750,
      "askDepth": 2300,
      "bookImbalance": 0.0891089108910891
    },
    {
      "index": 5,
      "t": 2500,
      "bestBid": 100.04,
      "bestAsk": 100.06,
      "mid": 100.05000000000001,
      "spread": 0.01999999999999602,
      "spreadBps": 1.999000499749727,
      "bidTopSize": 300,
      "askTopSize": 220,
      "topImbalance": 0.15384615384615385,
      "bidDepth": 3000,
      "askDepth": 2500,
      "bookImbalance": 0.09090909090909091
    },
    {
      "index": 6,
      "t": 3000,
      "bestBid": 100.05,
      "bestAsk": 100.07,
      "mid": 100.06,
      "spread": 0.01999999999999602,
      "spreadBps": 1.9988007195678614,
      "bidTopSize": 200,
      "askTopSize": 260,
      "topImbalance": -0.13043478260869565,
      "bidDepth": 2500,
      "askDepth": 2700,
      "bookImbalance": -0.038461538461538464
    },
    {
      "index": 7,
      "t": 3500,
      "bestBid": 100.06,
      "bestAsk": 100.08,
      "mid": 100.07,
      "spread": 0.01999999999999602,
      "spreadBps": 1.9986009793140824,
      "bidTopSize": 250,
      "askTopSize": 300,
      "topImbalance": -0.09090909090909091,
      "bidDepth": 2750,
      "askDepth": 2900,
      "bookImbalance": -0.02654867256637168
    },
    {
      "index": 8,
      "t": 4000,
      "bestBid": 100.05,
      "bestAsk": 100.07,
      "mid": 100.06,
      "spread": 0.01999999999999602,
      "spreadBps": 1.9988007195678614,
      "bidTopSize": 300,
      "askTopSize": 180,
      "topImbalance": 0.25,
      "bidDepth": 3000,
      "askDepth": 2300,
      "bookImbalance": 0.1320754716981132
    },
    {
      "index": 9,
      "t": 4500,
      "bestBid": 100.06,
      "bestAsk": 100.08,
      "mid": 100.07,
      "spread": 0.01999999999999602,
      "spreadBps": 1.9986009793140824,
      "bidTopSize": 200,
      "askTopSize": 220,
      "topImbalance": -0.047619047619047616,
      "bidDepth": 2500,
      "askDepth": 2500,
      "bookImbalance": 0
    },
    {
      "index": 10,
      "t": 5000,
      "bestBid": 100.06,
      "bestAsk": 100.08,
      "mid": 100.07,
      "spread": 0.01999999999999602,
      "spreadBps": 1.9986009793140824,
      "bidTopSize": 250,
      "askTopSize": 260,
      "topImbalance": -0.0196078431372549,
      "bidDepth": 2750,
      "askDepth": 2700,
      "bookImbalance": 0.009174311926605505
    },
    {
      "index": 11,
      "t": 5500,
      "bestBid": 100.04,
      "bestAsk": 100.06,
      "mid": 100.05000000000001,
      "spread": 0.01999999999999602,
      "spreadBps": 1.999000499749727,
      "bidTopSize": 300,
      "askTopSize": 300,
      "topImbalance": 0,
      "bidDepth": 3000,
      "askDepth": 2900,
      "bookImbalance": 0.01694915254237288
    }
  ],
  "averageSpreadBps": 1.9990172080133,
  "averageImbalance": 0.02216300207137215
}

Frequently asked questions

What does the Order Book Replay methodology page document?
CSV format, rendering model, assumptions, and limitations for the Order Book Replay Visualizer. Source citations, assumption deltas, and as-of dates included. It states the formulas, assumptions, data sources, limitations, and reproducibility steps behind the Order Book Replay, in the Finance category.
When was the Order Book Replay methodology last reviewed?
This methodology was last reviewed on 2026-04-20. The matching tool is at https://aifinhub.io/order-book-replay/.
Are the Order Book Replay numbers reproducible?
Yes. This page embeds a worked example whose output is the verbatim result of running the shipped order-book-replay engine on a fixed input; the embedded JSON is recomputed and diffed against the engine in CI, so the numbers cannot drift from the code.

Methodology · Playground · Last updated 2026-04-20

How Order Book Replay works

How the Order Book Replay Visualizer tool actually works — assumptions, algorithms, limitations.

Input format

Wide CSV. One row per L2 snapshot timestamp. Expected columns:

timestamp,bid_px1,bid_sz1,bid_px2,bid_sz2,...,ask_px1,ask_sz1,ask_px2,ask_sz2,...

Up to 20 levels per side are parsed. Missing or zero-size levels are skipped. The timestamp column may be timestamp, time, or ts, and may contain either unix epoch (seconds or milliseconds, auto-detected) or ISO-8601 strings.

Rendering model

  • Bids below the mid, asks above. Bar length ∝ size at that price level.
  • Dashed line is the mid price (best_bid + best_ask) / 2.
  • Spread shown absolute and in basis points: spread / mid × 10000.
  • Best bid / best ask prices are the first entries of the sorted level arrays (bids descending, asks ascending).

Privacy

Parsing and animation run entirely in the browser. Files never leave your device. The tool sets no cookies and makes no network calls after the initial page load.

Limitations

  1. Snapshot-only. The tool replays discrete snapshots, not an event-level message feed (add/modify/cancel). Inter-snapshot microstructure is invisible.
  2. Fixed-level CSV. Variable-depth per-row (e.g. different L2 depth every tick) is accepted but the rendering assumes each snapshot's declared levels are complete.
  3. No trade overlays. Prints / trades are not drawn on top of the book (future enhancement).
  4. Single venue. No consolidated-tape view; one CSV = one venue's book.
  5. Timestamp interpretation. Ambiguous numeric timestamps are assumed millis if > 1e12, else seconds. Feed producers should emit ISO-8601 for unambiguous times.

External resources

Planning estimates only — not financial, tax, or investment advice.