Files
nt8-sdk/TASK-01-kill-switch.md
2026-02-24 15:00:41 -05:00

102 lines
2.9 KiB
Markdown

# 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