2.9 KiB
2.9 KiB
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:
[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
private bool _killSwitchTriggered;
3. Set defaults in OnStateChange → State.SetDefaults block, after the existing defaults
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:
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:
// 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
EnableKillSwitchvisible in NT8 strategy parameter dialog under "Emergency Controls"EnableVerboseLoggingvisible under "Debug"- Setting
EnableKillSwitch = truemid-run causesExitLong("KillSwitch")andExitShort("KillSwitch")on next bar - After kill switch triggers, every subsequent bar returns immediately (no strategy logic runs)
verify-build.batpasses with zero errors
Do NOT Change
- Constructor or
InitializeSdkComponents() SubmitOrderToNT8()- Any OMS, Risk, Sizing, or Strategy logic