Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions application/execution_receipt_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
)


# Only promote these explicit cycle reasons. Broad no-ops stay ``no_action``
# so existing digests and projections keep digest-compatible outcomes.
_NO_SIGNAL_REASON_HEADS = frozenset({"no_signal"})
_NO_REBALANCE_REASON_HEADS = frozenset({"no_rebalance", "target_diff_below_threshold"})


def attach_cycle_execution_receipt(
report: dict[str, Any],
cycle_result: object,
Expand Down Expand Up @@ -39,6 +45,11 @@ def attach_cycle_execution_receipt(
reconciliation_required=reconciliation_required,
risk_blocked=risk_blocked,
)
if outcome == "no_action" and not bool(report.get("dry_run")):
explicit = _explicit_non_action_outcome(execution)
if explicit is not None:
outcome = explicit
confirmation = "not_applicable"
return attach_runtime_execution_receipt(
report,
outcome=outcome,
Expand All @@ -64,3 +75,17 @@ def attach_terminal_fallback_execution_receipt(report: dict[str, Any]) -> dict[s

def _as_mapping(value: object) -> Mapping[str, Any]:
return value if isinstance(value, Mapping) else {}


def _explicit_non_action_outcome(execution: Mapping[str, Any]) -> str | None:
"""Map only explicit cycle reasons to no_signal / no_rebalance."""

reason = str(execution.get("no_op_reason") or "").strip().lower()
if not reason:
return None
head = reason.split(":", 1)[0].strip()
if head in _NO_SIGNAL_REASON_HEADS:
return "no_signal"
if head in _NO_REBALANCE_REASON_HEADS:
return "no_rebalance"
return None
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = [
"google-cloud-storage",
"google-auth",
"numpy",
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@1826204e2927f4812a69348dd9c3d5235265be88",
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@f982aea79476cadd54d074f7c0447c1111658968",
"us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@4a3943883cd6b5bbfe32a559e56a91b40a81b7ce",
]

Expand Down Expand Up @@ -61,5 +61,5 @@ include = [

[tool.uv]
override-dependencies = [
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@1826204e2927f4812a69348dd9c3d5235265be88",
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@f982aea79476cadd54d074f7c0447c1111658968",
]
2 changes: 1 addition & 1 deletion qsl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ upgrade_ring = "ring_d"
allow_legacy = false

[qsl.requires]
quant_platform_kit = "1826204e2927f4812a69348dd9c3d5235265be88"
quant_platform_kit = "f982aea79476cadd54d074f7c0447c1111658968"
us_equity_strategies = "4a3943883cd6b5bbfe32a559e56a91b40a81b7ce"

[qsl.compat]
Expand Down
55 changes: 55 additions & 0 deletions tests/test_execution_receipt_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,58 @@ def test_strategy_risk_rejection_is_persisted_as_risk_blocked(self) -> None:

self.assertEqual(report["execution_receipt"]["outcome"], "risk_blocked")
self.assertEqual(report["execution_receipt"]["broker_confirmation"], "not_applicable")

def test_explicit_no_signal_reason_is_no_signal(self) -> None:
report = _report()

attach_cycle_execution_receipt(
report,
SimpleNamespace(execution={"no_op_reason": "no_signal"}, submitted_orders=()),
)

self.assertEqual(report["execution_receipt"]["outcome"], "no_signal")
self.assertEqual(report["execution_receipt"]["broker_confirmation"], "not_applicable")

def test_explicit_no_rebalance_reason_is_no_rebalance(self) -> None:
report = _report()

attach_cycle_execution_receipt(
report,
SimpleNamespace(
execution={
"execution_status": "no_op",
"no_op_reason": "target_diff_below_threshold",
},
submitted_orders=(),
),
)

self.assertEqual(report["execution_receipt"]["outcome"], "no_rebalance")
self.assertEqual(report["execution_receipt"]["broker_confirmation"], "not_applicable")

def test_ambiguous_no_op_reason_stays_no_action(self) -> None:
report = _report()

attach_cycle_execution_receipt(
report,
SimpleNamespace(
execution={"execution_status": "no_op", "no_op_reason": "market_closed"},
submitted_orders=(),
),
)

self.assertEqual(report["execution_receipt"]["outcome"], "no_action")

def test_dry_run_keeps_no_action_even_with_explicit_reason(self) -> None:
report = _report()
report["dry_run"] = True

attach_cycle_execution_receipt(
report,
SimpleNamespace(
execution={"no_op_reason": "no_signal"},
submitted_orders=(),
),
)

self.assertEqual(report["execution_receipt"]["outcome"], "no_action")
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.