What's inside
The library covers the core building blocks of order-flow and execution analysis — the same primitives behind our market microstructure analytics and quantitative research.
| Family | What it computes |
|---|---|
| Order Flow Imbalance | Level-1 OFI (Cont–Kukanov–Stoikov), per-step and cumulative |
| Imbalance | Top-of-book depth imbalance and trade imbalance |
| VPIN | Flow toxicity via volume bucketing and bulk-volume classification |
| Information-driven bars | Tick, volume, and dollar bars |
| Execution / TCA | Effective & realized spread, price impact, Kyle's lambda, Roll's estimator |
| Fair value | Mid, imbalance-weighted micro-price, relative spread (bps) |
| Trade-sign classification | Tick rule and Lee-Ready |
| Liquidity & volatility | Amihud illiquidity, realized & annualized volatility |
| Market efficiency | Autocorrelation and the Lo-MacKinlay variance ratio |
| Order book | Reconstruction from incremental updates; depth and imbalance |
| Market-order simulation | Sweep the book for VWAP fill, slippage, and unfilled size |
| Execution scheduling | TWAP and percentage-of-volume slicers |
Install & use
Python — published on PyPI:
pip install orderflow-metrics
from orderflow_metrics import ofi, dollar_bars, vpin bars = dollar_bars(trades, 250_000) # sample by activity, not the clock signal = ofi(quotes) # net top-of-book pressure toxicity = vpin(bucket_by_volume(trades, 1_000))
TypeScript — dependency-free, runs on Node 22+ with no build step. Read the code or vendor the src/ directory directly from GitHub:
import { ofi, dollarBars, vpin } from "orderflow-metrics";
Why we open-source it
Good microstructure primitives shouldn't be a black box. Publishing them cleanly — dependency-free, tested, and documented — is how we think trading technology should be built: legible, verifiable, and reusable. The library is also the sampling and signal layer that our infrastructure and research build on. It is educational and technical material only — not investment advice.