|
42 | 42 | "SelectedWindowCountsC", "SelectedWindowError", "WIRE_VERSION", "WindowRequest", |
43 | 43 | "build_report_window", "calendar_record", "calendar_session", "calendar_timezone", |
44 | 44 | "canonical_timeframe", "capabilities_record", "check_native_counts", |
45 | | - "check_report_placements", "check_selected_curve", "check_unsupported_options", |
| 45 | + "check_report_placements", "check_selected_curve", "check_selected_sink_curve", |
| 46 | + "check_unsupported_options", |
46 | 47 | "refusal_for_plan", "report_shape_full", |
47 | 48 | "retained_rows", "support_policy", "timeframe_seconds", "update_rows_hash", |
48 | 49 | "validate_request", |
@@ -626,7 +627,30 @@ def check_selected_curve(curve: Sequence[Mapping[str, Any]], start_ms: int, |
626 | 627 | if set(point) != {"time_ms", "equity", "open_profit"}: |
627 | 628 | raise _invariant(f"point {position} of the selected curve does not have exactly " |
628 | 629 | "time_ms, equity and open_profit") |
629 | | - anchor = curve[0] |
| 630 | + _check_selected_anchor(curve[0], start_ms, initial_capital) |
| 631 | + |
| 632 | + |
| 633 | +def check_selected_sink_curve(anchor: Optional[Mapping[str, Any]], equity_points: int, |
| 634 | + start_ms: int, window_script_bars: int, |
| 635 | + initial_capital: Any) -> None: |
| 636 | + """Check a verified sink's E count and first E, without retaining its curve. |
| 637 | +
|
| 638 | + The fixed v1 reader has already checked every point's fields and types and |
| 639 | + the trailer; the engine's selected latches own pre-roll, contiguity and |
| 640 | + observation-count checks. Anchor semantics, including unresolved capital, |
| 641 | + are shared with the array path. |
| 642 | + """ |
| 643 | + if equity_points != window_script_bars + 1: |
| 644 | + raise _invariant(f"the selected curve has {equity_points} points, the plan says " |
| 645 | + f"{window_script_bars + 1}") |
| 646 | + if anchor is None or set(anchor) != {"time_ms", "equity", "open_profit"}: |
| 647 | + raise _invariant("point 0 of the selected curve does not have exactly " |
| 648 | + "time_ms, equity and open_profit") |
| 649 | + _check_selected_anchor(anchor, start_ms, initial_capital) |
| 650 | + |
| 651 | + |
| 652 | +def _check_selected_anchor(anchor: Mapping[str, Any], start_ms: int, |
| 653 | + initial_capital: Any) -> None: |
630 | 654 | if anchor["time_ms"] != start_ms or anchor["open_profit"] != 0: |
631 | 655 | raise _invariant("the selected curve does not start with the window anchor at T with " |
632 | 656 | "open profit 0") |
|
0 commit comments