Sprint 3: Production Hardening — 9 tasks completed
## Summary Implemented 9 production-hardening tasks across risk, execution, calendar, and governance. All changes verified: build clean (0 errors), 492 tests passing (404 core + 78 integration + 10 perf). ## Core Changes ### Risk & Portfolio (3 tasks) - **GAP-019** Portfolio Heat Tier 3.5: Added MaxHeatPct (default 3%) to AdvancedRiskConfig; ValidatePortfolioHeat() computes TotalOpenRisk + NewTradeRisk / Equity * 100; rejects when exceeded. - **GAP-003** RiskPerTrade <= MaxTradeRisk Assertion: RiskPerTrade property in RiskConfig; throws ArgumentException at ValidateOrder() if RiskPerTrade > MaxTradeRisk; 3 unit tests. - **GAP-005** GetRiskStatus() Live Config: _currentDailyLossLimit field updated from config.DailyLossLimit on each ValidateOrder(); GetRiskStatus() returns actual value; 3 unit tests. ### Execution & Position Management (3 tasks) - **TASK-06a** Runner Mode Architecture: RunnerMode enum (Auto/Mode1DualLeg/Mode2RunnerOnly/ Mode3ScalerOnly/Disabled); ResolveRunnerMode() logic; 4-mode SubmitOrderToNT8() behavior. - **TASK-06b** ATR Dynamic Stop: EnableDynamicStop, AtrPeriod, AtrMultiplier, MinStopTicks, MaxStopTicks; computes dynStop = clamp(round(ATR/TickSize * Mult), Min, Max); overrides intent.StopTicks. - **GAP-006** Position-Close Re-arm: OnPositionUpdate() sends clear_trade_taken when flat; EnableBarBasedRearm parameter gates legacy bar-driven re-arm (default false for live). ### Strategy Intelligence (2 tasks) - **GAP-004** orbRangeTicks Fix: DailyBarContext.OrbRangeTicks field; computed from actual ORB high/low / TickSize; passed to Factor 7 (ORBvsATR). - **GAP-010** Short-Side Regime Filter: EnableShortTrendFilter param; vetoes shorts when AVWAP slope > 0 (bullish); configurable, default true. ### Calendar & Trailing (2 tasks) - **GAP-008** CME Holiday Awareness: NEW CmeHolidayCalendar.cs with 9 observed holidays + Good Friday (Easter calc); EnableCMEHolidayGuard skips ORB window on holidays. - **GAP-009** ATR Trailing Real ATR: EnableATRTrailing, ATRTrailingPeriod (14), ATRTrailingMultiplier (2.0), ATRTrailingMinTicks (8), ATRTrailingMaxTicks (60); computes trailTicks from ATR(Close,Period)[0]. ## Governance - SPRINT_BOARD.md, current_status.md, decisions.md (DEC-20260711-01 through -09), NEXT_PROMPT.md updated - All 9 tasks moved ACTIVE -> COMPLETED; GAP-011 (Gitea CI) now ACTIVE ## Verification - verify-build.bat: 0 errors, 0 warnings - Tests: 492 passing (404 core + 78 integration + 10 performance) ## Files - Modified: 13 source, 3 test, 9 governance - Deleted: 28 obsolete spec/docs - Added: 1 new module (NT8.Core.Calendar), governance files - Dual-deployed to NT8 Custom\Strategies\ ## Rollback Tag: sprint3-production-hardening-complete To revert: git reset --hard sprint3-production-hardening-complete
This commit is contained in:
178
docs/archive/completed-tasks/TASK_01_WIRE_NT8_EXECUTION.md
Normal file
178
docs/archive/completed-tasks/TASK_01_WIRE_NT8_EXECUTION.md
Normal file
@@ -0,0 +1,178 @@
|
||||
# Task 1 — Wire NT8OrderAdapter.ExecuteInNT8()
|
||||
|
||||
**Priority:** CRITICAL
|
||||
**Estimated time:** 3–4 hours
|
||||
**Blocks:** All backtest and live trading
|
||||
**Status:** TODO
|
||||
|
||||
---
|
||||
|
||||
## Problem
|
||||
|
||||
`NT8OrderAdapter.ExecuteInNT8()` in `src/NT8.Adapters/NinjaTrader/NT8OrderAdapter.cs` is a stub.
|
||||
It only logs to an internal list. The actual NT8 calls (`EnterLong`, `EnterShort`, `SetStopLoss`, `SetProfitTarget`) are in a commented-out block and never execute. This is why backtests show zero trades.
|
||||
|
||||
---
|
||||
|
||||
## What Needs to Change
|
||||
|
||||
### File: `src/NT8.Adapters/NinjaTrader/NT8OrderAdapter.cs`
|
||||
|
||||
The adapter currently has no reference to the actual NinjaScript `Strategy` object. It needs a way to call NT8 managed order methods. The pattern used by `NT8StrategyBase` is the right model to follow.
|
||||
|
||||
**Option A (Recommended):** Inject a callback delegate so the adapter can call NT8 methods without directly holding a NinjaScript reference.
|
||||
|
||||
Add a new `INT8ExecutionBridge` interface:
|
||||
```csharp
|
||||
// new file: src/NT8.Adapters/NinjaTrader/INT8ExecutionBridge.cs
|
||||
namespace NT8.Adapters.NinjaTrader
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides NT8OrderAdapter access to NinjaScript execution methods.
|
||||
/// Implemented by NT8StrategyBase.
|
||||
/// </summary>
|
||||
public interface INT8ExecutionBridge
|
||||
{
|
||||
/// <summary>Submit a long entry with stop and target.</summary>
|
||||
void EnterLongManaged(int quantity, string signalName, int stopTicks, int targetTicks, double tickSize);
|
||||
|
||||
/// <summary>Submit a short entry with stop and target.</summary>
|
||||
void EnterShortManaged(int quantity, string signalName, int stopTicks, int targetTicks, double tickSize);
|
||||
|
||||
/// <summary>Exit all long positions.</summary>
|
||||
void ExitLongManaged(string signalName);
|
||||
|
||||
/// <summary>Exit all short positions.</summary>
|
||||
void ExitShortManaged(string signalName);
|
||||
|
||||
/// <summary>Flatten the full position immediately.</summary>
|
||||
void FlattenAll();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Update `NT8OrderAdapter` constructor to accept `INT8ExecutionBridge`:
|
||||
```csharp
|
||||
public NT8OrderAdapter(INT8ExecutionBridge bridge)
|
||||
{
|
||||
if (bridge == null)
|
||||
throw new ArgumentNullException("bridge");
|
||||
_bridge = bridge;
|
||||
_executionHistory = new List<NT8OrderExecutionRecord>();
|
||||
}
|
||||
```
|
||||
|
||||
Implement `ExecuteInNT8()`:
|
||||
```csharp
|
||||
private void ExecuteInNT8(StrategyIntent intent, SizingResult sizing)
|
||||
{
|
||||
if (intent == null)
|
||||
throw new ArgumentNullException("intent");
|
||||
if (sizing == null)
|
||||
throw new ArgumentNullException("sizing");
|
||||
|
||||
var signalName = string.Format("SDK_{0}_{1}", intent.Symbol, intent.Side);
|
||||
|
||||
if (intent.Side == Common.Models.OrderSide.Buy)
|
||||
{
|
||||
_bridge.EnterLongManaged(
|
||||
sizing.Contracts,
|
||||
signalName,
|
||||
intent.StopTicks,
|
||||
intent.TargetTicks.HasValue ? intent.TargetTicks.Value : 0,
|
||||
intent.TickSize);
|
||||
}
|
||||
else if (intent.Side == Common.Models.OrderSide.Sell)
|
||||
{
|
||||
_bridge.EnterShortManaged(
|
||||
sizing.Contracts,
|
||||
signalName,
|
||||
intent.StopTicks,
|
||||
intent.TargetTicks.HasValue ? intent.TargetTicks.Value : 0,
|
||||
intent.TickSize);
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_executionHistory.Add(new NT8OrderExecutionRecord(
|
||||
intent.Symbol,
|
||||
intent.Side,
|
||||
intent.EntryType,
|
||||
sizing.Contracts,
|
||||
intent.StopTicks,
|
||||
intent.TargetTicks,
|
||||
DateTime.UtcNow));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### File: `src/NT8.Adapters/Strategies/NT8StrategyBase.cs`
|
||||
|
||||
Implement `INT8ExecutionBridge` on `NT8StrategyBase`:
|
||||
```csharp
|
||||
public class NT8StrategyBase : Strategy, INT8ExecutionBridge
|
||||
{
|
||||
public void EnterLongManaged(int quantity, string signalName, int stopTicks, int targetTicks, double tickSize)
|
||||
{
|
||||
SetStopLoss(signalName, CalculationMode.Ticks, stopTicks, false);
|
||||
if (targetTicks > 0)
|
||||
SetProfitTarget(signalName, CalculationMode.Ticks, targetTicks);
|
||||
EnterLong(quantity, signalName);
|
||||
}
|
||||
|
||||
public void EnterShortManaged(int quantity, string signalName, int stopTicks, int targetTicks, double tickSize)
|
||||
{
|
||||
SetStopLoss(signalName, CalculationMode.Ticks, stopTicks, false);
|
||||
if (targetTicks > 0)
|
||||
SetProfitTarget(signalName, CalculationMode.Ticks, targetTicks);
|
||||
EnterShort(quantity, signalName);
|
||||
}
|
||||
|
||||
public void ExitLongManaged(string signalName)
|
||||
{
|
||||
ExitLong(signalName);
|
||||
}
|
||||
|
||||
public void ExitShortManaged(string signalName)
|
||||
{
|
||||
ExitShort(signalName);
|
||||
}
|
||||
|
||||
// FlattenAll already called in NT8 as: this.Account.Flatten(Instrument)
|
||||
// or: ExitLong(); ExitShort();
|
||||
public void FlattenAll()
|
||||
{
|
||||
ExitLong("EmergencyFlatten");
|
||||
ExitShort("EmergencyFlatten");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] `NT8OrderAdapter` takes `INT8ExecutionBridge` in its constructor
|
||||
- [ ] `ExecuteInNT8()` calls the bridge (no more commented-out code)
|
||||
- [ ] `NT8StrategyBase` implements `INT8ExecutionBridge`
|
||||
- [ ] `OnOrderUpdate()` callback in `NT8OrderAdapter` updates `BasicOrderManager` state (pass the fill back)
|
||||
- [ ] `verify-build.bat` passes
|
||||
- [ ] A backtest run on SimpleORBNT8 produces actual trades (not zero)
|
||||
|
||||
---
|
||||
|
||||
## Files to Create/Modify
|
||||
|
||||
| File | Action |
|
||||
|---|---|
|
||||
| `src/NT8.Adapters/NinjaTrader/INT8ExecutionBridge.cs` | CREATE |
|
||||
| `src/NT8.Adapters/NinjaTrader/NT8OrderAdapter.cs` | MODIFY — implement `ExecuteInNT8()`, update constructor |
|
||||
| `src/NT8.Adapters/Strategies/NT8StrategyBase.cs` | MODIFY — implement `INT8ExecutionBridge` |
|
||||
|
||||
---
|
||||
|
||||
## Do NOT Change
|
||||
|
||||
- `src/NT8.Core/OMS/BasicOrderManager.cs` — the OMS is correct
|
||||
- `src/NT8.Strategies/Examples/SimpleORBStrategy.cs` — strategy logic is correct
|
||||
- Any existing test files
|
||||
Reference in New Issue
Block a user