Skip to main content

An order-flow-driven synthetic market simulator.

Project description

orderwave

PyPI version Python versions Release workflow

Order-flow-driven synthetic market simulation for Python, with built-in visualization.

orderwave does not random-walk price directly. It simulates a sparse aggregate limit 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 realism-oriented diagnostics without extra plotting glue.

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

orderwave overview

Why orderwave

  • Minimal public entry point: from orderwave import Market
  • 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, config={"preset": "trend"})
market.gen(steps=1_000)

snapshot = market.get()
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.tail())

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

Benchmark

The repository benchmark reports both throughput and micro-batch realism metrics.

python benchmarks/benchmark.py --steps 5000 --preset balanced

Expected output includes:

  • steps_per_second
  • events_per_step
  • market_flow=buy=... sell=... buy_share=...

Validation Sweep

The repository also includes a longer-form validation runner that summarizes preset separation, seed stability, invariants, and knob sensitivity into CSV, PNG, and markdown artifacts.

python scripts/validate_orderwave.py --steps 10000 --seeds 20 --outdir artifacts/validation

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
get() Return the current snapshot
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
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.

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, execution-only trade strength, 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 an execution-only signed imbalance. It is computed from an EWMA of realized aggressor buy and sell volume, so quote-only book changes do not move it.

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 execution 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

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.2.tar.gz (44.7 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.2-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: orderwave-0.4.2.tar.gz
  • Upload date:
  • Size: 44.7 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.2.tar.gz
Algorithm Hash digest
SHA256 a7f950f119cfad98ac37ba7997c1c6f679820cf2d03aae6101f4ab81b20723cf
MD5 20c358585c377791f51d4942e89d0544
BLAKE2b-256 7226197415d633a650b61a5b4c5ae593109f62ab43b78386cb87f1349ab12812

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: orderwave-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 40.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5c2642c6f20f793cc1901f263e732956da3b3efb61159c9ffb138dccd6d64088
MD5 120a953f1b7923cdfe0fc3627f4a5f23
BLAKE2b-256 ef4156fc616e0ab89fc5e5389299ad9c35e460663c58dc3f3bd4e634c3ffad2f

See more details on using hashes here.

Provenance

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