[GAP-050]: quantity-aware risk contract complete

- IRiskManager.cs: add quantity-aware ValidateOrder contract

- AdvancedRiskManager.cs: delegate Tier 1 through sized BasicRiskManager overload and preserve 3-arg behavior

- NT8StrategyBase.cs: remove BasicRiskManager type-check workaround and call sized interface method

- NT8OrderAdapter.cs: size before risk validation and pass actual contracts

- tests: add AdvancedRiskManager, NT8OrderAdapter, and NT8StrategyBase coverage

Build: clean | Tests: 566 passing; Core 476 passing | Dual-deployed: no - skipped by prompt
This commit is contained in:
2026-08-25 16:39:56 -04:00
parent a673475738
commit a99ce1d0e7
10 changed files with 388 additions and 15 deletions

View File

@@ -24,6 +24,15 @@ Use this file to record durable project decisions that affect implementation pat
- **Related Files:** `src/NT8.Adapters/Strategies/NT8StrategyBase.cs` (`MaybeWriteRejectSummarySnapshot`/`LogRejectRateLimited`/`ResetRejectTracking`/`WriteSessionHeader` ~1444-1517), `src/NT8.Strategies/Examples/SimpleORBStrategy.cs` (`OnBar` ~355-432, `RecordSignalRejection` ~1015-1026), `session_20260823_230519.log`
- **Implementation Note (2026-08-25):** GAP-060 implemented as logging/observability only. `NT8StrategyBase.MaybeWriteRejectSummarySnapshot()` no longer has a blanket midnight-to-10:00 AM suppression gate; suppression now delegates to an ORB-window-aware helper and `SimpleORBNT8` overrides that helper so the suppressed window is today's configured 09:30 + `OpeningRangeMinutes`. The once-after-ORB snapshot flag now resets per `barTime.Date`, allowing a new post-ORB summary every day in a continuous multi-day session. `OnBarUpdate()` now calls `MaybeWriteRejectSummarySnapshot(Time[0])` on the live bar heartbeat after the first realtime-bar guard, so 15-minute summary cadence can flush from regular processed bars and is not solely dependent on a newly logged reject. Existing `_rejectDetailsLogged` one-detail-line-per-reason rate limiting, reject reason strings, `REJECT:`/`REJECT SUMMARY:` formats, order flow, sizing, risk, and real trade decisions were unchanged. Open question resolved as possibility **(a)**: the missing `OrbRangeNotEstablished` visibility was adapter summary reporting, not a second SimpleORB rejection defect. A focused `SimpleORBStrategy.OnBar()` test proves the no-breakout RTH path records `OrbRangeNotEstablished` both while the ORB is building and after ORB close when no breakout confirms. Verification: focused GAP-060 tests passed 8/8; `verify-build.bat` passed with 543/543 tests (454 Core, 79 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 454/454.
- **Action Required:** Deployment remains pending. `deployment\deploy-to-nt8.bat` was attempted on 2026-08-25 but failed because NinjaTrader.exe PID 18800 locked `NT8.Core.dll`; operator instructed Kilocode to commit without deploy. After NinjaTrader is closed, rerun deployment, start NT8, manually compile NinjaScript, and in the next SIM session spanning a full trading day confirm `REJECT SUMMARY` appears throughout RTH at a reasonable cadence.
### DEC-20260825-03
- **ID:** DEC-20260825-03
- **Date:** 2026-08-25
- **Status:** implemented — Option A, deploy skipped by prompt
- **Context:** GAP-050 (`MaxTradeRisk` has no quantity term) was staged 2026-08-18 as an operator-decision item. Investigation on 2026-08-25 found the original framing ("$600 vs $1,000 daily limit") is stale for the live path: `SimpleORBNT8`/`NT8StrategyBase` constructs `BasicRiskManager` directly and already reaches the quantity-aware 4-arg `ValidateOrder(intent, context, config, candidateContracts)` overload via an `as BasicRiskManager` runtime type-check. `IRiskManager` itself, however, never declared a quantity-aware member. `AdvancedRiskManager` implemented `IRiskManager` but had no 4-arg overload and delegated Tier 1 to its inner `BasicRiskManager` through the 1-contract-assumed 3-arg call. `NT8OrderAdapter.ExecuteIntent` validated before sizing, so it also could not pass quantity. These scaffolding paths are not currently wired to live SimpleORB trading, but would silently reintroduce the 1-contract assumption if activated.
- **Decision:** Operator selected Option A: fix the contract at `IRiskManager`, add the quantity-aware implementation to `AdvancedRiskManager`, remove the live-path type-check workaround from `NT8StrategyBase`, and fix `NT8OrderAdapter.ExecuteIntent` to size before risk validation. Do not wire `AdvancedRiskManager` or `NT8OrderAdapter` into live trading in this task.
- **Implementation Note (2026-08-25):** `IRiskManager` now declares the quantity-aware 4-arg `ValidateOrder`; `BasicRiskManager` already satisfied the contract with no logic change; `AdvancedRiskManager` now has a 4-arg overload that forwards Tier 1 to `_basicRiskManager.ValidateOrder(..., candidateContracts)` and the 3-arg overload delegates to the 4-arg overload with `candidateContracts=1`; `NT8StrategyBase` now calls `_riskManager.ValidateOrder(intent, context, _riskConfig, sizingResult.Contracts)` directly instead of casting to `BasicRiskManager`; `NT8OrderAdapter.ExecuteIntent()` now sizes first, returns on `Contracts <= 0`, and then validates risk with the sized quantity. Added tests for quantity-aware AdvancedRiskManager rejection/allowance, backward-compatible 3-arg behavior, NT8OrderAdapter sized risk validation, and NT8StrategyBase source-level interface usage. Verification: focused Core tests passed 10/10; focused Integration tests passed 13/13; `verify-build.bat` passed with 566/566 tests (476 Core, 80 Integration, 10 Performance); `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --no-build --verbosity minimal` passed 476/476. Deploy intentionally skipped by task prompt.
- **Related Files:** `src/NT8.Core/Risk/IRiskManager.cs`, `src/NT8.Core/Risk/AdvancedRiskManager.cs`, `src/NT8.Adapters/Strategies/NT8StrategyBase.cs`, `src/NT8.Adapters/NinjaTrader/NT8OrderAdapter.cs`, `tests/NT8.Core.Tests/Risk/AdvancedRiskManagerTests.cs`, `tests/NT8.Core.Tests/Adapters/NT8StrategyBaseRiskContractTests.cs`, `tests/NT8.Integration.Tests/NT8OrderAdapterIntegrationTests.cs`, `TASK_GAP050_ADVANCED_RISK_QTY_PROMPT.md`
- **Action Required:** Deploy remains a separate manual operator step. No operator validation required before commit because the live path's underlying quantity-aware `BasicRiskManager` call is unchanged.
### DEC-20260825-04
- **ID:** DEC-20260825-04
- **Date:** 2026-08-25