Files
nt8-sdk/tests/NT8.Core.Tests/Adapters/SimpleORBNT8DefaultsTests.cs
mo 7e82b2ce5a [GAP-059]: ORB range telemetry context complete
- SimpleORBNT8.cs: source telemetry ORB range from SDK opening range tracker

- SimpleORBNT8DefaultsTests.cs: guard against dead adapter ORB fields and verify SDK source

- OrbConfluenceFactorTests.cs: prove realistic ORB range ticks produce ratio reason

- SPRINT_BOARD.md and decisions.md: record implementation and deploy blocker

Build: clean | Tests: 545 passing; Core 456 passing | Dual-deployed: no - NinjaTrader.exe PID 18800 locked NT8.Core.dll
2026-08-25 10:10:27 -04:00

116 lines
6.5 KiB
C#

using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace NT8.Core.Tests.Adapters
{
[TestClass]
public class SimpleORBNT8DefaultsTests
{
[TestMethod]
public void SetDefaults_DirectionFlags_EnableLongAndShortTrades()
{
string source = File.ReadAllText(FindSourceFile());
string setDefaults = ExtractSetDefaultsBlock(source);
Assert.IsTrue(setDefaults.Contains("EnableLongTrades = true;"), "SetDefaults must enable long trades by default.");
Assert.IsTrue(setDefaults.Contains("EnableShortTrades = true;"), "SetDefaults must enable short trades by default per DEC-20260814-04.");
Assert.IsFalse(setDefaults.Contains("EnableShortTrades = false;"), "SetDefaults must not disable short trades by default.");
}
[TestMethod]
public void BuildStateTelemetryIntent_DailyContext_UsesDirectionCorrectClone()
{
string source = File.ReadAllText(FindSourceFile());
string method = ExtractMethodBlock(source, "protected override StrategyIntent BuildStateTelemetryIntent");
Assert.IsTrue(method.Contains("CloneDailyBarContextForTelemetry((DailyBarContext)dailySource, side, barData, context)"), "Telemetry must clone daily context and set clone-only fields.");
Assert.IsTrue(method.Contains("metadata.Add(\"daily_bars\", telemetryDaily);"), "Telemetry must attach the cloned daily context.");
Assert.IsTrue(method.Contains("metadata.Add(\"orb_range_ticks\", telemetryDaily.OrbRangeTicks);"), "Telemetry must expose ORB range metadata for OrbRangeVsAtr.");
Assert.IsFalse(method.Contains("metadata.Add(\"daily_bars\", _strategyConfig.Parameters[\"daily_bars\"]);"), "Telemetry must not attach the shared daily context directly.");
}
[TestMethod]
public void CloneDailyBarContextForTelemetry_UsesTelemetrySideAndSessionOpen()
{
string source = File.ReadAllText(FindSourceFile());
string method = ExtractMethodBlock(source, "private static DailyBarContext CloneDailyBarContextForTelemetry");
Assert.IsTrue(method.Contains("daily.TradeDirection = side == OrderSide.Buy ? 1 : -1;"), "Telemetry clone must derive direction from the synthetic intent side.");
Assert.IsTrue(method.Contains("context.CustomData.ContainsKey(\"session_open_price\")"), "Telemetry clone must prefer session_open_price over current bar open.");
Assert.IsTrue(method.Contains("daily.TodayOpen = (double)sessionOpen;"), "Telemetry clone must apply the session open value.");
Assert.IsTrue(method.Contains("context.CustomData.ContainsKey(\"avg_volume\")"), "Telemetry clone must mirror trade-path avg_volume context.");
Assert.IsTrue(method.Contains("daily.BreakoutBarVolume = (double)barData.Volume;"), "Telemetry clone must use current bar volume for breakout-volume scoring.");
}
[TestMethod]
public void OnBarUpdate_DailyContextOrbRange_UsesSdkOpeningRangeTracker()
{
string source = File.ReadAllText(FindSourceFile());
string method = ExtractMethodBlock(source, "protected override void OnBarUpdate");
Assert.IsTrue(method.Contains("SdkSimpleORB sdkOrb = _sdkStrategy as SdkSimpleORB;"), "Daily context must read the live SDK-side ORB tracker.");
Assert.IsTrue(method.Contains("double orbHigh = (sdkOrb != null && sdkOrb.OpeningRangeReady) ? sdkOrb.OpeningRangeHigh : 0.0;"), "Daily context must use SDK ORB high only after the range is ready.");
Assert.IsTrue(method.Contains("double orbLow = (sdkOrb != null && sdkOrb.OpeningRangeReady) ? sdkOrb.OpeningRangeLow : 0.0;"), "Daily context must use SDK ORB low only after the range is ready.");
Assert.IsTrue(method.Contains("orbRangeTicks = Math.Round((orbHigh - orbLow) / tickSize);"), "Daily context must compute ORB range ticks from SDK high/low.");
Assert.IsFalse(source.Contains("_openingRangeHigh"), "Legacy adapter ORB high field must stay removed because the SDK tracker owns this state.");
Assert.IsFalse(source.Contains("_openingRangeLow"), "Legacy adapter ORB low field must stay removed because the SDK tracker owns this state.");
}
private static string FindSourceFile()
{
DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
while (dir != null)
{
string candidate = Path.Combine(dir.FullName, "src", "NT8.Adapters", "Strategies", "SimpleORBNT8.cs");
if (File.Exists(candidate))
return candidate;
dir = dir.Parent;
}
throw new FileNotFoundException("Could not locate src\\NT8.Adapters\\Strategies\\SimpleORBNT8.cs from test output directory.");
}
private static string ExtractSetDefaultsBlock(string source)
{
const string marker = "if (State == State.SetDefaults)";
int start = source.IndexOf(marker, StringComparison.Ordinal);
if (start < 0)
Assert.Fail("SimpleORBNT8.cs does not contain the SetDefaults state block.");
int end = source.IndexOf("else if (State == State.Configure)", start, StringComparison.Ordinal);
if (end < 0)
Assert.Fail("SimpleORBNT8.cs does not contain the Configure state block after SetDefaults.");
return source.Substring(start, end - start);
}
private static string ExtractMethodBlock(string source, string signature)
{
int start = source.IndexOf(signature, StringComparison.Ordinal);
if (start < 0)
Assert.Fail("SimpleORBNT8.cs does not contain method: " + signature);
int brace = source.IndexOf("{", start, StringComparison.Ordinal);
if (brace < 0)
Assert.Fail("SimpleORBNT8.cs method has no opening brace: " + signature);
int depth = 0;
for (int i = brace; i < source.Length; i++)
{
if (source[i] == '{')
depth++;
else if (source[i] == '}')
{
depth--;
if (depth == 0)
return source.Substring(start, i - start + 1);
}
}
Assert.Fail("SimpleORBNT8.cs method has no closing brace: " + signature);
return string.Empty;
}
}
}