- 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
10 KiB
TASK: GAP-050 — MaxTradeRisk quantity term missing from IRiskManager contract
Staged: 2026-08-18 (v7.0 review, "raised, not yet prompted"), decided 2026-08-25 (Option A)
Sprint: Stage 1 — risk-interface hardening, no live-behaviour change (see THE DEFECT)
Owner: Kilocode
Deploy: COMMIT ONLY — do NOT run deploy-to-nt8.bat or copy build output to
the live NT8 install as part of this task. Verify-build and commit
as usual; leave the deploy step for the operator to run manually
once ready.
─────────────────────────────────────────────────────────────────
THE DEFECT
MaxTradeRisk was originally flagged as "no quantity term — worst case is
$600 against a $1,000 daily limit." That framing is stale for the live
path — verify this yourself in READ-FIRST before touching anything — but
the underlying interface gap is real and worth closing properly.
Current state, confirmed by direct source read on 2026-08-25:
BasicRiskManagerhas TWO overloads:ValidateOrder(intent, context, config)(3-arg, hardcodescandidateContracts=1by calling the 4-arg version) andValidateOrder(intent, context, config, candidateContracts)(4-arg, real quantity —CalculateTradeRiskmultipliesStopTicks * tickValue * candidateContracts).IRiskManager(src/NT8.Core/Risk/IRiskManager.cs) only declares the 3-argValidateOrder(intent, context, config). The 4-arg overload is NOT part of the interface — it only exists as a concrete method onBasicRiskManager.- The live path is already safe, but only via a workaround, not the
interface:
SimpleORBNT8/NT8StrategyBase(NT8StrategyBase.cs:1763) constructs_riskManager = new BasicRiskManager(...)directly, and the order-eval flow (~2131-2136) doesvar basicRiskManager = _riskManager as BasicRiskManager; var riskDecision = basicRiskManager != null ? basicRiskManager.ValidateOrder(intent, context, _riskConfig, sizingResult.Contracts) : _riskManager.ValidateOrder (intent, context, _riskConfig);— a runtime type-check working around the interface's own gap, only correct today because nothing else is plugged into_riskManager. AdvancedRiskManager(src/NT8.Core/Risk/AdvancedRiskManager.cs) implementsIRiskManagerbut has no 4-argValidateOrderat all. Its 3-argValidateOrderdelegates Tier 1 to its inner_basicRiskManagervia the 1-contract-assumed 3-arg overload. Confirmed not currently wired to anything live —new AdvancedRiskManager(does not appear anywhere insrc/outside its own file; the only places it is constructed aretests/NT8.Core.Tests/Risk/AdvancedRiskManagerTests.csandtests/NT8.Integration.Tests/RiskSizingIntegrationTests.cs, both of which build it directly and call it in isolation.NT8OrderAdapter.ExecuteIntent(src/NT8.Adapters/NinjaTrader/ NT8OrderAdapter.cs) calls_riskManager.ValidateOrder(intent, context, config.RiskSettings)(3-arg) before calling_positionSizer. CalculateSize(...)— backwards even if the interface supported quantity, since the real size isn't known yet at the point risk is checked.NT8OrderAdapter/NT8Adapterare, in turn, only constructed byBaseNT8StrategyWrapper(src/NT8.Adapters/Wrappers/ BaseNT8StrategyWrapper.cs), whose own doc comment says: "This is a template that would be extended in actual NT8 strategy files" — nothing insrc/extends it. Confirmed not on the live path.
Net: today's SIM/live trading is not exposed. The gap is an interface contract hole that happens to be papered over by a type-check in the one place that matters right now, plus two pieces of unwired scaffolding that would silently reintroduce the 1-contract assumption the moment either is ever wired up. Fix it at the interface so this can't recur by accident.
READ-FIRST
src/NT8.Core/Risk/IRiskManager.cs— current interface, 3-arg only.src/NT8.Core/Risk/BasicRiskManager.cs(~lines 40-90) — the existing 3-arg-calls-4-arg pattern to mirror.src/NT8.Core/Risk/AdvancedRiskManager.cs(full file) — constructor wraps a realBasicRiskManager; existing 3-argValidateOrderruns Tier 1 via the inner basic manager, then Tier 2 (weekly loss, trailing drawdown), Tier 3 (cross-strategy exposure, time restrictions, correlation), and Tier 3.5 (portfolio heat, GAP-019) — all unchanged by this task.src/NT8.Adapters/Strategies/NT8StrategyBase.cs~2095-2145 — the sizing-then-risk-check flow and theas BasicRiskManagerternary this task removes.src/NT8.Adapters/NinjaTrader/NT8OrderAdapter.cs(full file, short) — theExecuteIntentvalidate-before-size ordering this task fixes.- Re-run the greps yourself before starting — confirm
new AdvancedRiskManager(andnew NT8OrderAdapter(/new NT8Adapter(/new BaseNT8StrategyWrapper(/new SimpleORBNT8Wrapper(still don't appear anywhere insrc/outside their own definitions and test files. If that has changed since 2026-08-25, stop and flag it — the risk profile of this task changes if either is now live.
THE CHANGE — Option A (decided by operator 2026-08-25)
-
IRiskManager.cs: addRiskDecision ValidateOrder(StrategyIntent intent, StrategyContext context, RiskConfig config, int candidateContracts);to the interface. Keep the existing 3-arg member too (still required by both implementations for source/test compatibility). -
BasicRiskManager.cs: no logic change — it already has both signatures with the exact right behaviour. Just confirm it still compiles as anIRiskManagerafter step 1 (it should, with zero edits). -
AdvancedRiskManager.cs: add the 4-argValidateOrder(intent, context, config, candidateContracts). It should run Tier 1 via_basicRiskManager.ValidateOrder(intent, context, config, candidateContracts)(the real, quantity-aware overload) instead of the 3-arg one, then fall through to the exact same Tier 2/3/3.5 body the existing 3-arg method already has (do not duplicate that logic — factor it into a shared private method both the 3-arg and 4-arg public methods call, or have the 3-arg method call the new 4-arg one withcandidateContracts=1, mirroringBasicRiskManager's own pattern exactly — your call which is cleaner, but no behavioural duplication/ drift between the two). -
NT8StrategyBase.cs~2131-2136: remove theas BasicRiskManagercast and fallback entirely. Replace with a direct call:var riskDecision = _riskManager.ValidateOrder(intent, context, _riskConfig, sizingResult.Contracts);— now safe for anyIRiskManagerimplementation, not justBasicRiskManager. This must produce byte- identical behaviour for the live path (currently always aBasicRiskManagerinstance) — same underlying 4-arg call, just reached without the type-check. -
NT8OrderAdapter.csExecuteIntent: reorder so_positionSizer. CalculateSize(...)runs first, then call the 4-argValidateOrderwith the realsizingResult.Contractsinstead of the 3-arg call before sizing. Keep the existingsizingResult.Contracts <= 0early-return, just move it ahead of the risk check.
DO NOT
- Do not change
BasicRiskManager's existing logic — it's already correct and is the class actually protecting live trading today. - Do not change any of
AdvancedRiskManager's Tier 2/3/3.5 check bodies (ValidateWeeklyLimit,ValidateTrailingDrawdown,ValidateCrossStrategyExposure,ValidateTimeRestrictions,ValidateCorrelationLimits,ValidatePortfolioHeat) — only how Tier 1 is invoked changes. - Do not wire
AdvancedRiskManagerorNT8OrderAdapter/NT8Adapter/BaseNT8StrategyWrapperinto the liveSimpleORBNT8/NT8StrategyBaseconstruction path. That is a separate, much larger decision (switching which risk manager actually governs live trading) and is explicitly out of scope for this task — this task only guarantees correctness if that ever happens, it does not make it happen. - Do not touch
src/_archive/legacy-orders/OrderManager.cs— archived, out of scope. - Do not touch
RiskConfig/AdvancedRiskConfigfield shapes.
TESTS (required)
- New test(s) in
AdvancedRiskManagerTests.csproving the 4-argValidateOrdercorrectly scales rejected/allowed decisions bycandidateContracts(mirror the existing quantity-aware tests inBasicRiskManagerTests.csif any exist — same shape, e.g. a trade that passes at qty=1 but is correctly rejected at qty=3 onceStopTicks * tickValue * 3 > MaxTradeRisk). - A test proving
AdvancedRiskManager's 3-argValidateOrderstill behaves exactly as before (backward-compatibility / no regression for existing callers, includingRiskSizingIntegrationTests.cs). - A test proving
NT8OrderAdapter.ExecuteIntentnow callsValidateOrderwith the actual sized quantity, not a hardcoded 1 (construct with a test-double bridge/risk manager/sizer and assert the call). - Confirm the full existing suite still passes, including
RiskSizingIntegrationTests.csand anything covering theNT8StrategyBase.csternary area (source-text assertion is fine there, consistent with this codebase's established precedent for NinjaScript-derived classes that can't be instantiated directly).
VALIDATION (operator)
None required for correctness — the live path (BasicRiskManager reached
directly by SimpleORBNT8) is unchanged in behaviour, just reached via the
interface instead of a type-check. AdvancedRiskManager/NT8OrderAdapter
remain unwired to live trading after this task. No SIM/gate validation
needed before committing; deploy is still an explicit operator step per the
header above.
GOVERNANCE
Track as [GAP-050] in SPRINT_BOARD.md — promote out of the "operator
decision needed" catch-all line into its own entry, Option A implemented,
noting the live path was already safe and this closes the interface
contract gap plus the two unwired call sites. Update
docs/00-governance/decisions.md with a new dated entry recording Option A
and the implementation, referencing this task.
Reference: this task, DEC-20260825-03 (operator decision + investigation
findings), original v7.0 review staging (SPRINT_BOARD.md "Also raised by
the review, not yet prompted").