51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""Lightweight contract and schema registry for TradeCipher MVP.
|
|
|
|
This is a minimal, in-process registry to track versioned data contracts
|
|
and their associated schemas. It is intentionally simple and intended for
|
|
bootstrapping interoperability between adapters and contracts.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Dict, Tuple
|
|
import json
|
|
|
|
|
|
# Simple in-memory registry keeping (name -> (version, schema))
|
|
_REGISTRY: Dict[str, Tuple[int, dict]] = {}
|
|
|
|
|
|
def register_contract(name: str, version: int, schema: dict) -> None:
|
|
"""Register or update a contract schema version."""
|
|
_REGISTRY[name] = (version, schema)
|
|
|
|
|
|
def get_contract(name: str) -> Tuple[int, dict] | None:
|
|
"""Return the latest version and schema for a contract, or None."""
|
|
return _REGISTRY.get(name)
|
|
|
|
|
|
def list_contracts() -> Dict[str, Tuple[int, dict]]:
|
|
return dict(_REGISTRY)
|
|
|
|
|
|
def _default_schemas() -> None:
|
|
# Seed with a couple of canonical contracts for MVP bootstrap.
|
|
register_contract(
|
|
"LocalTrade",
|
|
1,
|
|
{
|
|
"fields": ["trade_id", "product_id", "venue", "price", "size", "side", "timestamp", "signer_id", "signature"]
|
|
},
|
|
)
|
|
register_contract(
|
|
"SharedSignals",
|
|
1,
|
|
{
|
|
"fields": ["signals_version", "aggregated_risk", "margin_impact", "liquidity_metric"]
|
|
},
|
|
)
|
|
|
|
|
|
_default_schemas()
|