diff --git a/SPRINT_BOARD.md b/SPRINT_BOARD.md index 5c8aef0..f61ad5a 100644 --- a/SPRINT_BOARD.md +++ b/SPRINT_BOARD.md @@ -1,5 +1,5 @@ # NT8 SDK — Sprint Board -**Last Updated:** 2026-08-26 (GAP-025 implemented/deployed; GAP-030 prompted next) +**Last Updated:** 2026-08-26 (GAP-030 implemented/deployed test-only; GAP-022-FOLLOWUP prompted) **Truth source:** compiler output, test output, deployed-file comparisons, and runtime artifacts override board claims. ## Current gate state @@ -152,13 +152,15 @@ The dirty working tree — several modified/untracked files including live strat - Scoped diagnostic-only: adds an `ORDER {signal} State=... Filled=.../... AvgFillPrice=...` FileLog line to `OnOrderUpdate` for every transition, and adds the signal name to the existing `FILL` line. Zero change to order submission, sizing, or execution-adapter logic. - Prompt: `TASK_GAP025_RUNNER_ORDER_LIFECYCLE_LOGGING_PROMPT.md`. Implemented as additive logging only: `OnOrderUpdate` now writes realtime `ORDER SDK_... State=... Filled=.../... AvgFillPrice=...` lines for SDK-managed order transitions, and the existing `FILL` line now includes `Signal=...` so scaler/runner fills are distinguishable. Existing circuit-breaker, execution-adapter, and portfolio-risk callbacks were left unchanged. Verification: focused Adapter tests 81/81, `verify-build.bat` 572/572. Deploy backup `20260826_010153`. -**[GAP-022-FOLLOWUP] Connection-State Test Seam** | Sprint 2.7 | ⏳ QUEUED — branch-only during Gate Run #2 -- Add an injectable connection-state seam around `NT8StrategyBase`. -- Then implement the three deferred scenarios: news-day reduced sizing, mid-trade disconnect, and pre-entry disconnect. +**[GAP-022-FOLLOWUP] Injectable connection-state seam + 2 of 3 deferred scenario tests** | Sprint 2.7 | 🟡 PROMPTED +- `ScenarioTests.cs`'s own TODO block (more precise than this board's old one-line summary) names three deferred scenarios: `NEWS_DAY_REDUCED_SIZE` (needs a high-impact-event calendar + sizing-policy API that doesn't exist yet — separate, larger, not-yet-designed scope, explicitly excluded from this task), `MID_TRADE_DISCONNECT`, and `PRE_ENTRY_DISCONNECT` (both need the connection-state seam). +- Confirmed on 2026-08-26: `_connectionLost` is a bare private field on `NT8StrategyBase`, set only by `OnConnectionStatusUpdate` and checked once early in `OnBarUpdate` — there is no re-check immediately before order submission (`ProcessStrategyIntent`/`SubmitOrderToNT8`), confirming `PRE_ENTRY_DISCONNECT`'s TODO is a real, if narrow, gap. +- Scoped to extract connection state into a new plain (non-NinjaScript-derived) class so it's genuinely unit-testable, add the missing pre-submit re-check, and implement `MID_TRADE_DISCONNECT`/`PRE_ENTRY_DISCONNECT` as real execution tests against it. `NEWS_DAY_REDUCED_SIZE` stays deferred. +- Prompt: `TASK_GAP022_FOLLOWUP_CONNECTION_SEAM_PROMPT.md`. -**[GAP-030] Historical ORB range hydration on a late strategy enable** | Sprint 2.7 | 🟡 PROMPTED — verify-first +**[GAP-030] Historical ORB range hydration on a late strategy enable** | Sprint 2.7 | ✅ IMPLEMENTED — test-only, deployed 2026-08-26 - Traced on 2026-08-26: `SimpleORBStrategy.OnBar()`'s ORB-building logic is state-blind (no `State.Historical`/`Realtime` awareness at all in `StrategyContext`) and accumulates the range from whatever bars it's given; `NT8StrategyBase.OnBarUpdate()` doesn't currently block `State.Historical` bars from reaching it; and `ProcessStrategyIntent()` already has an explicit `State == State.Historical` guard blocking any real order from a historical-replay bar. **This suggests both halves GAP-030 originally asked for may already exist by construction** — but the task explicitly requires Kilocode to verify (not assume) that NT8 actually delivers same-day historical catch-up bars on a late enable before treating it as settled, and to only implement new logic if that verification finds a real gap; otherwise the task closes the missing test-coverage gap instead. -- Prompt: `TASK_GAP030_ORB_HYDRATION_VERIFY_PROMPT.md`. +- Prompt: `TASK_GAP030_ORB_HYDRATION_VERIFY_PROMPT.md`. Verify-first outcome: no production hydration logic added. Source trace confirmed repo-side behavior works by construction: Core `SimpleORBStrategy` is state-blind and hydrates ORB range from delivered bars, `NT8StrategyBase.OnBarUpdate()` does not block `State.Historical` bars before `_sdkStrategy.OnBar()`, and `ProcessStrategyIntent()` blocks live-account historical orders before risk/submission via `HistoricalReplayCatchup`. Added tests for full-window and partial-window delivered-bar hydration plus adapter source assertions for no executable pre-`OnBar` historical block and preserved historical order guard. Verification: focused GAP-030 tests 4/4, `verify-build.bat` 576/576. Deploy backup `20260826_010653`. External NT8 docs did not prove the late-enable same-day delivery assumption; remaining validation is operator/platform observation. **[GAP-007] Walk-Forward Validation** | Sprint 2.7 | ⏳ QUEUED — only after a passing Gate Run #2 ruling diff --git a/docs/00-governance/current_status.md b/docs/00-governance/current_status.md index b4946a9..807f189 100644 --- a/docs/00-governance/current_status.md +++ b/docs/00-governance/current_status.md @@ -1,5 +1,13 @@ # Current Status — NT8 SDK -**Last Updated:** 2026-08-26 (GAP-025 implemented; GAP-030 next) +**Last Updated:** 2026-08-26 (GAP-030 implemented/deployed test-only) + +--- + +## 2026-08-26 — GAP-030 verified; repo-side fix is test coverage only + +Implemented `TASK_GAP030_ORB_HYDRATION_VERIFY_PROMPT.md` as a verify-first, test-only task. The source trace checked out: `SimpleORBStrategy.OnBar()` has no historical/realtime state input and builds the ORB range from every delivered in-window bar; `NT8StrategyBase.OnBarUpdate()` does not block `State.Historical` bars before `_sdkStrategy.OnBar()`; `ProcessStrategyIntent()` retains the live-account `State == State.Historical && Account != null` guard before portfolio risk, sizing, and submission. No production hydration logic was added. + +Added tests proving full-window replay hydrates `_openingRangeHigh`/`_openingRangeLow` and marks `OpeningRangeReady` on the first post-window bar, partial-window delivered bars hydrate from the bars actually delivered, `OnBarUpdate()` does not contain an executable pre-`OnBar` historical block, and `ProcessStrategyIntent()` keeps the `HistoricalReplayCatchup` order-submission guard. Focused GAP-030 tests passed 4/4; `verify-build.bat` passed 576/576. Deploy completed with backup `20260826_010653`; `NinjaTrader.Custom.dll` was already absent. External NT8 docs fetched during the task did not prove whether a late enable always receives same-day historical bars, so that platform behavior remains an operator observation point rather than a source-code defect. --- diff --git a/docs/00-governance/decisions.md b/docs/00-governance/decisions.md index f4989f1..95aa06f 100644 --- a/docs/00-governance/decisions.md +++ b/docs/00-governance/decisions.md @@ -13,6 +13,29 @@ Use this file to record durable project decisions that affect implementation pat ## Decision Log +### DEC-20260826-06 +- **ID:** DEC-20260826-06 +- **Date:** 2026-08-26 +- **Status:** implemented — test-only repo change, deployed by operator request +- **Context:** GAP-030 asked whether late strategy enable correctly hydrates the current day's ORB range from historical bars and prevents live-account orders from historical catch-up bars. Source verification confirmed the repo-side trace from `DEC-20260826-03`: Core `SimpleORBStrategy` cannot distinguish historical from realtime because `StrategyContext` has no such field, `UpdateOpeningRange()` accumulates from any delivered in-window `BarData`, `NT8StrategyBase.OnBarUpdate()` does not block `State.Historical` bars before `_sdkStrategy.OnBar()`, and `ProcessStrategyIntent()` blocks `State == State.Historical && Account != null` before risk/sizing/submission. Fetched NT8 `OnBarUpdate()` documentation did not expose enough body text to prove whether late enable always receives same-day historical catch-up bars, so that platform-delivery assumption remains an operator observation point. +- **Decision:** Do not add redundant production hydration logic. Close the repo-side coverage gap with tests proving the existing behavior and guard placement. +- **Proof:** Added `SimpleORBHydrationTests` proving full-window delivered bars hydrate the expected ORB high/low and mark `OpeningRangeReady` on the first post-window bar, and partial-window delivered bars hydrate from the bars actually delivered. Added `NT8StrategyBaseHistoricalGuardTests` proving `OnBarUpdate()` has no executable pre-`_sdkStrategy.OnBar()` `State.Historical` block and `ProcessStrategyIntent()` still contains the `HistoricalReplayCatchup` live-account guard before portfolio risk and order submission. +- **Verification:** `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --filter "FullyQualifiedName~SimpleORBHydration|FullyQualifiedName~NT8StrategyBaseHistoricalGuard" --verbosity minimal` passed 4/4. `verify-build.bat` passed 576/576. Deploy completed with backup `20260826_010653`; `NinjaTrader.Custom.dll` was already absent. +- **Related Files:** `TASK_GAP030_ORB_HYDRATION_VERIFY_PROMPT.md`, `tests/NT8.Core.Tests/Strategies/SimpleORBHydrationTests.cs`, `tests/NT8.Core.Tests/Adapters/NT8StrategyBaseHistoricalGuardTests.cs`, `src/NT8.Strategies/Examples/SimpleORBStrategy.cs`, `src/NT8.Adapters/Strategies/NT8StrategyBase.cs`, `SPRINT_BOARD.md`, `docs/00-governance/current_status.md`. +- **Action Required:** Manual NinjaScript compile after deploy. On the next SIM late-enable check, confirm whether NT8 delivers same-day ORB-window historical bars as expected; if it does not, stage a new production fix based on that observed platform behavior. + +### DEC-20260826-05 +- **ID:** DEC-20260826-05 +- **Date:** 2026-08-26 +- **Status:** decided — prompted; DASH-002 re-prompt averted +- **Context:** Continuing "what comes next" after GAP-025/GAP-030. Two candidates were checked against current source before prompting either, to avoid wasting Kilocode effort on stale backlog framing: + - **DASH-002** was about to be re-prompted with a refreshed deadline framing, but a `git status`/grep check first found `EnableStateTelemetry` already fully implemented in `NT8StrategyBase.cs` (property, default-true assignment commented "DASH-002: additive realtime observability", the `MaybeWriteStateTelemetry` gate, and the settings-export line) and confirmed live via this session's own prior `STATE:`/`STATE_CONTEXT` investigations (GAP-047/059/060/061 all read from telemetry DASH-002 produces). SPRINT_BOARD's "🔵 ACTIVE... no implementation has landed" framing was stale. **Not re-prompted** — would have been duplicate work. The refreshed `TASK_DASH-002_PROMPT.md` draft was reverted back to its original 2026-08-16 content since DASH-002 needs no further action. + - **GAP-022-FOLLOWUP** checked out as still genuinely open: `ScenarioTests.cs`'s own TODO block (more precise than SPRINT_BOARD's old one-liner) names `NEWS_DAY_REDUCED_SIZE` (needs a calendar + sizing-policy API that doesn't exist — separate, larger, undesigned scope), `MID_TRADE_DISCONNECT`, and `PRE_ENTRY_DISCONNECT` (both blocked on the missing connection-state seam). Confirmed via source read: `_connectionLost` is checked once early in `OnBarUpdate` with no re-check immediately before order submission — `PRE_ENTRY_DISCONNECT`'s TODO description is accurate, not stale. +- **Decision:** Prompted `TASK_GAP022_FOLLOWUP_CONNECTION_SEAM_PROMPT.md`, scoped to only the two seam-blocked scenarios (extract connection state into a new, plain, unit-testable class; add the missing pre-submit re-check; implement `MID_TRADE_DISCONNECT`/`PRE_ENTRY_DISCONNECT` as real execution tests). `NEWS_DAY_REDUCED_SIZE` explicitly excluded — flagged as a separate future task once a news-calendar/sizing-policy design exists. +- **Consequences:** Avoided handing Kilocode a redundant DASH-002 re-implementation. GAP-022-FOLLOWUP's scope is now honest and matches what `ScenarioTests.cs`'s own TODO says is actually missing, rather than the three-scenario bundle SPRINT_BOARD previously implied. +- **Related Files:** `TASK_GAP022_FOLLOWUP_CONNECTION_SEAM_PROMPT.md`, `tests/NT8.Core.Tests/Scenarios/ScenarioTests.cs`, `src/NT8.Adapters/Strategies/NT8StrategyBase.cs`, `SPRINT_BOARD.md`. +- **Action Required:** Await Kilocode's implementation and commit; verify by reading the diff directly per standing practice. + ### DEC-20260826-04 - **ID:** DEC-20260826-04 - **Date:** 2026-08-26 diff --git a/tests/NT8.Core.Tests/Adapters/NT8StrategyBaseHistoricalGuardTests.cs b/tests/NT8.Core.Tests/Adapters/NT8StrategyBaseHistoricalGuardTests.cs new file mode 100644 index 0000000..c2b17ca --- /dev/null +++ b/tests/NT8.Core.Tests/Adapters/NT8StrategyBaseHistoricalGuardTests.cs @@ -0,0 +1,82 @@ +using System; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace NT8.Core.Tests.Adapters +{ + [TestClass] + public class NT8StrategyBaseHistoricalGuardTests + { + [TestMethod] + public void OnBarUpdate_DoesNotBlockStateHistoricalBeforeSdkStrategyOnBar() + { + string source = File.ReadAllText(FindStrategyBaseSourceFile()); + string method = ExtractMethodBlock(source, "protected override void OnBarUpdate"); + int replayGuard = method.IndexOf("if (State == State.Realtime)", StringComparison.Ordinal); + int onBar = method.IndexOf("_sdkStrategy.OnBar", StringComparison.Ordinal); + + Assert.IsTrue(replayGuard >= 0, "OnBarUpdate must retain the realtime replay-burst guard."); + Assert.IsTrue(onBar > replayGuard, "OnBarUpdate must still call the SDK strategy after early guards."); + Assert.IsFalse(method.Contains("if (State == State.Historical)"), "State.Historical bars must not be blocked before the SDK strategy can hydrate the ORB range."); + Assert.IsFalse(method.Contains("if (State == State.Historical && Account != null)"), "Live-account historical order blocking belongs in ProcessStrategyIntent, after ORB hydration."); + } + + [TestMethod] + public void ProcessStrategyIntent_BlocksLiveAccountHistoricalOrdersBeforeRiskAndSubmission() + { + string source = File.ReadAllText(FindStrategyBaseSourceFile()); + string method = ExtractMethodBlock(source, "private void ProcessStrategyIntent"); + + int historicalGuard = method.IndexOf("if (State == State.Historical && Account != null)", StringComparison.Ordinal); + int portfolioRisk = method.IndexOf("Portfolio-level risk check", StringComparison.Ordinal); + int submit = method.IndexOf("SubmitOrderToNT8", StringComparison.Ordinal); + + Assert.IsTrue(historicalGuard >= 0, "ProcessStrategyIntent must retain the live-account historical guard."); + Assert.IsTrue(method.Contains("HistoricalReplayCatchup"), "Historical catch-up rejections must remain diagnosable."); + Assert.IsTrue(method.Contains("return;"), "Historical catch-up guard must return before order processing."); + Assert.IsTrue(portfolioRisk > historicalGuard, "Historical guard must run before portfolio risk."); + Assert.IsTrue(submit > historicalGuard, "Historical guard must run before order submission."); + } + + private static string FindStrategyBaseSourceFile() + { + DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); + while (dir != null) + { + string candidate = Path.Combine(dir.FullName, "src", "NT8.Adapters", "Strategies", "NT8StrategyBase.cs"); + if (File.Exists(candidate)) + return candidate; + dir = dir.Parent; + } + + throw new FileNotFoundException("Could not locate src\\NT8.Adapters\\Strategies\\NT8StrategyBase.cs from test output directory."); + } + + private static string ExtractMethodBlock(string source, string signature) + { + int start = source.IndexOf(signature, StringComparison.Ordinal); + if (start < 0) + Assert.Fail("Source does not contain method: " + signature); + + int brace = source.IndexOf("{", start, StringComparison.Ordinal); + if (brace < 0) + Assert.Fail("Method has no opening brace: " + signature); + + int depth = 0; + for (int i = brace; i < source.Length; i++) + { + if (source[i] == '{') + depth++; + else if (source[i] == '}') + { + depth--; + if (depth == 0) + return source.Substring(start, i - start + 1); + } + } + + Assert.Fail("Method has no closing brace: " + signature); + return string.Empty; + } + } +} diff --git a/tests/NT8.Core.Tests/Strategies/SimpleORBHydrationTests.cs b/tests/NT8.Core.Tests/Strategies/SimpleORBHydrationTests.cs new file mode 100644 index 0000000..e8775b9 --- /dev/null +++ b/tests/NT8.Core.Tests/Strategies/SimpleORBHydrationTests.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NT8.Core.Common.Models; +using NT8.Core.Logging; +using NT8.Strategies.Examples; + +namespace NT8.Core.Tests.Strategies +{ + [TestClass] + public class SimpleORBHydrationTests + { + [TestMethod] + public void OnBar_FullOpeningWindowReplay_HydratesOpeningRangeBeforeRealtimeBreakout() + { + SimpleORBStrategy strategy = CreateStrategy(); + DateTime sessionStart = DateTime.Today.AddHours(9.5); + StrategyContext context = CreateContext(sessionStart); + + StrategyIntent first = strategy.OnBar(CreateBar(sessionStart.AddMinutes(5), 19000.0, 19040.0, 18990.0, 19020.0), context); + context.CurrentTime = sessionStart.AddMinutes(15); + StrategyIntent second = strategy.OnBar(CreateBar(sessionStart.AddMinutes(15), 19020.0, 19080.0, 19010.0, 19050.0), context); + context.CurrentTime = sessionStart.AddMinutes(29); + StrategyIntent third = strategy.OnBar(CreateBar(sessionStart.AddMinutes(29), 19050.0, 19070.0, 18975.0, 19000.0), context); + context.CurrentTime = sessionStart.AddMinutes(35); + StrategyIntent afterWindow = strategy.OnBar(CreateBar(sessionStart.AddMinutes(35), 19010.0, 19030.0, 18995.0, 19015.0), context); + + Assert.IsNull(first, "Opening-window replay bars must not create intents while the range is building."); + Assert.IsNull(second, "Opening-window replay bars must not create intents while the range is building."); + Assert.IsNull(third, "Opening-window replay bars must not create intents while the range is building."); + Assert.IsNull(afterWindow, "A non-breakout bar after replay hydration must not create an intent."); + Assert.AreEqual(19080.0, strategy.OpeningRangeHigh, 0.000001); + Assert.AreEqual(18975.0, strategy.OpeningRangeLow, 0.000001); + Assert.IsTrue(strategy.OpeningRangeReady, "The first post-window bar should mark the replay-built range ready."); + } + + [TestMethod] + public void OnBar_PartialOpeningWindowReplay_HydratesFromDeliveredBarsWithoutNewProductionLogic() + { + SimpleORBStrategy strategy = CreateStrategy(); + DateTime sessionStart = DateTime.Today.AddHours(9.5); + StrategyContext context = CreateContext(sessionStart); + + StrategyIntent firstDelivered = strategy.OnBar(CreateBar(sessionStart.AddMinutes(18), 19020.0, 19055.0, 19005.0, 19035.0), context); + context.CurrentTime = sessionStart.AddMinutes(28); + StrategyIntent secondDelivered = strategy.OnBar(CreateBar(sessionStart.AddMinutes(28), 19035.0, 19062.0, 18992.0, 19010.0), context); + context.CurrentTime = sessionStart.AddMinutes(34); + StrategyIntent afterWindow = strategy.OnBar(CreateBar(sessionStart.AddMinutes(34), 19005.0, 19025.0, 18998.0, 19008.0), context); + + Assert.IsNull(firstDelivered); + Assert.IsNull(secondDelivered); + Assert.IsNull(afterWindow); + Assert.AreEqual(19062.0, strategy.OpeningRangeHigh, 0.000001); + Assert.AreEqual(18992.0, strategy.OpeningRangeLow, 0.000001); + Assert.IsTrue(strategy.OpeningRangeReady); + } + + private static SimpleORBStrategy CreateStrategy() + { + SimpleORBStrategy strategy = new SimpleORBStrategy(30, 1.0); + StrategyConfig config = new StrategyConfig( + "SimpleORB", + "NQ", + new Dictionary(), + new RiskConfig(1000.0, 200.0, 2, false), + new SizingConfig(SizingMethod.FixedDollarRisk, 1, 3, 100.0, null)); + config.Parameters.Add("TestMode", false); + config.Parameters.Add("MaxDailyTrades", 1); + config.Parameters.Add("StopTicks", 8); + config.Parameters.Add("TargetTicks", 16); + config.Parameters.Add("MinTradeGrade", 1); + strategy.Initialize(config, null, new BasicLogger("test")); + return strategy; + } + + private static StrategyContext CreateContext(DateTime sessionStart) + { + MarketSession session = new MarketSession(sessionStart, sessionStart.Date.AddHours(16), true, "RTH"); + return new StrategyContext( + "NQ", + sessionStart, + null, + new AccountInfo(100000.0, 100000.0, 0.0, 0.0, DateTime.UtcNow), + session, + new Dictionary()); + } + + private static BarData CreateBar(DateTime time, double open, double high, double low, double close) + { + return new BarData("NQ", time, open, high, low, close, 1000, TimeSpan.FromMinutes(5)); + } + } +}