GAP-031: fix submitted trade provenance

- serialize grade, score, ORB ticks, and resolved mode from accepted submission data
- add exact-value JSONL provenance test
- prepare governance for Gate Run 3

Build: clean | Tests: 498 passing | Dual-deployed: yes
This commit is contained in:
2026-08-03 08:50:04 -04:00
parent 56d7c7880e
commit 5844b2ce0b
9 changed files with 215 additions and 78 deletions

View File

@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using NT8.Core.Common.Models;
using NT8.Core.Intelligence;
namespace NT8.Core.Logging
{
/// <summary>
/// Serializes submitted trade provenance from the accepted strategy intent.
/// </summary>
public static class TradeProvenanceSerializer
{
/// <summary>
/// Creates one JSONL payload for a submitted trade.
/// </summary>
public static string Serialize(
string sessionId,
int tradeSequence,
DateTime timestampUtc,
StrategyIntent intent,
int quantity,
double atrStopTicks,
string resolvedRunnerMode,
string riskMode,
double dailyPnlAtEntry,
string sessionTag,
string codeVersion)
{
if (intent == null)
throw new ArgumentNullException("intent");
string grade = "Unknown";
double score = 0.0;
double orbRangeTicks = 0.0;
ConfluenceScore confluenceScore = null;
if (intent.Metadata != null)
{
if (intent.Metadata.ContainsKey("confluence_score"))
confluenceScore = intent.Metadata["confluence_score"] as ConfluenceScore;
if (confluenceScore != null)
{
grade = confluenceScore.Grade.ToString();
score = confluenceScore.WeightedScore;
}
else
{
if (intent.Metadata.ContainsKey("trade_grade") && intent.Metadata["trade_grade"] != null)
grade = intent.Metadata["trade_grade"].ToString();
score = GetDouble(intent.Metadata, "confluence_weighted_score");
}
orbRangeTicks = GetDouble(intent.Metadata, "orb_range_ticks");
}
var trade = new Dictionary<string, object>();
trade.Add("session_id", sessionId);
trade.Add("trade_seq", tradeSequence);
trade.Add("timestamp_utc", timestampUtc.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"));
trade.Add("symbol", intent.Symbol);
trade.Add("side", intent.Side.ToString());
trade.Add("quantity", quantity);
trade.Add("stop_ticks", intent.StopTicks);
trade.Add("target_ticks", intent.TargetTicks);
trade.Add("atr_stop_ticks", atrStopTicks);
trade.Add("resolved_runner_mode", resolvedRunnerMode);
trade.Add("confluence_grade", grade);
trade.Add("confluence_score", score);
trade.Add("OrbRangeTicks", orbRangeTicks);
trade.Add("risk_mode", riskMode);
trade.Add("daily_pnl_at_entry", dailyPnlAtEntry);
trade.Add("session_tag", sessionTag);
trade.Add("code_version", codeVersion);
return JsonConvert.SerializeObject(trade);
}
private static double GetDouble(Dictionary<string, object> metadata, string key)
{
object value;
if (!metadata.TryGetValue(key, out value) || value == null)
return 0.0;
if (value is double)
return (double)value;
if (value is decimal)
return (double)(decimal)value;
if (value is float)
return (double)(float)value;
if (value is int)
return (double)(int)value;
if (value is long)
return (double)(long)value;
return 0.0;
}
}
}