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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file market_wave-2.2.0.tar.gz.
File metadata
- Download URL: market_wave-2.2.0.tar.gz
- Upload date:
- Size: 45.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0acc11c7f948dc40ce4d3be65aaa0277370397a8c6b81c9cf1a7b02d11a6b55d
|
|
| MD5 |
ea13084f379440b53cb02b823ab853e6
|
|
| BLAKE2b-256 |
3c7b757dc9085be130982ac1bb1b2c38f2e4aabea98c402e96d8dd454950af12
|
Provenance
The following attestation bundles were made for market_wave-2.2.0.tar.gz:
Publisher:
workflow.yml on smturtle2/market-wave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
market_wave-2.2.0.tar.gz -
Subject digest:
0acc11c7f948dc40ce4d3be65aaa0277370397a8c6b81c9cf1a7b02d11a6b55d - Sigstore transparency entry: 2155136064
- Sigstore integration time:
-
Permalink:
smturtle2/market-wave@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Trigger Event:
push
-
Statement type:
File details
Details for the file market_wave-2.2.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: market_wave-2.2.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 266.7 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
567369a81822a77da3891175e64006cd1226190834c32f968347d84fb893fe10
|
|
| MD5 |
d1387670381d63257b1ea116acb68557
|
|
| BLAKE2b-256 |
ed2ee120234acbf1428e0abad60afff1b785abb61190283cd494ed29a7eec5f9
|
Provenance
The following attestation bundles were made for market_wave-2.2.0-cp310-abi3-win_amd64.whl:
Publisher:
workflow.yml on smturtle2/market-wave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
market_wave-2.2.0-cp310-abi3-win_amd64.whl -
Subject digest:
567369a81822a77da3891175e64006cd1226190834c32f968347d84fb893fe10 - Sigstore transparency entry: 2155136642
- Sigstore integration time:
-
Permalink:
smturtle2/market-wave@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Trigger Event:
push
-
Statement type:
File details
Details for the file market_wave-2.2.0-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: market_wave-2.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 570.2 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74ef350cae147c50e4148dc0a50cfc83113d6751750287f77622ebda669f0d1e
|
|
| MD5 |
1a99f756aaee5f349120a8071663abf4
|
|
| BLAKE2b-256 |
b798d0cc0188b98a5917e53df7fa166ba35f8438901958f85d18047baa88cd56
|
Provenance
The following attestation bundles were made for market_wave-2.2.0-cp310-abi3-musllinux_1_2_x86_64.whl:
Publisher:
workflow.yml on smturtle2/market-wave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
market_wave-2.2.0-cp310-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
74ef350cae147c50e4148dc0a50cfc83113d6751750287f77622ebda669f0d1e - Sigstore transparency entry: 2155136438
- Sigstore integration time:
-
Permalink:
smturtle2/market-wave@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Trigger Event:
push
-
Statement type:
File details
Details for the file market_wave-2.2.0-cp310-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: market_wave-2.2.0-cp310-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 515.2 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e617d6b4469252f670e2b20a74909e535f13a3b1e5396c57b5d5f93f1f89b9b9
|
|
| MD5 |
36f5c1d90d87f0027d750c2364709598
|
|
| BLAKE2b-256 |
47b37857abfd99075185695c6ba147514e2e80032288db6b5029a22d938e3c0d
|
Provenance
The following attestation bundles were made for market_wave-2.2.0-cp310-abi3-musllinux_1_2_aarch64.whl:
Publisher:
workflow.yml on smturtle2/market-wave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
market_wave-2.2.0-cp310-abi3-musllinux_1_2_aarch64.whl -
Subject digest:
e617d6b4469252f670e2b20a74909e535f13a3b1e5396c57b5d5f93f1f89b9b9 - Sigstore transparency entry: 2155136877
- Sigstore integration time:
-
Permalink:
smturtle2/market-wave@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Trigger Event:
push
-
Statement type:
File details
Details for the file market_wave-2.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: market_wave-2.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 364.4 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a316c5189cea1b8091c84f3e1cc1c797923762941196b67e11490ffca501397c
|
|
| MD5 |
8b89684dedaf0d1c56a4b98b47efa673
|
|
| BLAKE2b-256 |
8ae53cb5b6a85475c1b395b385fb39569a3632623628fb4e7c3209e5850073d4
|
Provenance
The following attestation bundles were made for market_wave-2.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
workflow.yml on smturtle2/market-wave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
market_wave-2.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
a316c5189cea1b8091c84f3e1cc1c797923762941196b67e11490ffca501397c - Sigstore transparency entry: 2155137346
- Sigstore integration time:
-
Permalink:
smturtle2/market-wave@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Trigger Event:
push
-
Statement type:
File details
Details for the file market_wave-2.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: market_wave-2.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 339.5 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fb65f7763a99ca54ebe2a0270de0d2e212d3dd94ca225e523385a75a5fa9188
|
|
| MD5 |
73fac23c03946233168fb569ed7da107
|
|
| BLAKE2b-256 |
bcce6290819cce02d853f83fb8bbc5e69c4a7a40ccaf7c82468ee9ae35be4545
|
Provenance
The following attestation bundles were made for market_wave-2.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
workflow.yml on smturtle2/market-wave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
market_wave-2.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
2fb65f7763a99ca54ebe2a0270de0d2e212d3dd94ca225e523385a75a5fa9188 - Sigstore transparency entry: 2155137129
- Sigstore integration time:
-
Permalink:
smturtle2/market-wave@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Trigger Event:
push
-
Statement type:
File details
Details for the file market_wave-2.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: market_wave-2.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 613.4 kB
- Tags: CPython 3.10+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7afb0392964bd716f474b656ad33b5fdca261b8fb986e9dbba55fd4d5e7c2453
|
|
| MD5 |
6e1ec2b16c3894f0d8ee354fa6ece283
|
|
| BLAKE2b-256 |
45e122021ff9c2975f367f612ab88cc80200767681e858ad8728697a5ac11538
|
Provenance
The following attestation bundles were made for market_wave-2.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:
Publisher:
workflow.yml on smturtle2/market-wave
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
market_wave-2.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl -
Subject digest:
7afb0392964bd716f474b656ad33b5fdca261b8fb986e9dbba55fd4d5e7c2453 - Sigstore transparency entry: 2155137511
- Sigstore integration time:
-
Permalink:
smturtle2/market-wave@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@c49f131c8652f79c34c2de0a3ed5295daec57373 -
Trigger Event:
push
-
Statement type: