An order-flow-driven synthetic market simulator.
Project description
orderwave
Order-flow-driven aggregate order-book market-state simulation for Python, with built-in visualization.
orderwave models a sparse aggregate order book, participant-conditioned limit flow, marketable flow, adverse quote revision, passive refill, latent meta-orders, exogenous shocks, and session-aware state changes. Price is still an outcome of book mechanics rather than a directly random-walked process.
orderwave is an aggregate order-book market-state simulator.
It is built for believable intraday path generation, book-state diagnostics, preset comparison, and sandbox experimentation.
It is not an order-level matching or fill-precision simulator.
English Docs | 한국어 README | 한국어 문서
Why orderwave
- Minimal public entry point:
from orderwave import Market Marketis the supported public API; engine and model internals stay private- Price changes only through quote improvement, depletion, marketable flow, and refill dynamics
- Internal microphases shape open release, midday lull, power-hour activity, and closing imbalance behavior
- Same seed, same path
- Built-in overview, current-book, and diagnostics figures
- Thin public history plus richer event-aligned debug history when you want the latent state
Installation
pip install orderwave
For local development:
pip install -e .[dev]
Quick Start
from orderwave import Market
market = Market(seed=42, preset="trend")
result = market.run(steps=1_000)
snapshot = market.get_snapshot()
history = market.get_history()
events = market.get_event_history()
debug = market.get_debug_history()
overview = market.plot()
book = market.plot_book()
diagnostics = market.plot_diagnostics()
print(snapshot.session_phase, snapshot.mid_price, snapshot.best_bid, snapshot.best_ask)
print(history.tail())
print(events.tail())
print(debug[["microphase", "maker_stress", "quote_revision_wave", "refill_pressure"]].tail())
overview.savefig("orderwave-overview.png")
For long runs where compact history and plotting are enough:
fast_market = Market(seed=7, preset="balanced", logging_mode="history_only")
summary = fast_market.run(steps=10_000).history
figure = fast_market.plot()
Core Realism Model
- Aggregate visible book levels rather than per-order FIFO
- Participant mix:
passive_lp,inventory_mm,noise_taker,informed_meta - Market-first step cycle with structural pre-withdrawal and post-refill behavior
- Regime persistence plus hazard-like switching between
calm,directional, andstressed - Session phase and internal microphase structure:
open_release,morning_trend,midday_lull,power_hour,closing_imbalance - Event-aligned latent diagnostics including
flow_toxicity,maker_stress,quote_revision_wave, andrefill_pressure
API Surface
| API | Purpose |
|---|---|
step() |
Run one micro-batch and return the latest snapshot |
gen(steps=n) |
Run n micro-batches and return the latest snapshot |
run(steps=n) |
Run n micro-batches and return a bundled typed result |
get() |
Return the current snapshot |
get_snapshot() |
Return the current snapshot as a typed dataclass |
get_history() |
Return compact pandas.DataFrame history |
get_event_history() |
Return the applied event log as a pandas.DataFrame |
get_debug_history() |
Return event-aligned latent debug history |
get_labeled_event_history() |
Return event history joined with latent debug labels |
plot() |
Render price, spread, trade strength, and signed visible-depth heatmap |
plot_book() |
Render the current order book on a real price axis |
plot_diagnostics() |
Render session, excitation, imbalance, spread/volatility, resiliency, occupancy, microphase, and revision/refill diagnostics |
Advanced configuration is available through orderwave.config.MarketConfig.
Common settings can also be passed directly as Market(..., preset="trend", logging_mode="history_only", liquidity_backstop="off").
logging_mode="history_only" keeps summary history plus overview/book plotting data, but disables get_event_history(), get_debug_history(), and plot_diagnostics().
Default liquidity_backstop="on_empty" restores a missing side without forcing minimum visible depth after every step.
Use "always" for more aggressively stabilized books or "off" to allow thinner post-step liquidity.
Built-in Visualization
All plotting methods return matplotlib.figure.Figure and leave save/show control to the caller.
plot()renders the main overview: mid/last price, spread band, trade strength, and signed visible-depth heatmapplot_book()renders the current order book on a real price axisplot_diagnostics()renders: session phase profile, imbalance lead, market-flow excitation, spread-volatility coupling, depletion resiliency, regime/shock occupancy, microphase stress profile, and revision/refill pressure
The overview heatmap keeps signed depth. Ask liquidity is red, bid liquidity is blue, 0 maps to a light gray midpoint, and missing levels render as blank background.
Performance Measurement
Use the single performance runner for throughput, memory, and full vs history_only logging comparison.
python -m scripts.measure_performance --preset balanced --seeds 20 --steps 20000 --outdir artifacts/performance
The runner writes:
performance_metrics.csvperformance_summary.csvperformance_logging_modes.csvperformance_summary.md
Validation Sweep
The repository also ships a validation runner for preset sweeps, sensitivity checks, reproducibility, and soak tests.
python -m scripts.validate_orderwave --profile quality_regression --jobs 4 --outdir artifacts/validation
The runner writes:
validation_summary.mdrun_metrics.csvpreset_summary.csvsensitivity_summary.csvinvariant_failures.csvacceptance_decision.mddiagnostics_<preset>_<seed>.pngwhen diagnostics rendering is enabled
Release builds use a shorter smoke workload:
python -m scripts.validate_orderwave --profile release_smoke --outdir artifacts/validation-release --baseline-json tests/golden/validation_release_baseline.json --fail-on-baseline-drift
Core Semantics
mid_pricemoves when quotes improve, cancel, or get depletedlast_priceonly changes on realized tradesday,session_step, andsession_phaseexpose the synthetic session clocktrade_strengthis a realized-trade signed imbalance from aggressor buy/sell EWMAget_debug_history()adds latent fields such asmicrophase,flow_toxicity,maker_stress,quote_revision_wave, andrefill_pressure
Core guarantees:
- Price is never random-walked directly
- Quote improvement, best-quote depletion, and market trades are the only price-moving mechanisms
- Visible history starts at
step == 0with the seeded initial book - Applied limit, market, and cancel events are available through
get_event_history() - Aggregate depth is modeled without exposing per-order FIFO complexity in v1
Docs
orderwave.validation is also a supported advanced API for reproducibility checks, sensitivity sweeps, and validation pipelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 orderwave-0.5.1.tar.gz.
File metadata
- Download URL: orderwave-0.5.1.tar.gz
- Upload date:
- Size: 86.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a960c99400b84624646b6534811640d81d63ff36188c4c0ace5c245da698375
|
|
| MD5 |
1fbbaf4152872e4217b3182917f01935
|
|
| BLAKE2b-256 |
16e00a446cf992dd59c1f51b6aa852297abe54ffc04d59528214b5bd3dd6807a
|
Provenance
The following attestation bundles were made for orderwave-0.5.1.tar.gz:
Publisher:
workflow.yml on smturtle2/quoteflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
orderwave-0.5.1.tar.gz -
Subject digest:
1a960c99400b84624646b6534811640d81d63ff36188c4c0ace5c245da698375 - Sigstore transparency entry: 1089733340
- Sigstore integration time:
-
Permalink:
smturtle2/quoteflow@a59a04c2bf90ba03474017598015c45ebfb48c4f -
Branch / Tag:
refs/tags/v0.5.1 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@a59a04c2bf90ba03474017598015c45ebfb48c4f -
Trigger Event:
release
-
Statement type:
File details
Details for the file orderwave-0.5.1-py3-none-any.whl.
File metadata
- Download URL: orderwave-0.5.1-py3-none-any.whl
- Upload date:
- Size: 85.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e535bf0b51206ee6f85d622b643e7a1e7a24ac939b54b655f299e1f9d50c08db
|
|
| MD5 |
4ff9c9dc06a5340b06f2cc93377664a2
|
|
| BLAKE2b-256 |
85b163b9d4e092b36b4aaec483cc611ce3e1a23be317326b8baf9c9f34c3f04c
|
Provenance
The following attestation bundles were made for orderwave-0.5.1-py3-none-any.whl:
Publisher:
workflow.yml on smturtle2/quoteflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
orderwave-0.5.1-py3-none-any.whl -
Subject digest:
e535bf0b51206ee6f85d622b643e7a1e7a24ac939b54b655f299e1f9d50c08db - Sigstore transparency entry: 1089733348
- Sigstore integration time:
-
Permalink:
smturtle2/quoteflow@a59a04c2bf90ba03474017598015c45ebfb48c4f -
Branch / Tag:
refs/tags/v0.5.1 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@a59a04c2bf90ba03474017598015c45ebfb48c4f -
Trigger Event:
release
-
Statement type: