Skip to main content

An order-flow-driven synthetic market simulator.

Project description

orderwave

PyPI version Python versions Release workflow

Order-flow-driven aggregate order-book market-state simulation for Python, with built-in visualization.

orderwave does not random-walk price directly. It simulates a sparse aggregate order book, participant-conditioned limit flow, marketable flow, cancellations, latent meta-orders, exogenous shocks, and session-aware state changes, then lets price emerge from those book mechanics. The same Market object can render the path, the current book snapshot, and built-in market-state diagnostics without extra plotting glue.

orderwave is an aggregate order-book market-state simulator. It is designed to generate believable intraday market paths, book states, and regime changes for research, visualization, and sandbox experimentation. It does not try to present itself as an order-level matching or fill-precision simulator.

English Docs | 한국어 README | 한국어 문서

orderwave overview

Why orderwave

  • Minimal public entry point: from orderwave import Market
  • Market is the supported public API; engine and model internals are implementation details
  • Price changes only as a consequence of book mechanics
  • Hidden fair value, session clock, shocks, and meta-orders bias flow without directly overwriting price
  • Same seed, same path
  • Built-in figures for overview, current book, and diagnostics
  • Thin public event history plus optional latent debug history

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_labeled_event_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(result.debug_history.tail())

overview.savefig("orderwave-overview.png")

For lighter long runs where you only need summary history, visible book snapshots, and trade strength:

fast_market = Market(seed=7, preset="balanced", logging_mode="history_only")
summary = fast_market.run(steps=10_000).history
figure = fast_market.plot()

Performance Measurement

Use the single performance runner when you want a quick throughput check plus a 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.csv
  • performance_summary.csv
  • performance_logging_modes.csv
  • performance_summary.md

Validation Sweep

The repository also includes a validation runner for preset sweeps, knob sensitivity, reproducibility checks, and soak tests.

python -m scripts.validate_orderwave --profile quality_regression --jobs 4 --outdir artifacts/validation

The runner writes:

  • validation_summary.md
  • run_metrics.csv
  • preset_summary.csv
  • sensitivity_summary.csv
  • invariant_failures.csv
  • acceptance_decision.md
  • diagnostics_<preset>_<seed>.png when diagnostics rendering is enabled

Release builds run a separate Release Validation job that executes the shorter --profile release_smoke regression and compares it against tests/golden/validation_release_baseline.json before PyPI publish. That smoke profile is intentionally kept small so the CI validation gate stays fast.

The current engine roadmap is broader market-state fidelity: stronger preset separation, richer time structure, cleaner sensitivity control, and better validation artifacts.

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 for advanced inspection
get_labeled_event_history() Return event history joined with latent debug labels
plot() Render price, spread, trade strength, and visible-book heatmap
plot_book() Render the current order book on a real price axis
plot_diagnostics() Render session, excitation, imbalance, spread/volatility, resiliency, and occupancy 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" when you want a more aggressively stabilized book, or "off" when you want 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: price, spread, realized-trade imbalance, and signed visible-depth heatmap
  • plot_book() renders the current order book on a real price axis
  • plot_diagnostics() renders session phase profile, imbalance lead, market-flow excitation, spread-volatility coupling, depletion resiliency, and regime or shock occupancy

orderwave current book

orderwave diagnostics

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 instead of black cells.

Presets At A Glance

orderwave presets

balanced, trend, and volatile reuse the same public API while shifting spread behavior, flow pressure, cancellation pressure, and hidden fair-price dynamics.

Core Semantics

Market.get() returns a compact dictionary with session clock fields, prices, spread, visible depth, aggressive volume, trade strength, depth imbalance, and regime.

trade_strength is a realized-trade signed imbalance. It is computed from an EWMA of aggressor buy and sell volume, so quote-only book changes do not move it.

Market.run() returns a SimulationResult bundle with the typed snapshot plus whichever tables are available for the current logging mode.

Important distinction:

  • mid_price can move when quotes improve, cancel, or get depleted
  • last_price only changes when a trade actually executes
  • day, session_step, and session_phase expose the synthetic intraday clock

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 == 0 with the seeded initial book
  • Applied limit, market, and cancel events are available through get_event_history()
  • Participant type, meta-order progress, burst state, and shock state are available through get_debug_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

orderwave-0.4.16.tar.gz (80.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

orderwave-0.4.16-py3-none-any.whl (80.7 kB view details)

Uploaded Python 3

File details

Details for the file orderwave-0.4.16.tar.gz.

File metadata

  • Download URL: orderwave-0.4.16.tar.gz
  • Upload date:
  • Size: 80.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for orderwave-0.4.16.tar.gz
Algorithm Hash digest
SHA256 ee8123920107337ea696c0927e8cd56b630755cbf05d3c6203a52fe90a717b9e
MD5 7c289723e3814d2a6004a1ff5974caf9
BLAKE2b-256 ec82ff0f85c03051dc1fb9b979591f6ad7ca652faad73597d8603599fb7b4136

See more details on using hashes here.

Provenance

The following attestation bundles were made for orderwave-0.4.16.tar.gz:

Publisher: workflow.yml on smturtle2/quoteflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file orderwave-0.4.16-py3-none-any.whl.

File metadata

  • Download URL: orderwave-0.4.16-py3-none-any.whl
  • Upload date:
  • Size: 80.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for orderwave-0.4.16-py3-none-any.whl
Algorithm Hash digest
SHA256 ad7fe1bee8d576238c9bb15a06dd4364fb61a09047a9d62a4cd6c84a7557a9ee
MD5 2bd9dc8dd120f05ec96b52f714bcf4cd
BLAKE2b-256 cec2b7b21ed2b74460038ceaa9821b2222f06a6e1c2881574a5eeabd5d6a1207

See more details on using hashes here.

Provenance

The following attestation bundles were made for orderwave-0.4.16-py3-none-any.whl:

Publisher: workflow.yml on smturtle2/quoteflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page