An order-flow-driven synthetic market simulator.
Project description
orderwave
orderwave is an order-flow-driven market simulator.
It does not random-walk price directly. Instead, it simulates a limit order book with stochastic limit arrivals, marketable flow, cancellations, and inside-spread quote improvement, then lets price emerge from those book changes.
Installation
pip install orderwave
For local development:
pip install -e .[dev]
Quick Start
from orderwave import Market
market = Market(seed=42)
market.step()
market.gen(steps=1_000)
snapshot = market.get()
history = market.get_history()
print(snapshot["mid_price"], snapshot["best_bid"], snapshot["best_ask"])
print(history.tail())
Why orderwave
- Minimal public API:
from orderwave import Market - Price is an outcome of book dynamics, not a separately sampled process
- Hidden fair value and regime shifts bias order flow without directly overwriting price
- Deterministic paths under the same seed
API
from orderwave import Market
market = Market(
init_price=100.0,
tick_size=0.01,
levels=5,
seed=42,
config={"preset": "balanced"},
)
Methods:
step()returns the latest snapshot after one micro-batchgen(steps=n)advancesnsteps and returns the latest snapshotget()returns the current snapshotget_history()returns a compactpandas.DataFrame
Supported presets:
balancedtrendvolatile
config accepts either a plain dict or orderwave.config.MarketConfig.
Snapshot
Market.get() returns:
{
"step": int,
"last_price": float,
"mid_price": float,
"microprice": float,
"best_bid": float,
"best_ask": float,
"spread": float,
"bids": [{"price": float, "qty": float}, ...],
"asks": [{"price": float, "qty": float}, ...],
"last_trade_side": "buy" | "sell" | None,
"last_trade_qty": float,
"buy_aggr_volume": float,
"sell_aggr_volume": float,
"trade_strength": float,
"depth_imbalance": float,
"regime": str,
}
last_price is the last executed trade price. If the book changes without a trade, mid_price can move while last_price stays fixed.
Model
Each step() is a micro-batch:
- Compute state features from the current book
- Update regime:
calm,directional, orstressed - Update hidden fair value
- Sample limit orders, marketable flow, and cancellations
- Shuffle events and apply them to the book
- Record the snapshot and compact history row
Price moves only through book mechanics:
- market buy removes ask liquidity
- market sell removes bid liquidity
- cancellation depletes the best quote
- a new limit order improves the quote inside the spread
Diagnostics Example
from orderwave import Market
market = Market(seed=7, config={"preset": "trend"})
market.gen(steps=5_000)
history = market.get_history()
mid_ret = history["mid_price"].diff().fillna(0.0)
abs_ret = mid_ret.abs()
spread_mean = history["spread"].mean()
imbalance_lead_corr = history["depth_imbalance"].corr(mid_ret.shift(-1).fillna(0.0))
vol_cluster = abs_ret.autocorr(lag=1)
print("spread mean:", spread_mean)
print("imbalance -> next return corr:", imbalance_lead_corr)
print("|return| lag-1 autocorr:", vol_cluster)
Maintainer Release
PyPI publishing is wired through workflow.yml.
On 2026-03-06, GitHub Actions release event docs document that release.types: [published] triggers when a release is published, while drafts themselves do not trigger workflows. PyPI trusted publishing docs document the id-token: write flow used by the publish job.
Release flow:
- Update
versioninpyproject.toml - Commit and push to
main - In GitHub, open
Releases - Click
Draft a new release - Create a tag like
v0.1.0 - Set the release title, then click
Publish release - GitHub Actions runs tests, builds the distributions, and publishes to PyPI
Trusted Publisher settings for PyPI:
- PyPI project name:
orderwave - Repository owner:
smturtle2 - Repository name:
quoteflow - Workflow filename:
.github/workflows/workflow.yml - Environment name:
pypi
If orderwave does not exist on PyPI yet, create the project through a pending publisher first. PyPI notes that a pending publisher does not reserve the name until the first successful publish.
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.1.0.tar.gz.
File metadata
- Download URL: orderwave-0.1.0.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a07e13d1a78e7f787f6d1a9e66958bf1be45bc0dacc01e2819980a5f5b42627c
|
|
| MD5 |
4f2502c953f36ae914b485423539c4ee
|
|
| BLAKE2b-256 |
184ac501bd5ae2edac55bd6c9a0c9e6411f0e41b64a544049e018d1047f95bf6
|
Provenance
The following attestation bundles were made for orderwave-0.1.0.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.1.0.tar.gz -
Subject digest:
a07e13d1a78e7f787f6d1a9e66958bf1be45bc0dacc01e2819980a5f5b42627c - Sigstore transparency entry: 1050365821
- Sigstore integration time:
-
Permalink:
smturtle2/quoteflow@245c98f92d11e2505d255e0ce8b4822344549477 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@245c98f92d11e2505d255e0ce8b4822344549477 -
Trigger Event:
release
-
Statement type:
File details
Details for the file orderwave-0.1.0-py3-none-any.whl.
File metadata
- Download URL: orderwave-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.3 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 |
6acd56bddb5997ae4f961a1884e16465f2b1941da68be9350836b97a0f79b97e
|
|
| MD5 |
3d9002254cc97475dfe2117cc4f263dd
|
|
| BLAKE2b-256 |
5cbfbb1bbfa5a35e9db12aa4739a77c65def94571a7fda4f4607867a613642d7
|
Provenance
The following attestation bundles were made for orderwave-0.1.0-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.1.0-py3-none-any.whl -
Subject digest:
6acd56bddb5997ae4f961a1884e16465f2b1941da68be9350836b97a0f79b97e - Sigstore transparency entry: 1050365823
- Sigstore integration time:
-
Permalink:
smturtle2/quoteflow@245c98f92d11e2505d255e0ce8b4822344549477 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/smturtle2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@245c98f92d11e2505d255e0ce8b4822344549477 -
Trigger Event:
release
-
Statement type: