build(agent): molt-x#ed374b iteration

This commit is contained in:
agent-ed374b2a16b664d2 2026-04-15 22:20:33 +02:00
parent c703bea9d7
commit b538216c64
2 changed files with 93 additions and 15 deletions

View File

@ -1,20 +1,37 @@
# MercuryMesh Federated Reproducible Market Sandbox (MVP) MercuryMesh Federated Reproducible Market Sandbox (MVP)
Overview Overview
- A minimal, portable Python-based MVP for a federated, contract-driven market microstructure sandbox. - A portable, open-source stack to design, simulate, and reproduce cross-venue market microstructure experiments for multiple assets.
- Primitives: MarketStateSnapshot, SharedSignals, PlanDelta, AuditLog. - Canonical primitives: LocalBook (per-asset local state), SharedSignals (aggregated metrics), PlanDelta (deltas/allocations), AuditLog (provenance).
- Coordination: FederatedCoordinator provides a tiny, safe aggregation layer to mimic cross-venue signal exchange. - Federated coordination: lightweight, ADMM-like signals exchange with bounded staleness, preserving data privacy.
- Deterministic replay and auditability are scaffolded around the core data contracts. - Deterministic replay: offline backtesting and education through seedable, reproducible runs.
- Edge-friendly runtimes and scenario builder: WebAssembly-ready cores, portable Python/C++ binaries, and an orchestration UI for scenario design and backtests.
What you get in this MVP Status
- A reproducible Python package: mercurymesh_federated_reproducible_marke - MVP focus: Python-based core primitives and a minimal federated coordinator suitable for unit tests.
- Lightweight, testable contracts and a toy federated coordinator - Testing: powered by pytest; packaging via setuptools. See test.sh for the verification workflow.
- Basic tests ensuring serialization, coordination, and data contracts work as intended
- A test script (test.sh) to run tests and packaging checks
Usage Getting started
- Install: python3 -m build (outside-of-repo tooling) and pip install dist/* - Core API: mercurymesh_federated_reproducible_marke.core
- Run tests: bash test.sh - Replay: mercurymesh_federated_reproducible_marke.replay
- Public exports: mercurymesh_federated_reproducible_marke.__init__ (MarketStateSnapshot, SharedSignals, PlanDelta, AuditLog, FederatedCoordinator)
Notes Usage example (high level)
- This is a starter MVP meant for extension. It intentionally focuses on clarity and correct packaging wiring, not production-grade performance or security. - Create a MarketStateSnapshot for initial state.
- Produce PlanDelta updates from participating agents.
- Use DeterministicReplayer.replay to deterministically apply deltas and obtain a final state.
Future plans (phases)
- Phase 0: protocol skeleton with two starter adapters and a basic ADMM-lite solver.
- Phase 1: governance ledger, secure identities, and secure aggregation of signals.
- Phase 2: cross-domain demo with simulated multi-venue scenarios and bindings.
- Phase 3: hardware-in-the-loop validation with metrics and dashboards.
Contributing
- This project follows a lightweight MVP approach focused on quality and reproducibility.
- See AGENTS.md for architectural notes and contribution guidelines.
Licensing
- MIT License. See LICENSE file in the repository root.
For more details, see the code and tests under mercurymesh_federated_reproducible_marke.

View File

@ -0,0 +1,61 @@
"""Deterministic replay engine for MercuryMesh MVP.
This module provides a tiny, deterministic replay utility that applies a
sequence of PlanDelta updates to a starting MarketStateSnapshot to reproduce
past runs. The implementation is intentionally minimal and safe for educational
and testing purposes.
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Dict, Iterable, List
from datetime import datetime
from .core import MarketStateSnapshot, PlanDelta
def _now_iso() -> str:
return datetime.utcnow().isoformat() + "Z"
@dataclass
class DeterministicReplayer:
"""A tiny replay engine that applies PlanDelta deltas to a MarketStateSnapshot.
The replay model is intentionally simple: for each delta, asset-level values
in bids are increased by delta amount, while corresponding values in offers
are decreased by the same amount. This provides a predictable, reversible
transformation suitable for offline backtesting and educational labs.
"""
@staticmethod
def apply_delta(state: MarketStateSnapshot, delta: PlanDelta) -> MarketStateSnapshot:
# Copy mutable maps to avoid in-place mutation of inputs
bids = dict(state.bids)
offers = dict(state.offers)
for asset, change in delta.delta.items():
bids[asset] = bids.get(asset, 0.0) + float(change)
offers[asset] = offers.get(asset, 0.0) - float(change)
# Build a new MarketStateSnapshot with updated bids/offers and a new timestamp
return MarketStateSnapshot(
assets=list(state.assets),
bids=bids,
offers=offers,
last_trade_times=dict(state.last_trade_times),
liquidity_metrics=dict(state.liquidity_metrics),
timestamp=_now_iso(),
version=int(state.version) + 1,
)
@staticmethod
def replay(start: MarketStateSnapshot, deltas: Iterable[PlanDelta]) -> MarketStateSnapshot:
"""Replays a sequence of PlanDelta updates starting from a given state.
Returns the final MarketStateSnapshot after applying all deltas in order.
"""
current = start
for d in deltas:
current = DeterministicReplayer.apply_delta(current, d)
return current