Files
nt8-sdk/docs/archive/completed-tasks/TASK-05-session-holidays.md
mo c9041df36a 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
2026-07-13 08:38:25 -04:00

3.5 KiB

TASK-05: Add CME Holiday Awareness to SessionManager

File: src/NT8.Core/MarketData/SessionManager.cs Priority: MEDIUM No dependencies Estimated time: 30 min


Background

IsRegularTradingHours() currently only checks session time windows. It has no awareness of CME holidays, so the system would attempt to trade on Christmas, Thanksgiving, etc. when markets are closed.


Exact Changes Required

1. Add a static holiday set as a private field on SessionManager

Add this inside the class (near the other private fields):

// CME US Futures holidays — markets closed all day on these dates.
// Update annually. Dates are in the format new DateTime(year, month, day).
private static readonly System.Collections.Generic.HashSet<DateTime> _cmeHolidays =
    new System.Collections.Generic.HashSet<DateTime>
    {
        // 2025 holidays
        new DateTime(2025, 1, 1),   // New Year's Day
        new DateTime(2025, 1, 20),  // Martin Luther King Jr. Day
        new DateTime(2025, 2, 17),  // Presidents' Day
        new DateTime(2025, 4, 18),  // Good Friday
        new DateTime(2025, 5, 26),  // Memorial Day
        new DateTime(2025, 6, 19),  // Juneteenth
        new DateTime(2025, 7, 4),   // Independence Day
        new DateTime(2025, 9, 1),   // Labor Day
        new DateTime(2025, 11, 27), // Thanksgiving
        new DateTime(2025, 12, 25), // Christmas Day

        // 2026 holidays
        new DateTime(2026, 1, 1),   // New Year's Day
        new DateTime(2026, 1, 19),  // Martin Luther King Jr. Day
        new DateTime(2026, 2, 16),  // Presidents' Day
        new DateTime(2026, 4, 3),   // Good Friday
        new DateTime(2026, 5, 25),  // Memorial Day
        new DateTime(2026, 6, 19),  // Juneteenth
        new DateTime(2026, 7, 4),   // Independence Day (observed Mon 7/3 if falls on Sat — keep both just in case)
        new DateTime(2026, 9, 7),   // Labor Day
        new DateTime(2026, 11, 26), // Thanksgiving
        new DateTime(2026, 12, 25), // Christmas Day
    };

2. Add a helper method

/// <summary>
/// Returns true if the given UTC date is a CME holiday (market closed all day).
/// </summary>
private static bool IsCmeHoliday(DateTime utcTime)
{
    // Convert to ET for holiday date comparison
    try
    {
        var estTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime,
            TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
        return _cmeHolidays.Contains(estTime.Date);
    }
    catch (Exception)
    {
        return false;
    }
}

3. Update IsRegularTradingHours() to check holidays first

The existing method body is:

var sessionInfo = GetCurrentSession(symbol, time);
return sessionInfo.IsRegularHours;

Replace with:

// Markets are fully closed on CME holidays
if (IsCmeHoliday(time))
{
    _logger.LogInformation("Holiday detected for {0} on {1} — market closed.", symbol, time.Date);
    return false;
}

var sessionInfo = GetCurrentSession(symbol, time);
return sessionInfo.IsRegularHours;

Acceptance Criteria

  • IsRegularTradingHours("ES", new DateTime(2025, 12, 25, 14, 0, 0, DateTimeKind.Utc)) returns false
  • IsRegularTradingHours("ES", new DateTime(2025, 12, 26, 14, 0, 0, DateTimeKind.Utc)) returns true (normal day)
  • IsRegularTradingHours("ES", new DateTime(2025, 11, 27, 14, 0, 0, DateTimeKind.Utc)) returns false (Thanksgiving)
  • verify-build.bat passes
  • All existing tests pass