exec(unified): UnifiedExecutor — initial-submit pipeline + S2 pain-fence

executor.py composes the built parts into one execute(request, snapshot): S-grade fence →
router.decide → placer.pre_submit → submit → register working. The initial-submit half that
complements DriveLoop's expiry half (analogue of pink_direct.py:1645-1700).

Composition rulings encoded + tested:
- S2/S3 pain-fence (§15.2): refused WHOLE, loudly, below T14 — never silently sliced.
- placer declines (spread gate) → cross ONLY if urgency crosses on expiry; ACQUIRE ABANDONS
  (a missed entry is free, §4-1). Both mutation-verified RED.
- TTL from urgency discipline: PROTECT 2s / ROTATE deadline_ms / ACQUIRE quote-lifetime.

contract.py: SGrade enum (S0-S3) + s_grade/parent_request_id fields. _constants: MAKER_QUOTE_TTL_S.

FIX (real bug, not just test): drive_loop._is_resolved EXIT was trade_id-based (a PINK
artifact — PINK reused the position's trade_id for exits). The agnostic layer never gets
the position id, so exit-done is now SIZE-based. Kept ENTER on clientOrderId match.

Full exec_unified suite: 94 green, mutation-litmus verified.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-07-15 02:30:30 +02:00
parent a310c92977
commit 21419b03d0
6 changed files with 376 additions and 3 deletions

View File

@@ -47,6 +47,24 @@ class UrgencyClass(Enum):
UrgencyClass.HARVEST, UrgencyClass.ROTATE)
class SGrade(Enum):
"""Size axis — orthogonal to the T-tier smartness ladder (spec §15.2).
Computed at intake from Appendix E's power-law depth model (per-asset, stress-adjusted),
or supplied by the caller. Below T14 the layer executes S0/S1 directly and REFUSES S2+
whole (the pain-fence) so nobody meets the large-size pain class by accident.
"""
S0 = 0 # size << top-of-book depth (walk < 1 tick) — any tier executes directly
S1 = 1 # walks visible levels (expected walk >= spread) — T2+ prices the walk
S2 = 2 # exceeds book capacity in the urgency window — must be SLICED; refused below T14
S3 = 3 # size IS the market (footprint moves MM behaviour) — MALKHUT/VIBRASS territory
@property
def needs_slicing(self) -> bool:
return self in (SGrade.S2, SGrade.S3)
@dataclass(frozen=True)
class ProtectiveSpec:
"""Attach-a-dead-man's-stop geometry (spec §10). Mark-based, rides the entry order.
@@ -113,6 +131,8 @@ class ExecutionRequest:
protective: ProtectiveSpec | None = None
advice: ExecutionAdvice | None = None
deadline_ms: int | None = None # caller's patience budget (ROTATE/ACQUIRE)
s_grade: SGrade = SGrade.S0 # size regime (§15.2); default S0 = fits at touch
parent_request_id: str | None = None # slicer family linkage (§15.2 T*.s), telemetry only
def __post_init__(self) -> None:
if not self.request_id: