Snapshot PINK DITAv2 system + Sprint 0 flaw-fix verification
First commit of the previously-untracked PINK-on-DITAv2 migration system (execution moves to the Rust kernel; policy stays on legacy DITA, so Alpha Engine algorithmic integrity is preserved). BLUE is untouched. Sprint 0 (safety snapshot + flaw-fix verification, MARKET single-leg scope): - Verified Rust FSM fixes (flaws 2,4,10,11,13) by source read of lib.rs. - Hardened 5 vacuous/guarded assertions in test_flaws.py so each flaw test genuinely exercises its fix. Most important: Flaw 5 now asserts capital moves by EXACTLY realized PnL (was entering/exiting at the same price). - Offline suites: 533 passed, 0 failed (35 flaws + 402 kernel/accounting/ bridge + 96 runtime/persistence/multi-exit/restart/seams). - GATE PASS: MARKET-path-critical flaws 1,2,5 confirmed fixed + green. - Added SPRINT0_FLAW_VERIFICATION.md report and _rust_kernel/.gitignore (excludes Rust target/ build artifacts). LIMIT/partial-fill remain explicitly out of scope (MARKET-only bring-up). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
67
prod/clean_arch/dita_v2/hazelcast_projection.py
Normal file
67
prod/clean_arch/dita_v2/hazelcast_projection.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any, Protocol
|
||||
|
||||
from .contracts import KernelTransition, TradeSlot
|
||||
from .control import KernelControlSnapshot
|
||||
from .journal import _transition_row
|
||||
from .projection import build_position_state_row
|
||||
from .utils import json_safe
|
||||
|
||||
|
||||
class HazelcastClientLike(Protocol):
|
||||
def get_map(self, name: str): ...
|
||||
def get_topic(self, name: str): ...
|
||||
|
||||
|
||||
class HazelcastProjector:
|
||||
"""Durable BLUE/PINK-compatible projection mirror."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
client: HazelcastClientLike | None = None,
|
||||
*,
|
||||
active_slots_map: str = "dita_active_slots",
|
||||
events_topic: str = "dita_trade_events",
|
||||
) -> None:
|
||||
self.client = client
|
||||
self.active_slots_map = active_slots_map
|
||||
self.events_topic = events_topic
|
||||
|
||||
def publish_slot(self, slot: TradeSlot) -> None:
|
||||
if self.client is None:
|
||||
return
|
||||
self.client.get_map(self.active_slots_map).put(slot.trade_id, build_position_state_row(slot))
|
||||
|
||||
def publish_event(self, event_type: str, payload: dict[str, Any]) -> None:
|
||||
if self.client is None:
|
||||
return
|
||||
topic = self.client.get_topic(self.events_topic)
|
||||
topic.publish(
|
||||
json.dumps(
|
||||
{"event_type": event_type, "payload": json_safe(payload)},
|
||||
ensure_ascii=False,
|
||||
sort_keys=True,
|
||||
default=str,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class HazelcastRowWriter:
|
||||
"""Callback bridge for ``HazelcastProjection`` writer hooks."""
|
||||
|
||||
def __init__(self, client: HazelcastClientLike) -> None:
|
||||
self.client = client
|
||||
|
||||
def __call__(self, name: str, row: dict[str, Any]) -> None:
|
||||
if name.endswith("trade_events"):
|
||||
self.client.get_topic(name).publish(
|
||||
json.dumps(row, ensure_ascii=False, sort_keys=True, default=str)
|
||||
)
|
||||
return
|
||||
if name.endswith("control"):
|
||||
key = "control"
|
||||
else:
|
||||
key = str(row.get("trade_id", row.get("slot_id", row.get("event_id", ""))))
|
||||
self.client.get_map(name).put(key, json_safe(row))
|
||||
Reference in New Issue
Block a user