OrderFlowKit
OrderFlowKit is a Python library for free-data market microstructure analytics, order-flow features, L2 order-book capture, replay, and ML-ready dataset generation.
It is built for independent quant researchers, educators, ML researchers, and crypto market-data projects that need a reproducible research pipeline without paid feeds or private trading credentials.
What It Does
OrderFlowKit turns OHLCV bars, trades, and public crypto L2 depth streams into clean, testable research artifacts:
- Bar and trade microstructure metrics such as Roll spread, Corwin-Schultz spread, Amihud illiquidity, VWAP deviation, tick rule signs, BVC volume splits, Parkinson volatility, realized volatility, variance ratio, and Hurst exponent.
- Binance REST klines and aggregate trade ingestion with normalized pandas outputs.
- Binance Spot WebSocket depth ingestion for public L2 streams.
- Deterministic local order-book reconstruction with sequence-gap, crossed-book, and stale-book detection.
- Quote, depth, imbalance, flow, volatility, and label generation for ML workflows.
- Parquet, compressed JSONL, quality-report, replay, plotting, and CLI utilities.
OrderFlowKit is a research toolkit. It does not execute orders, manage portfolios, claim manipulation detection, or model private exchange queues.
Install
From PyPI after release:
uv pip install OrderFlowKit
For local development:
git clone https://github.com/tayor/orderflowkit.git
cd orderflowkit
uv venv
uv sync --extra dev --extra stream --extra viz --extra bars
The import name is lowercase:
import orderflowkit as ofk
The command-line entry point is:
ofk --help
Quickstart: OHLCV Metrics
from orderflowkit import MicrostructurePipeline
from orderflowkit.feeders import YFinanceFeeder
feeder = YFinanceFeeder()
bars = feeder.fetch("SPY", start="2024-01-01", end="2024-12-31", interval="1d")
result = (
MicrostructurePipeline(bars)
.add_roll_spread(window=20)
.add_corwin_schultz_spread()
.add_amihud_illiquidity(window=20)
.add_vwap_deviation()
.add_parkinson_vol(window=20)
.add_realized_vol(window=20)
.run()
)
print(result.metrics.tail())
print(result.summary())
Quickstart: Binance REST Trades
from orderflowkit.feeders import BinanceRestFeeder
from orderflowkit.metrics.order_flow import order_imbalance, tick_rule
feeder = BinanceRestFeeder()
trades = feeder.fetch_trades("BTCUSDT", start="2026-05-01", end="2026-05-02")
trades["sign"] = tick_rule(trades["price"])
trades["signed_volume"] = trades["sign"] * trades["quantity"]
imbalance = order_imbalance.from_signed_volume(trades["signed_volume"])
Quickstart: Local Book Reconstruction
from orderflowkit.book import LocalBook
book = LocalBook(symbol="BTCUSDT", depth=10)
book.apply_snapshot(
bids=[(100.0, 2.0), (99.5, 1.0)],
asks=[(100.5, 1.5), (101.0, 3.0)],
update_id=1,
)
book.apply_delta(side="bid", price=100.0, size=3.0, update_id=2)
print(book.mid)
print(book.spread_bps)
print(book.imbalance(levels=2))
Quickstart: Binance L2 Recording
import asyncio
from orderflowkit.record import Recorder
from orderflowkit.streams import BinanceDepthStream
async def main() -> None:
stream = BinanceDepthStream(symbol="BTCUSDT", depth=100)
recorder = Recorder(stream, out_dir="./data/BTCUSDT")
await recorder.run(duration="1m")
asyncio.run(main())
This writes raw compressed JSONL, normalized Parquet events, book snapshots, and a quality report.
CLI Examples
Fetch bars:
ofk fetch bars AAPL --source yfinance --start 2024-01-01 --end 2024-12-31 --interval 1d --out data/AAPL.bars.parquet
Compute bar metrics:
ofk metrics bars data/AAPL.bars.parquet --preset academic --out metrics/AAPL.metrics.parquet
Build L2 features from normalized events:
ofk features l2 data/BTCUSDT/normalized/2026-05-03.l2_events.parquet --levels 1,5,10 --out features/BTCUSDT.features.parquet
Generate labels:
ofk labels features/BTCUSDT.features.parquet --horizons 1s,5s,30s --threshold-bps 2 --out datasets/BTCUSDT.ml.parquet
Replay a local event file:
ofk replay data/BTCUSDT/normalized/2026-05-03.l2_events.parquet --speed max
Data Schemas
OrderFlowKit normalizes data around stable pandas/Parquet schemas:
- Bars:
timestamp,symbol,source,open,high,low,close,volume,dollar_volume,interval - Trades:
timestamp,symbol,source,trade_id,price,quantity,side,is_buyer_maker,notional - L2 events:
ts_exchange,ts_local,exchange,symbol,event_type,side,price,size,update_id,first_update_id,last_update_id,sequence,is_snapshot,raw_payload - Book snapshots:
ts_exchange,ts_local,exchange,symbol,level,bid_price,bid_size,ask_price,ask_size,mid,spread,spread_bps,microprice,valid,status
Feature Presets
academic: bar-data metrics for classical market microstructure research.crypto_l2: book-derived quote, depth, spread, microprice, imbalance, and volatility features.ml_default: lagged returns, depth ratios, order-flow windows, volatility windows, and quality flags.
Testing
The test suite is designed to run in minutes and does not require network access:
uv run pytest
uv run ruff check .
uv run mypy
uv run python -m build
uv run twine check dist/*
Data-Source Notes
Free data sources have limits, gaps, symbol restrictions, and outages. OrderFlowKit preserves raw exchange payloads where possible, emits data-quality reports, and surfaces invalid book intervals so downstream research can filter or label them.
License
OrderFlowKit is MIT licensed.
Metadata
Release files for OrderFlowKit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| orderflowkit-0.1.0.tar.gz | 201.4 kB | Without provenance | Details for orderflowkit-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| orderflowkit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for orderflowkit-0.1.0-py3-none-any.whl |
Total release size: 259.5 kB
Release files / orderflowkit-0.1.0.tar.gz
| Download URL | orderflowkit-0.1.0.tar.gz |
|---|---|
| Size | 201.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b75eef61d92985f590bac8f018854a353e928733fa47c7918eb5d5eabf55b1f
|
|
BLAKE2b-256 checksum How to use checksums |
aa7ec77479328c250db90dcfc2fac04e243ac92446325fe4a9d4579e5b01cb7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / orderflowkit-0.1.0-py3-none-any.whl
| Download URL | orderflowkit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 58.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ae2f717212e7c4fbca6819a136d54591c9a55b01dd81161ade2463868004d8f
|
|
BLAKE2b-256 checksum How to use checksums |
a8b66323a986cf502bc7b9920471e802ad991a28b64156d5efa07e5013f70222
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for OrderFlowKit 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.