chore: Improve wrapper thread safety and logging

- Add thread-safe locking to BaseNT8StrategyWrapper
- Add BasicLogger initialization
- Improve null checking and error handling
- Minor adapter enhancements
This commit is contained in:
2026-02-16 18:31:21 -05:00
parent 6325c091a0
commit 79dcb1890c
6 changed files with 565 additions and 71 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using NT8.Core.Common.Interfaces;
using NT8.Core.Common.Models;
using NT8.Core.Risk;
@@ -12,9 +13,11 @@ namespace NT8.Adapters.NinjaTrader
/// </summary>
public class NT8Adapter : INT8Adapter
{
private readonly object _lock = new object();
private readonly NT8DataAdapter _dataAdapter;
private readonly NT8OrderAdapter _orderAdapter;
private readonly NT8LoggingAdapter _loggingAdapter;
private readonly List<NT8OrderExecutionRecord> _executionHistory;
private IRiskManager _riskManager;
private IPositionSizer _positionSizer;
@@ -26,6 +29,7 @@ namespace NT8.Adapters.NinjaTrader
_dataAdapter = new NT8DataAdapter();
_orderAdapter = new NT8OrderAdapter();
_loggingAdapter = new NT8LoggingAdapter();
_executionHistory = new List<NT8OrderExecutionRecord>();
}
/// <summary>
@@ -67,10 +71,32 @@ namespace NT8.Adapters.NinjaTrader
/// </summary>
public void ExecuteIntent(StrategyIntent intent, SizingResult sizing)
{
if (intent == null)
{
throw new ArgumentNullException("intent");
}
if (sizing == null)
{
throw new ArgumentNullException("sizing");
}
// In a full implementation, this would execute the order through NT8
// For now, we'll just log what would be executed
_loggingAdapter.LogInformation("Executing intent: {0} {1} contracts at {2} ticks stop",
intent.Side, sizing.Contracts, intent.StopTicks);
lock (_lock)
{
_executionHistory.Add(new NT8OrderExecutionRecord(
intent.Symbol,
intent.Side,
intent.EntryType,
sizing.Contracts,
intent.StopTicks,
intent.TargetTicks,
DateTime.UtcNow));
}
}
/// <summary>
@@ -88,5 +114,17 @@ namespace NT8.Adapters.NinjaTrader
{
_orderAdapter.OnExecutionUpdate(executionId, orderId, price, quantity, marketPosition, time);
}
/// <summary>
/// Gets execution history captured by the order adapter.
/// </summary>
/// <returns>Execution history snapshot.</returns>
public IList<NT8OrderExecutionRecord> GetExecutionHistory()
{
lock (_lock)
{
return new List<NT8OrderExecutionRecord>(_executionHistory);
}
}
}
}