Open Source MIT License • Python & TypeScript

Open-Source Microstructure Tooling

We maintain orderflow-metrics — a dependency-free library of the market-microstructure metrics institutional desks take for granted, implemented cleanly, tested, and free to read. It ships in both Python (on PyPI) and TypeScript (on npm), with the same API surface.

npm version PyPI version Python versions GitHub stars License MIT Zero dependencies

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 ImbalanceLevel-1 OFI (Cont–Kukanov–Stoikov), per-step and cumulative
ImbalanceTop-of-book depth imbalance and trade imbalance
VPINFlow toxicity via volume bucketing and bulk-volume classification
Information-driven barsTick, volume, and dollar bars
Execution / TCAEffective & realized spread, price impact, Kyle's lambda, Roll's estimator
Fair valueMid, imbalance-weighted micro-price, relative spread (bps)
Trade-sign classificationTick rule and Lee-Ready
Liquidity & volatilityAmihud illiquidity, realized & annualized volatility
Market efficiencyAutocorrelation and the Lo-MacKinlay variance ratio
Hurst exponentLong memory — trend vs mean reversion via rescaled range (R/S)
Range-based volatilityParkinson, Garman-Klass, Rogers-Satchell, Yang-Zhang (from OHLC)
Realized momentsRealized skewness and kurtosis of intraday returns
Jumps & bipower variationSeparate jumps from continuous volatility (Barndorff-Nielsen–Shephard)
Realized semivarianceUpside / downside variance split and signed jump variation
Order-flow entropyShannon, normalized and sign entropy of order flow
Online / streaming estimatorsWelford, EWMA / RiskMetrics variance, O(1) rolling windows
Cross-assetRealized covariance, correlation and beta from aligned returns
Spread estimators (OHLC)Corwin-Schultz and Abdi-Ranaldo effective-spread estimators
Market impact & markoutsSquare-root & Almgren-Chriss impact, implementation shortfall, trade markouts
Order bookReconstruction from incremental updates; depth and imbalance
Market-order simulationSweep the book for VWAP fill, slippage, and unfilled size
Execution schedulingTWAP 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 — published on npm as compiled ESM with type declarations (zero runtime dependencies, Node ≥ 18). You can also read or vendor the TypeScript src/ directly from GitHub:

npm install orderflow-metrics
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.

Explore the code, install the package, or open an issue:

💻 GitHub 📦 npm 🐍 PyPI 📚 Research