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:
192
docs/archive/ai-setup/AI_DEVELOPMENT_GUIDELINES.md
Normal file
192
docs/archive/ai-setup/AI_DEVELOPMENT_GUIDELINES.md
Normal file
@@ -0,0 +1,192 @@
|
||||
# NT8 SDK - AI Development Guidelines
|
||||
|
||||
## 🚨 CRITICAL: .NET Framework 4.8 Compatibility Requirements
|
||||
|
||||
This project MUST maintain compatibility with NinjaTrader 8, which requires:
|
||||
- **.NET Framework 4.8** (NOT .NET Core/.NET 5+)
|
||||
- **C# 5.0 language features only**
|
||||
- **Traditional class syntax** (NO records, nullable references, etc.)
|
||||
|
||||
## Language Restrictions (C# 5.0 Only)
|
||||
|
||||
### ❌ FORBIDDEN FEATURES
|
||||
- `record` types → Use `class` with constructors
|
||||
- Nullable reference types (`string?`) → Use `string`
|
||||
- String interpolation (`$"Hello {name}"`) → Use `String.Format("Hello {0}", name)`
|
||||
- Dictionary initializers (`new Dictionary<string, object> { ["key"] = value }`) → Use `dict.Add("key", value)`
|
||||
- Pattern matching → Use `switch` statements or `if/else`
|
||||
- Auto-property initializers → Initialize in constructor
|
||||
- Expression-bodied members → Use full method bodies
|
||||
- `nameof` operator → Use string literals
|
||||
- Exception filters → Use try/catch blocks
|
||||
- Async Main → Use traditional Main methods
|
||||
|
||||
### ✅ ALLOWED FEATURES
|
||||
- Traditional classes with properties and methods
|
||||
- Constructors with parameters
|
||||
- Standard interfaces and inheritance
|
||||
- LINQ (System.Linq)
|
||||
- Generics
|
||||
- Extension methods
|
||||
- Lambda expressions
|
||||
- Anonymous types
|
||||
- var keyword
|
||||
- Traditional async/await (with Task)
|
||||
|
||||
## Project Structure Rules
|
||||
|
||||
### Framework Targeting
|
||||
ALL projects must target `net48`:
|
||||
```xml
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<LangVersion>5.0</LangVersion>
|
||||
```
|
||||
|
||||
### Package Restrictions
|
||||
- **NO Microsoft.Extensions.*** packages (use custom implementations)
|
||||
- **NO System.Text.Json** (use Newtonsoft.Json)
|
||||
- **NO modern testing frameworks** (use MSTest for .NET Framework)
|
||||
|
||||
### Required Using Statements
|
||||
Always include these for basic functionality:
|
||||
```csharp
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks; // if async needed
|
||||
```
|
||||
|
||||
## Architecture Rules
|
||||
|
||||
### 1. Risk-First Design
|
||||
- ALL trading intents MUST pass through IRiskManager
|
||||
- Risk validation happens BEFORE position sizing
|
||||
- No strategy can bypass risk controls
|
||||
|
||||
### 2. Thin Strategy Pattern
|
||||
- Strategies implement ONLY signal generation
|
||||
- No direct market access from strategies
|
||||
- All execution goes through SDK framework
|
||||
|
||||
### 3. Deterministic Behavior
|
||||
- Same inputs MUST produce same outputs
|
||||
- No random number generation without seeds
|
||||
- All calculations must be reproducible
|
||||
|
||||
## Code Style Requirements
|
||||
|
||||
### Class Structure
|
||||
```csharp
|
||||
// ✅ Correct C# 5.0 class
|
||||
public class StrategyIntent
|
||||
{
|
||||
public string Symbol { get; set; }
|
||||
public OrderSide Side { get; set; }
|
||||
|
||||
public StrategyIntent(string symbol, OrderSide side)
|
||||
{
|
||||
Symbol = symbol;
|
||||
Side = side;
|
||||
}
|
||||
}
|
||||
|
||||
// ❌ FORBIDDEN - Record syntax
|
||||
public record StrategyIntent(string Symbol, OrderSide Side);
|
||||
```
|
||||
|
||||
### Dictionary Initialization
|
||||
```csharp
|
||||
// ✅ Correct C# 5.0 syntax
|
||||
var metrics = new Dictionary<string, object>();
|
||||
metrics.Add("trade_risk", riskAmount);
|
||||
metrics.Add("daily_pnl", dailyPnL);
|
||||
|
||||
// ❌ FORBIDDEN - Dictionary initializer
|
||||
var metrics = new Dictionary<string, object>
|
||||
{
|
||||
["trade_risk"] = riskAmount,
|
||||
["daily_pnl"] = dailyPnL
|
||||
};
|
||||
```
|
||||
|
||||
### String Formatting
|
||||
```csharp
|
||||
// ✅ Correct C# 5.0 syntax
|
||||
_logger.LogDebug("Order approved: {0} {1} risk=${2:F2}",
|
||||
intent.Symbol, intent.Side, tradeRisk);
|
||||
|
||||
// ❌ FORBIDDEN - String interpolation
|
||||
_logger.LogDebug($"Order approved: {intent.Symbol} {intent.Side} risk=${tradeRisk:F2}");
|
||||
```
|
||||
|
||||
## Testing Requirements
|
||||
|
||||
### Use MSTest Framework
|
||||
```csharp
|
||||
[TestClass]
|
||||
public class BasicRiskManagerTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ValidateOrder_ShouldPass()
|
||||
{
|
||||
// Test implementation
|
||||
Assert.IsTrue(result.Allow);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Test Coverage Requirements
|
||||
- Minimum 80% code coverage for core components
|
||||
- All risk scenarios must be tested
|
||||
- All position sizing calculations must be validated
|
||||
|
||||
## Build Verification
|
||||
|
||||
Before committing ANY code, run:
|
||||
```bash
|
||||
.\verify-build.bat
|
||||
```
|
||||
|
||||
This MUST pass with zero errors and warnings.
|
||||
|
||||
## Phase Development Rules
|
||||
|
||||
### Phase 1 Focus Areas (ONLY)
|
||||
- NT8 adapter implementations
|
||||
- Market data integration
|
||||
- Order execution system
|
||||
- Enhanced risk controls (Tier 2)
|
||||
|
||||
### DO NOT IMPLEMENT
|
||||
- Advanced features from later phases
|
||||
- Modern C# language features
|
||||
- Complex UI components
|
||||
- Performance optimizations (until Phase 3)
|
||||
|
||||
## Common Pitfalls to Avoid
|
||||
|
||||
1. **Using modern C# syntax** - Stick to C# 5.0 only
|
||||
2. **Adding .NET Core packages** - Use .NET Framework compatible only
|
||||
3. **Bypassing risk management** - All trades must go through IRiskManager
|
||||
4. **Complex inheritance hierarchies** - Keep design simple and testable
|
||||
5. **Hardcoding values** - Use configuration classes
|
||||
|
||||
## AI Agent Checklist
|
||||
|
||||
Before implementing ANY feature:
|
||||
- [ ] Does this maintain .NET Framework 4.8 compatibility?
|
||||
- [ ] Does this use only C# 5.0 language features?
|
||||
- [ ] Does this follow the risk-first architecture?
|
||||
- [ ] Does this include appropriate error handling?
|
||||
- [ ] Does this include unit tests?
|
||||
- [ ] Does this compile without warnings?
|
||||
|
||||
## Emergency Contacts
|
||||
|
||||
If agents encounter compatibility issues:
|
||||
1. Check this document first
|
||||
2. Review existing working code patterns
|
||||
3. Test with `.\verify-build.bat`
|
||||
4. Flag for human review if unsure
|
||||
|
||||
Remember: **Compatibility with NT8 is non-negotiable.** When in doubt, use simpler, more traditional code patterns.
|
||||
Reference in New Issue
Block a user