PINK: TUI Hz fix + DC gate + ACB boost + 10 new tests (104/104 green)

TUI Hz fix:
- hazelcast_projection.py: write_engine_snapshot now writes all NAUTILUS-era
  field aliases (trades_executed, current_leverage, open_positions as list,
  last_scan_number, last_vel_div, vol_ok, open_notional) so gear_rows/capital
  panel work with no TUI changes.
- dolphin_status_pink.py: _normalize_eng_for_tui() safety-net translation added;
  render() uses it on every Hz read.

DC gate (SYSTEM BIBLE §4.2, champion config):
- pink_direct.py: _dc_contradicts() — 7-tick lookback, 0.75 bps threshold.
  Rising price (chg > 0.75 bps) blocks ENTER via dataclasses.replace(HOLD, DC_CONTRADICT).
  Price history deque initialized in connect(); dc_skip_contradicts=True enforced.

ACB boost (SYSTEM BIBLE §10):
- hazelcast_feed.py: fix wrong key "latest_acb" → "acb_boost" (DOLPHIN_FEATURES key
  written by acb_processor_service.py).
- pink_direct.py: _last_acb_boost read from scan_payload["acb_boost"] first (scan
  bridge may embed it), then Hz direct fallback. Applied to intent.leverage via
  dataclasses.replace() after IntentEngine.plan(), capped at 3x.
- _last_scan_number, _last_vel_div, _last_vol_ok tracked from scan_payload.

OBF gate: NOT implemented. OBF shards (DOLPHIN_FEATURES_SHARD_*) require new
Hz map connections + symbol routing. Gap documented; requires separate decision.

Tests: TestDCGate (5) + TestNormalizeEngForTui (5) — 10 new, 104 total, all green.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-06-03 14:00:48 +02:00
parent 8d85d75ded
commit 29d44c338e
5 changed files with 435 additions and 12 deletions

View File

@@ -131,31 +131,56 @@ class PinkHzStateWriter:
acc_dict: dict,
posture: str = "APEX",
our_leverage: float = 0.0,
scan_number: int = 0,
vel_div: float = 0.0,
vol_ok: bool = True,
) -> None:
"""Write full engine state. Called after every kernel mutation (non-blocking)."""
"""Write full engine state. Called after every kernel mutation (non-blocking).
Field names mirror DOLPHIN_STATE_BLUE["engine_snapshot"] where possible so
the existing PINK TUI panels (gear_rows, capital panel, etc.) work without
modification. DITAv2-specific fields are additive.
"""
open_pos_int = int(acc_dict.get("open_positions", 0))
trade_seq = int(acc_dict.get("trade_seq", 0))
size = float(slot_dict.get("size") or 0.0)
ep = float(slot_dict.get("entry_price") or 0.0)
open_notional = size * ep
payload: dict[str, Any] = {
# Core (BLUE-compatible names)
"strategy": "pink",
"capital": acc_dict.get("capital", 0.0),
"equity": acc_dict.get("equity", 0.0),
"available_capital": acc_dict.get("available_capital", 0.0),
"pnl": acc_dict.get("realized_pnl_total", 0.0),
"fee_total": acc_dict.get("fee_total", 0.0),
"open_positions": int(acc_dict.get("open_positions", 0)),
"trade_seq": int(acc_dict.get("trade_seq", 0)),
"posture": posture,
"capital_frozen": bool(acc_dict.get("capital_frozen", False)),
"updated_at": _utcnow_iso(),
# TUI-compatible aliases (NAUTILUS-era field names expected by gear_rows etc.)
"trades_executed": trade_seq,
"current_leverage": our_leverage,
"leverage_abs_cap": 3.0,
"open_notional": open_notional,
"open_positions": [slot_dict] if open_pos_int > 0 else [],
"last_scan_number": scan_number,
"scans_processed": scan_number,
"last_vel_div": vel_div,
"vol_ok": vol_ok,
"bar_idx": scan_number,
# DITAv2-native fields
"trade_seq": trade_seq,
"our_leverage": our_leverage,
"slot": slot_dict,
"updated_at": _utcnow_iso(),
}
_hz_write_no_wait(self._state_map, "engine_snapshot", _json_encode(payload))
# Compact "latest" key — same shape as BLUE's DOLPHIN_STATE_BLUE["latest"]
# Compact "latest" — same shape as BLUE's DOLPHIN_STATE_BLUE["latest"]
_hz_write_no_wait(self._state_map, "latest", _json_encode({
"strategy": "pink",
"capital": payload["capital"],
"date": _today_iso(),
"pnl": payload["pnl"],
"trades": payload["trade_seq"],
"trades": trade_seq,
"posture": posture,
"updated_at": payload["updated_at"],
}))