Skip to main content

A compact aggregate order-book market simulator.

Project description

orderwave

Compact aggregate order-book simulation for Python, with readable built-in heatmaps.

orderwave keeps the runtime model small: a sparse bid/ask book, bounded mean-reverting fair value, and a latent distribution-synthesis kernel that combines stochastic depth distributions before revealing, canceling, and sweeping aggregate liquidity.

Overview

Install

pip install orderwave

Quick Start

from orderwave import Market

market = Market(seed=42, capture="visual")
result = market.run(steps=1_000)

snapshot = result.snapshot
history = result.history
overview = market.plot()
heatmap = market.plot_heatmap(anchor="price")
book = market.plot_book()

Public API

  • Market(...): create a simulator with an initial price, tick size, visible depth, seed, optional MarketConfig, and capture="summary" | "visual".
  • step(): advance one step and return the latest snapshot.
  • gen(steps): run multiple steps and return the latest snapshot.
  • run(steps): return SimulationResult(snapshot=..., history=...).
  • get(): return the current snapshot as a dict.
  • get_history(): return the summary history as a pandas.DataFrame.
  • plot(): render the price path with a stable level-ranked signed-depth heatmap. Requires capture="visual".
  • plot_heatmap(anchor="mid" | "price"): render a standalone heatmap on stable level coordinates. Requires capture="visual".
  • plot_book(): render the current order book.

capture="summary" keeps the fast path lean. capture="visual" stores a fixed signed-depth window around the moving market center so the heatmap can show sweep, void, and refill structure clearly. Heatmap rows are always fixed visible ranks, laid out as ask N ... ask 1 | bid 1 ... bid N, so they do not drift vertically with price.

Snapshot and History

Snapshot fields:

  • step
  • last_price
  • mid_price
  • best_bid
  • best_ask
  • spread
  • bids
  • asks
  • bid_depth
  • ask_depth
  • depth_imbalance
  • buy_aggr_volume
  • sell_aggr_volume
  • fair_price

History columns:

  • step
  • last_price
  • mid_price
  • best_bid
  • best_ask
  • spread
  • bid_depth
  • ask_depth
  • depth_imbalance
  • buy_aggr_volume
  • sell_aggr_volume
  • fair_price

Model

  • Fair price follows a bounded mean-reverting Gaussian process with weak flow coupling.
  • Hidden liquidity evolves as stochastic distributions rather than a hand-written rule tree. Total liquidity, side skew, flow pressure, and side-specific depth mixtures move first, then visible limit/cancel/market flow is sampled from those distributions through Cox-Poisson style intensities.
  • Visible depth is not rebuilt with symptom-specific rules. Thin-side recovery comes from dynamically synthesized shortage and near-touch distributions rather than hard visible-level floors.
  • Repair is safety-only: it prevents one-sided or crossed books and enforces the spread cap, but it does not cosmetically repad every visible rank.

Realism Profiling

Profile generic microstructure behavior with:

python -m scripts.profile_realism --steps 5000

The profiler reports spread/impact persistence, trade-sign autocorrelation, top-rank gap frequency, per-rank depth shape, visible/full-book one-sidedness, near-touch connectivity, and pair-distribution entropy.

Documentation Assets

Book

Diagnostics

Variants

Regenerate the documentation images with:

python -m scripts.render_doc_images

Render the standalone heatmap example with:

python -m examples.plot_market_heatmap --output artifacts/orderwave_heatmap.png

More docs:

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.6.7.tar.gz (25.4 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.6.7-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for orderwave-0.6.7.tar.gz
Algorithm Hash digest
SHA256 be437eff2b939ee80bf7603ac1e09a9dd732d540fd69c7a5237b14629dbfb7ad
MD5 4151ca31bbcd4b13f5b38119c072f1cd
BLAKE2b-256 7a3532c3adc2621375836270a3007fda4e180eb89e582b3ed11b3fbb2abe6ba3

See more details on using hashes here.

Provenance

The following attestation bundles were made for orderwave-0.6.7.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.6.7-py3-none-any.whl.

File metadata

  • Download URL: orderwave-0.6.7-py3-none-any.whl
  • Upload date:
  • Size: 22.4 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.6.7-py3-none-any.whl
Algorithm Hash digest
SHA256 676f2628800b507b9a9cda1cdc77cb7380d3482f06801018965db2f026a33007
MD5 4577b78ded14d6f4121038110eff853a
BLAKE2b-256 e89ea1cf06b160ca12885d8be9009e7a8d08a97aca089ae6f26e7195e2e0e5df

See more details on using hashes here.

Provenance

The following attestation bundles were made for orderwave-0.6.7-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