Market Wave
Adaptive order flow. Exact price-time matching. No hidden price path.
A seeded, in-memory continuous double auction for market-microstructure experiments and synthetic scenario generation.
Quick start · Visualization · Model · API · Development
One 300-second run · seed 7 · N=64 · generated by render_run()
Why Market Wave?
Market Wave generates a market from orders and executions—not from a latent price series that is corrected after the fact.
- Exact microstructure — continuous-time arrivals, maker-price execution, strict price-time priority, partial fills, resting remainders, and expiry.
- Adaptive order flow — an ensemble of predictive laws learns from every completed step at different memory scales.
- Visible-liquidity feedback — the live book can reshape marketable and spread-improving flow without moving prices directly.
- Native performance — the market, order book, RNG, flow, and projection solver run in Rust through PyO3.
- Reproducible experiments — explicit configuration, immutable results, and deterministic seeded sequences for the same release and platform target.
- Honest visualization — event-time fills, step-end states, real interval widths, shared comparison scales, and no invented midpoint.
Market Wave models aggregate market intent, not named traders. It is a research simulator, not a forecasting or venue-calibration product.
Installation
Published wheels include the native Rust engine and support CPython 3.10+.
pip install market-wave
Visualization is optional:
pip install "market-wave[visualization]"
Building from source requires Rust 1.83+.
Quick start
from market_wave import Market, MarketConfig, Trade
market = Market(
MarketConfig(
initial_price=100_000,
tick_size=1,
step_seconds=1.0,
order_rate=20.0,
mean_price_offset_ticks=4.0,
mean_order_size_lots=3.0,
mean_order_lifetime_seconds=5.0,
flow_component_count=64,
seed=7,
)
)
steps = market.step(300)
last = steps[-1]
executed_lots = sum(
event.quantity
for step in steps
for event in step.events
if isinstance(event, Trade)
)
print("best bid:", last.book.best_bid)
print("best ask:", last.book.best_ask)
print("executed lots:", executed_lots)
step() and step(1) return one Step; step(0) returns (); values above
one return tuple[Step, ...]. Use market.stream(count) when results should be
consumed lazily.
Visualization
The optional visualization namespace exposes three focused renderers:
from market_wave.visualization import (
render_book,
render_comparison,
render_run,
)
render_run(steps, "run.png", title="Reference run", level_count=10)
render_book(steps[-1], "book.png", level_count=10)
render_comparison(
{"baseline": steps, "alternative": alternative_steps},
"comparison.png",
columns=2,
)
| Renderer | Question answered |
|---|---|
render_run() |
How did quotes, fills, depth, spread, and order flow evolve? |
render_book() |
What exactly was resting at one selected step? |
render_comparison() |
How do several runs differ on shared price and depth scales? |
Rendering is non-mutating and writes an atomically replaced PNG. Prices are
converted to integer tick offsets before float plotting, so very large absolute
prices retain their local structure. Bilateral depth uses real step widths and
the fixed row order Ask LN … Ask L1 | Bid L1 … Bid LN.
To regenerate the repository's 32-scenario factorial atlas:
uv run python benchmarks/visualize_32_scenarios.py
How it works
N predictive laws at different memory scales
│
▼
combine side, price, quantity, and lifetime marginals
│
▼
condition feasible order flow on visible liquidity
│
▼
sample → submit → match → rest → expire
│
▼
feed the completed Step back to every law
Adaptive ensemble
Law i retains rho_i = (i + 0.5) / N of its prior evidence. The evenly
spaced retention spectrum supplies short and long memory without a hand-tuned
decay schedule. Every law observes the same completed market step.
Direct marginal sampling
The engine combines the ensemble before each draw, then samples mathematically equivalent conditional components directly: discrete-Laplace price offsets, geometric quantities, and exponential resting lifetimes. Component selection is ephemeral and never decides which laws receive feedback.
Liquidity-aware flow
When the visible book admits a support-preserving solution, a minimum-KL projection reweights marketable, spread-improving, and neutral price regions. Conditional shapes remain intact. If projection is infeasible, the aggregate unconditioned distribution is used.
Exact matching lifecycle
Crossing orders consume resting liquidity at maker prices. Only the unfilled remainder rests, expiry begins at rest time, and fully filled orders cannot later cancel. Feedback is applied once, after the half-open step completes.
Configuration
Every MarketConfig field is explicit and required.
| Field | Contract |
|---|---|
initial_price |
positive integer, aligned to tick_size |
tick_size |
positive integer |
step_seconds |
finite seconds greater than zero |
order_rate |
finite expected orders/second, at least zero |
mean_price_offset_ticks |
finite mean absolute offset, at least zero |
mean_order_size_lots |
finite mean quantity, at least one |
mean_order_lifetime_seconds |
finite mean resting lifetime greater than zero |
flow_component_count |
positive ensemble size N |
seed |
integer |
Prices and quantities remain exact Python integers throughout the public model.
Public API
| Surface | Contract |
|---|---|
Market.step(n=1) |
eagerly advances consecutive feedback intervals |
Market.stream(count) |
lazily advances the same market |
Step.events |
chronological Submission, Trade, and Cancellation values |
Step.book |
immutable step-end BookSnapshot |
Market.book |
current immutable book snapshot |
Market.buy_distribution, sell_distribution |
current aggregate price laws |
EntryDistribution.probability(), .cdf() |
exact aggregate price PMF and CDF |
market_wave.visualization |
optional run, book, and comparison PNG renderers |
Calling step() or consuming stream() mutates only the market's forward
state. Returned events, steps, books, and distributions do not retain a mutable
engine back-reference.
Performance and validation
The repository tests matching invariants, event lifecycles, seeded reproducibility, conditional marginal sampling, numerical boundaries, native batching, parallel markets, adaptive feedback, and visualization semantics.
uv run python benchmarks/benchmark_market.py
On the release validation host (Linux x86-64, CPython 3.14), the default
flow_component_count=64 workload measured 4.04 ms/step after warm-up, or
247.6 steps/s. Treat this as a comparison point, not a runtime guarantee.
Development
uv sync --extra dev
uv run maturin develop --release --locked
uv run pytest
cargo test --manifest-path rust/Cargo.toml
Release artifacts are built for Linux glibc, Linux musl, macOS universal2, and Windows through GitHub Actions. See the changelog for versioned behavior changes.
Scope and license
Market Wave intentionally has no CLI, persistence layer, replay engine, hidden calibration state, named-agent model, or financial forecast. Callers decide which generated immutable results to retain.
Released under the MIT License.
Metadata
Release files for market-wave 2.2.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 | |
|---|---|---|---|
| market_wave-2.2.0.tar.gz | 45.1 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| market_wave-2.2.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| market_wave-2.2.0-cp310-abi3-musllinux_1_2_x86_64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ x86-64 | Details |
| market_wave-2.2.0-cp310-abi3-musllinux_1_2_aarch64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ ARM64 | Details |
| market_wave-2.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| market_wave-2.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| market_wave-2.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64, macOS 10.12+ x86-64, macOS 10.12+ universal2 (ARM64, x86-64) | Details |
Total release size: 2.7 MB
Release files / market_wave-2.2.0.tar.gz
| Download URL | market_wave-2.2.0.tar.gz |
|---|---|
| Size | 45.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0acc11c7f948dc40ce4d3be65aaa0277370397a8c6b81c9cf1a7b02d11a6b55d
|
|
BLAKE2b-256 checksum How to use checksums |
3c7b757dc9085be130982ac1bb1b2c38f2e4aabea98c402e96d8dd454950af12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.
Transparency logRelease files / market_wave-2.2.0-cp310-abi3-win_amd64.whl
| Download URL | market_wave-2.2.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 266.7 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
567369a81822a77da3891175e64006cd1226190834c32f968347d84fb893fe10
|
|
BLAKE2b-256 checksum How to use checksums |
ed2ee120234acbf1428e0abad60afff1b785abb61190283cd494ed29a7eec5f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.
Transparency logRelease files / market_wave-2.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | market_wave-2.2.0-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 570.2 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
74ef350cae147c50e4148dc0a50cfc83113d6751750287f77622ebda669f0d1e
|
|
BLAKE2b-256 checksum How to use checksums |
b798d0cc0188b98a5917e53df7fa166ba35f8438901958f85d18047baa88cd56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.
Transparency logRelease files / market_wave-2.2.0-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | market_wave-2.2.0-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 515.2 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
e617d6b4469252f670e2b20a74909e535f13a3b1e5396c57b5d5f93f1f89b9b9
|
|
BLAKE2b-256 checksum How to use checksums |
47b37857abfd99075185695c6ba147514e2e80032288db6b5029a22d938e3c0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.
Transparency logRelease files / market_wave-2.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | market_wave-2.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 364.4 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
a316c5189cea1b8091c84f3e1cc1c797923762941196b67e11490ffca501397c
|
|
BLAKE2b-256 checksum How to use checksums |
8ae53cb5b6a85475c1b395b385fb39569a3632623628fb4e7c3209e5850073d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.
Transparency logRelease files / market_wave-2.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | market_wave-2.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 339.5 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2fb65f7763a99ca54ebe2a0270de0d2e212d3dd94ca225e523385a75a5fa9188
|
|
BLAKE2b-256 checksum How to use checksums |
bcce6290819cce02d853f83fb8bbc5e69c4a7a40ccaf7c82468ee9ae35be4545
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.
Transparency logRelease files / market_wave-2.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | market_wave-2.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 613.4 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7afb0392964bd716f474b656ad33b5fdca261b8fb986e9dbba55fd4d5e7c2453
|
|
BLAKE2b-256 checksum How to use checksums |
45e122021ff9c2975f367f612ab88cc80200767681e858ad8728697a5ac11538
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.
Transparency log