Async Python SDK for the MockMarket reactive exchange simulator
Project description
MockMarket SDK
Async Python SDK for the MockMarket reactive exchange simulator. Unlike paper trading, your orders trade against a live limit order book with background liquidity — a market order moves the price and a limit order joins the queue.
Built with httpx + pydantic v2.
Installation
uv add mockmarket
uv add "mockmarket[ws]" # + WebSocket streaming
Quick Start
import asyncio
from mockmarket import MockMarketAsyncClient, SandboxCreate
async def main() -> None:
async with MockMarketAsyncClient("YOUR_API_KEY", base_url="http://localhost") as client:
# A deterministic challenge run → lands on the public leaderboard.
sb = await client.create_sandbox(
SandboxCreate(challenge_preset="sprint_v1", agent_name="my-bot")
)
await sb.start()
order = await sb.market_buy(10) # this moves the mid
print(order.status, order.avg_fill_price)
book = await sb.orderbook(depth=5)
print("best bid/ask", book.best_bid, book.best_ask)
acct = await sb.account()
print("equity", acct.equity, "position", acct.position)
await sb.stop()
for e in await client.leaderboard(preset="sprint_v1"):
print(e.agent_name, e.return_pct)
asyncio.run(main())
The Sandbox handle
create_sandbox() / get_sandbox() return a stateful Sandbox you trade with:
| Method | Description |
|---|---|
start() / pause() / stop() / delete() |
Lifecycle |
orderbook(depth=10) |
Top-of-book snapshot (OrderBook with best_bid/best_ask/spread) |
account() |
Position, balances, realized/unrealized PnL, equity |
trades(limit=100) |
Recent tape |
market_buy(qty) / market_sell(qty) |
Market orders |
limit_buy(qty, price) / limit_sell(qty, price) |
Limit orders |
submit_order(side, qty, type=..., price=..., client_order_id=...) |
Full control |
orders() / cancel_order(order_id) |
Open orders |
stream(channels=...) |
Live WebSocket events (needs mockmarket[ws]) |
Client-level helpers: client.create_sandbox(), client.get_sandbox(id),
client.leaderboard(preset=..., metric=..., limit=...), client.create_key(name),
client.health().
Business rejects vs errors
A business reject (e.g. exceeding the notional cap) is not an exception —
it comes back as a normal Order with status == "rejected" and a reject_reason:
order = await sb.market_buy(1_000_000)
if order.is_rejected:
print("rejected:", order.reject_reason)
HTTP failures raise MockMarketAPIError subclasses: AuthenticationError (401/403),
NotFoundError (404), ConflictError (409, e.g. pausing before start),
RateLimitError (429), ValidationError (422).
Live stream (WebSocket)
async for msg in sb.stream(channels=["orderbook", "trade", "fill", "account"]):
print(msg.type, msg.data)
Mint an API key
info = await client.create_key("my-bot")
print(info.api_key) # shown only once
Exact arithmetic
Prices, quantities and money are Decimal end-to-end and cross the wire as
strings, so the SDK inherits the engine's exact matching/accounting — no float drift.
See example_bot.py for a runnable agent.
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
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 mockmarket-0.2.0.tar.gz.
File metadata
- Download URL: mockmarket-0.2.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a9c88f8d49e411707d6f343534b91d4fc327823bac8cb8cf2745d289df842b0
|
|
| MD5 |
28f00a75e3c13b3cdc5c1bfb6dbf3820
|
|
| BLAKE2b-256 |
5ca15db447ed845dd84f4807b7d762a095dadb5d402dab46f4aac27397e03cf1
|
File details
Details for the file mockmarket-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mockmarket-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bac957c6814ee9d5004d341e3cb159b3c3d2859d3f79e893da17f828a72e6216
|
|
| MD5 |
910201f5ee274582804de665fc3ec188
|
|
| BLAKE2b-256 |
06487b4efc454f5663ac9eebff8596c20fb5d274ad1815bbc5905a74a1362ff9
|