test: cover GAP-035 GAP-036 and DEC-20260814-04 regressions
This commit is contained in:
49
tests/NT8.Core.Tests/Adapters/SimpleORBNT8DefaultsTests.cs
Normal file
49
tests/NT8.Core.Tests/Adapters/SimpleORBNT8DefaultsTests.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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.");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,5 +54,38 @@ namespace NT8.Core.Tests.Logging
|
||||
Assert.AreEqual("Mode1DualLeg", (string)result["resolved_runner_mode"]);
|
||||
Assert.AreEqual(42.5, (double)result["OrbRangeTicks"], 0.000001);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Serialize_IntentMetadataRiskMode_WritesResolvedRiskMode()
|
||||
{
|
||||
var metadata = new Dictionary<string, object>();
|
||||
metadata.Add("risk_mode", "PCP");
|
||||
var intent = new StrategyIntent(
|
||||
"NQ",
|
||||
OrderSide.Buy,
|
||||
OrderType.Market,
|
||||
null,
|
||||
20,
|
||||
40,
|
||||
0.83,
|
||||
"synthetic trade",
|
||||
metadata);
|
||||
|
||||
string json = TradeProvenanceSerializer.Serialize(
|
||||
"session-1",
|
||||
1,
|
||||
new DateTime(2026, 8, 3, 12, 0, 0, DateTimeKind.Utc),
|
||||
intent,
|
||||
2,
|
||||
20.0,
|
||||
"Mode1DualLeg",
|
||||
metadata["risk_mode"].ToString(),
|
||||
0.0,
|
||||
"RTH_ORB",
|
||||
"test-version");
|
||||
JObject result = JObject.Parse(json);
|
||||
|
||||
Assert.AreEqual("PCP", (string)result["risk_mode"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using NT8.Core.Common.Models;
|
||||
using NT8.Core.Intelligence;
|
||||
using NT8.Core.Logging;
|
||||
using NT8.Strategies.Examples;
|
||||
|
||||
namespace NT8.Core.Tests.Strategies
|
||||
{
|
||||
[TestClass]
|
||||
public class SimpleORBRejectionLoggingTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void OnBar_BelowThresholdGrade_RecordsGradeFilterRejectLineWithScore()
|
||||
{
|
||||
SimpleORBStrategy strategy = new SimpleORBStrategy(30, 1.0);
|
||||
StrategyConfig config = new StrategyConfig(
|
||||
"SimpleORB",
|
||||
"NQ",
|
||||
new Dictionary<string, object>(),
|
||||
new RiskConfig(1000.0, 200.0, 2, false),
|
||||
new SizingConfig(SizingMethod.FixedDollarRisk, 1, 3, 100.0, null));
|
||||
config.Parameters.Add("TestMode", true);
|
||||
config.Parameters.Add("MaxDailyTrades", 1);
|
||||
config.Parameters.Add("StopTicks", 8);
|
||||
config.Parameters.Add("TargetTicks", 16);
|
||||
config.Parameters.Add("MinTradeGrade", (int)TradeGrade.APlus);
|
||||
strategy.Initialize(config, null, new BasicLogger("SimpleORBRejectionLoggingTests"));
|
||||
|
||||
DateTime sessionStart = DateTime.Today.AddHours(9.5);
|
||||
MarketSession session = new MarketSession(sessionStart, sessionStart.Date.AddHours(16), true, "RTH");
|
||||
StrategyContext context = new StrategyContext(
|
||||
"NQ",
|
||||
sessionStart.AddMinutes(5),
|
||||
null,
|
||||
new AccountInfo(100000, 100000, 0, 0, DateTime.UtcNow),
|
||||
session,
|
||||
new Dictionary<string, object>());
|
||||
BarData bar = new BarData("NQ", sessionStart.AddMinutes(5), 19000, 19060, 18990, 19065, 1500, TimeSpan.FromMinutes(5));
|
||||
|
||||
StrategyIntent intent = strategy.OnBar(bar, context);
|
||||
|
||||
Assert.IsNull(intent);
|
||||
Assert.IsTrue(context.CustomData.ContainsKey("signal_reject_line"));
|
||||
string line = context.CustomData["signal_reject_line"].ToString();
|
||||
Assert.IsTrue(line.Contains("REJECT: reason=GradeFilter"), line);
|
||||
Assert.IsTrue(line.Contains("Score="), line);
|
||||
Assert.IsTrue(line.Contains("Grade="), line);
|
||||
Assert.IsTrue(line.Contains("MinTradeGrade="), line);
|
||||
Assert.IsTrue(line.Contains("Factors="), line);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user