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:
101
TASK-01-kill-switch.md
Normal file
101
TASK-01-kill-switch.md
Normal file
@@ -0,0 +1,101 @@
|
||||
# TASK-01: Add Kill Switch + Verbose Logging Toggle
|
||||
|
||||
**File:** `src/NT8.Adapters/Strategies/NT8StrategyBase.cs`
|
||||
**Priority:** CRITICAL
|
||||
**Estimated time:** 45 min
|
||||
**No dependencies**
|
||||
|
||||
---
|
||||
|
||||
## Exact Changes Required
|
||||
|
||||
### 1. Add two new NinjaScript properties to the `#region User-Configurable Properties` block
|
||||
|
||||
Add these after the existing `MaxContracts` property:
|
||||
|
||||
```csharp
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Kill Switch (Flatten + Stop)", GroupName = "Emergency Controls", Order = 1)]
|
||||
public bool EnableKillSwitch { get; set; }
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Verbose Logging", GroupName = "Debug", Order = 1)]
|
||||
public bool EnableVerboseLogging { get; set; }
|
||||
```
|
||||
|
||||
### 2. Add a private field near the other private fields at the top of the class
|
||||
|
||||
```csharp
|
||||
private bool _killSwitchTriggered;
|
||||
```
|
||||
|
||||
### 3. Set defaults in `OnStateChange` → `State.SetDefaults` block, after the existing defaults
|
||||
|
||||
```csharp
|
||||
EnableKillSwitch = false;
|
||||
EnableVerboseLogging = false;
|
||||
_killSwitchTriggered = false;
|
||||
```
|
||||
|
||||
### 4. Add kill switch check at the TOP of `OnBarUpdate()`, before EVERYTHING else
|
||||
|
||||
The very first lines of `OnBarUpdate()` must become:
|
||||
|
||||
```csharp
|
||||
protected override void OnBarUpdate()
|
||||
{
|
||||
// Kill switch check — must be first
|
||||
if (EnableKillSwitch)
|
||||
{
|
||||
if (!_killSwitchTriggered)
|
||||
{
|
||||
_killSwitchTriggered = true;
|
||||
Print(string.Format("[SDK] KILL SWITCH ACTIVATED at {0} — flattening all positions.", Time[0]));
|
||||
try
|
||||
{
|
||||
ExitLong("KillSwitch");
|
||||
ExitShort("KillSwitch");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Print(string.Format("[SDK] Kill switch flatten error: {0}", ex.Message));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Existing guards follow unchanged
|
||||
if (!_sdkInitialized || _sdkStrategy == null)
|
||||
{ ... }
|
||||
...
|
||||
```
|
||||
|
||||
### 5. Add verbose logging to `ProcessStrategyIntent()` — wrap existing Print calls
|
||||
|
||||
Replace the existing bare `Print(...)` calls in `ProcessStrategyIntent()` with guarded versions:
|
||||
|
||||
```csharp
|
||||
// Change every Print(...) inside ProcessStrategyIntent() to:
|
||||
if (EnableVerboseLogging)
|
||||
Print(string.Format("...existing message..."));
|
||||
```
|
||||
|
||||
The `Print` call that shows the intent being generated in `OnBarUpdate` (not in `ProcessStrategyIntent`) should remain unguarded — that one is important.
|
||||
|
||||
---
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] `EnableKillSwitch` visible in NT8 strategy parameter dialog under "Emergency Controls"
|
||||
- [ ] `EnableVerboseLogging` visible under "Debug"
|
||||
- [ ] Setting `EnableKillSwitch = true` mid-run causes `ExitLong("KillSwitch")` and `ExitShort("KillSwitch")` on next bar
|
||||
- [ ] After kill switch triggers, every subsequent bar returns immediately (no strategy logic runs)
|
||||
- [ ] `verify-build.bat` passes with zero errors
|
||||
|
||||
---
|
||||
|
||||
## Do NOT Change
|
||||
|
||||
- Constructor or `InitializeSdkComponents()`
|
||||
- `SubmitOrderToNT8()`
|
||||
- Any OMS, Risk, Sizing, or Strategy logic
|
||||
Reference in New Issue
Block a user