Production hardening: kill switch, circuit breaker, trailing stops, log level, holiday calendar
Some checks failed
Build and Test / build (push) Has been cancelled
Some checks failed
Build and Test / build (push) Has been cancelled
This commit is contained in:
@@ -1,147 +1,52 @@
|
||||
# File Modification Boundaries - Phase 2
|
||||
# File Modification Boundaries — Production Hardening
|
||||
|
||||
You are implementing **Phase 2: Enhanced Risk & Sizing** for the NT8 SDK project.
|
||||
You are fixing specific gaps. These are the ONLY files you may touch.
|
||||
|
||||
## Allowed Modifications
|
||||
---
|
||||
|
||||
You MAY create and modify files in these directories ONLY:
|
||||
## ✅ Files You MAY Modify
|
||||
|
||||
### Phase 2 Implementation
|
||||
- `src/NT8.Core/Risk/**/*.cs` - All risk management files
|
||||
- `src/NT8.Core/Sizing/**/*.cs` - All sizing files
|
||||
- `src/NT8.Core/OMS/OrderStateMachine.cs` - NEW file only
|
||||
| File | What to Change |
|
||||
|---|---|
|
||||
| `src/NT8.Adapters/Strategies/NT8StrategyBase.cs` | Add `EnableKillSwitch`, `EnableVerboseLogging` NinjaScript params; add kill switch early-exit in `OnBarUpdate`; wire `ExecutionCircuitBreaker`; call `_circuitBreaker.RecordOrderRejection()` from `OnOrderUpdate` |
|
||||
| `src/NT8.Core/Execution/TrailingStopManager.cs` | Fix `CalculateNewStopPrice()` — replace placeholder math with real formulas for `FixedTrailing`, `ATRTrailing`, `Chandelier` |
|
||||
| `src/NT8.Core/Logging/BasicLogger.cs` | Add `LogLevel MinimumLevel` property; skip writes below minimum level |
|
||||
| `src/NT8.Core/MarketData/SessionManager.cs` | Add static CME holiday list; update `IsRegularTradingHours()` to return `false` on holidays |
|
||||
|
||||
### Limited Modifications (Add Only, Don't Change)
|
||||
- `src/NT8.Core/Risk/RiskConfig.cs` - ADD properties only (don't modify existing)
|
||||
- `src/NT8.Core/OMS/OrderModels.cs` - ADD records only (don't modify existing)
|
||||
- `src/NT8.Core/OMS/BasicOrderManager.cs` - ADD methods only (don't modify existing)
|
||||
---
|
||||
|
||||
### Testing
|
||||
- `tests/NT8.Core.Tests/Risk/**/*.cs` - Risk tests
|
||||
- `tests/NT8.Core.Tests/Sizing/**/*.cs` - Sizing tests
|
||||
- `tests/NT8.Core.Tests/OMS/EnhancedOMSTests.cs` - NEW file
|
||||
- `tests/NT8.Integration.Tests/RiskSizingIntegrationTests.cs` - NEW file
|
||||
- `tests/NT8.Performance.Tests/Phase2PerformanceTests.cs` - NEW file
|
||||
## ✅ Files You MAY Create (New)
|
||||
|
||||
## Strictly Forbidden Modifications
|
||||
| File | Purpose |
|
||||
|---|---|
|
||||
| `tests/NT8.Core.Tests/Execution/TrailingStopManagerFixedTests.cs` | Unit tests for fixed trailing stop calculations |
|
||||
|
||||
You MUST NOT modify:
|
||||
---
|
||||
|
||||
### Interfaces (Breaking Changes)
|
||||
- `src/NT8.Core/Common/Interfaces/IStrategy.cs`
|
||||
- `src/NT8.Core/Risk/IRiskManager.cs` - Interface itself
|
||||
- `src/NT8.Core/Sizing/IPositionSizer.cs` - Interface itself
|
||||
- `src/NT8.Core/OMS/IOrderManager.cs` - Interface itself
|
||||
- `src/NT8.Core/OMS/INT8OrderAdapter.cs` - Interface itself
|
||||
## ❌ Files You Must NOT Touch
|
||||
|
||||
### Phase 1 Implementations
|
||||
- `src/NT8.Core/Risk/BasicRiskManager.cs` - Keep as-is
|
||||
- `src/NT8.Core/Sizing/BasicPositionSizer.cs` - Keep as-is
|
||||
- `src/NT8.Core/OMS/BasicOrderManager.cs` - ADD only, don't modify existing methods
|
||||
| File / Directory | Reason |
|
||||
|---|---|
|
||||
| `src/NT8.Adapters/NinjaTrader/NT8OrderAdapter.cs` | The stub does NOT block execution — `NT8StrategyBase.SubmitOrderToNT8()` is what submits orders. Leave the adapter alone. |
|
||||
| `src/NT8.Adapters/Strategies/SimpleORBNT8.cs` | Strategy wrapper is correct |
|
||||
| `src/NT8.Strategies/Examples/SimpleORBStrategy.cs` | Strategy logic is correct |
|
||||
| `src/NT8.Core/OMS/**` | Complete and tested |
|
||||
| `src/NT8.Core/Risk/**` | Complete and tested |
|
||||
| `src/NT8.Core/Sizing/**` | Complete and tested |
|
||||
| `src/NT8.Core/Intelligence/**` | Complete and tested |
|
||||
| `src/NT8.Core/Analytics/**` | Complete and tested |
|
||||
| `src/NT8.Core/Execution/ExecutionCircuitBreaker.cs` | Already correct — only instantiate and use it, don't modify |
|
||||
| `src/NT8.Core/Common/**` | Interfaces and models — never touch |
|
||||
| `Directory.Build.props` | Never touch |
|
||||
| `*.csproj` | Never touch |
|
||||
| Any existing passing test file | Do not break passing tests |
|
||||
|
||||
### Common Models
|
||||
- `src/NT8.Core/Common/Models/**` - Don't modify existing models
|
||||
---
|
||||
|
||||
### Build Configuration
|
||||
- `Directory.Build.props`
|
||||
- `*.csproj` files (unless adding new files)
|
||||
- `.gitignore`
|
||||
## Quick Self-Check
|
||||
|
||||
### Documentation (Read-Only)
|
||||
- `nt8_phasing_plan.md`
|
||||
- `nt8_dev_spec.md`
|
||||
- Phase 1 guides
|
||||
|
||||
## New File Creation Rules
|
||||
|
||||
### When creating new files:
|
||||
1. Use proper namespace:
|
||||
- `NT8.Core.Risk` for risk files
|
||||
- `NT8.Core.Sizing` for sizing files
|
||||
- `NT8.Core.OMS` for OMS files
|
||||
- `NT8.Core.Tests.Risk` for risk tests
|
||||
- `NT8.Core.Tests.Sizing` for sizing tests
|
||||
|
||||
2. Include XML documentation on all public members
|
||||
3. Follow existing file naming patterns (PascalCase)
|
||||
4. Add to appropriate project file if needed
|
||||
|
||||
### File naming examples:
|
||||
✅ `AdvancedRiskManager.cs` - Implementation class
|
||||
✅ `AdvancedRiskModels.cs` - Model classes
|
||||
✅ `OptimalFCalculator.cs` - Calculator utility
|
||||
✅ `EnhancedPositionSizer.cs` - Sizer implementation
|
||||
✅ `AdvancedRiskManagerTests.cs` - Test class
|
||||
|
||||
## Modification Patterns
|
||||
|
||||
### ✅ CORRECT: Adding to existing file
|
||||
```csharp
|
||||
// In RiskConfig.cs - ADD new properties
|
||||
public record RiskConfig(
|
||||
// Phase 1 properties - DON'T TOUCH
|
||||
double DailyLossLimit,
|
||||
double MaxTradeRisk,
|
||||
int MaxOpenPositions,
|
||||
bool EmergencyFlattenEnabled,
|
||||
|
||||
// Phase 2 properties - ADD THESE
|
||||
double? WeeklyLossLimit = null,
|
||||
double? TrailingDrawdownLimit = null,
|
||||
int? MaxCrossStrategyExposure = null
|
||||
);
|
||||
```
|
||||
|
||||
### ❌ WRONG: Modifying existing
|
||||
```csharp
|
||||
// DON'T change existing property types or remove them
|
||||
public record RiskConfig(
|
||||
int DailyLossLimit, // ❌ Changed type from double
|
||||
// ❌ Removed MaxTradeRisk property
|
||||
);
|
||||
```
|
||||
|
||||
### ✅ CORRECT: Adding methods to BasicOrderManager
|
||||
```csharp
|
||||
public class BasicOrderManager : IOrderManager
|
||||
{
|
||||
// Existing methods - DON'T TOUCH
|
||||
public async Task<string> SubmitOrderAsync(...) { }
|
||||
|
||||
// NEW Phase 2 methods - ADD THESE
|
||||
public async Task<bool> HandlePartialFillAsync(...) { }
|
||||
public async Task<bool> RetryOrderAsync(...) { }
|
||||
}
|
||||
```
|
||||
|
||||
## Verification
|
||||
|
||||
Before any file operation, ask yourself:
|
||||
1. Is this file in an allowed directory?
|
||||
2. Am I modifying an existing interface signature? (FORBIDDEN)
|
||||
3. Am I changing existing Phase 1 behavior? (FORBIDDEN)
|
||||
4. Am I only ADDING to existing files? (ALLOWED)
|
||||
|
||||
If unsure, DO NOT proceed - ask for clarification first.
|
||||
|
||||
## Phase 2 Specific Rules
|
||||
|
||||
### Risk Files
|
||||
- ✅ Create AdvancedRiskManager.cs (NEW)
|
||||
- ✅ Create AdvancedRiskModels.cs (NEW)
|
||||
- ✅ Extend RiskConfig.cs (ADD ONLY)
|
||||
|
||||
### Sizing Files
|
||||
- ✅ Create OptimalFCalculator.cs (NEW)
|
||||
- ✅ Create VolatilityAdjustedSizer.cs (NEW)
|
||||
- ✅ Create EnhancedPositionSizer.cs (NEW)
|
||||
- ✅ Create SizingModels.cs (NEW)
|
||||
|
||||
### OMS Files
|
||||
- ✅ Create OrderStateMachine.cs (NEW)
|
||||
- ✅ Extend OrderModels.cs (ADD ONLY)
|
||||
- ✅ Extend BasicOrderManager.cs (ADD METHODS ONLY)
|
||||
|
||||
### Test Files
|
||||
- ✅ Create all new test files
|
||||
- ✅ Don't modify existing test files unless fixing bugs
|
||||
Before editing any file, ask:
|
||||
1. Is this file in the allowed list above?
|
||||
2. Am I changing an interface? → STOP
|
||||
3. Am I modifying existing Risk/Sizing/OMS/Intelligence/Analytics code? → STOP
|
||||
4. Am I breaking a passing test? → STOP
|
||||
|
||||
Reference in New Issue
Block a user