92 lines
2.9 KiB
C#
92 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Newtonsoft.Json.Linq;
|
|
using NT8.Core.Common.Models;
|
|
using NT8.Core.Intelligence;
|
|
using NT8.Core.Logging;
|
|
|
|
namespace NT8.Core.Tests.Logging
|
|
{
|
|
[TestClass]
|
|
public class TradeProvenanceSerializerTests
|
|
{
|
|
[TestMethod]
|
|
public void Serialize_SubmittedIntent_WritesComputedProvenanceValues()
|
|
{
|
|
var confluence = new ConfluenceScore(
|
|
0.81,
|
|
0.83,
|
|
TradeGrade.A,
|
|
new List<ConfluenceFactor>(),
|
|
DateTime.UtcNow,
|
|
new Dictionary<string, object>());
|
|
var metadata = new Dictionary<string, object>();
|
|
metadata.Add("confluence_score", confluence);
|
|
metadata.Add("orb_range_ticks", 42.5);
|
|
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",
|
|
"PCP",
|
|
0.0,
|
|
"RTH_ORB",
|
|
"test-version");
|
|
JObject result = JObject.Parse(json);
|
|
|
|
Assert.AreEqual("A", (string)result["confluence_grade"]);
|
|
Assert.AreEqual(0.83, (double)result["confluence_score"], 0.000001);
|
|
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"]);
|
|
}
|
|
}
|
|
}
|