Some checks failed
Build and Test / build (push) Has been cancelled
Implementation (7 files, ~2,640 lines): - AdvancedRiskManager with Tier 2-3 risk controls * Weekly rolling loss limits (7-day window, Monday rollover) * Trailing drawdown protection from peak equity * Cross-strategy exposure limits by symbol * Correlation-based position limits * Time-based trading windows * Risk mode system (Normal/Aggressive/Conservative) * Cooldown periods after violations - Optimal-f position sizing (Ralph Vince method) * Historical trade analysis * Risk of ruin calculation * Drawdown probability estimation * Dynamic leverage optimization - Volatility-adjusted position sizing * ATR-based sizing with regime detection * Standard deviation sizing * Volatility regimes (Low/Normal/High) * Dynamic size adjustment based on market conditions - OrderStateMachine for formal state management * State transition validation * State history tracking * Event logging for auditability Testing (90+ tests, >85% coverage): - 25+ advanced risk management tests - 47+ position sizing tests (optimal-f, volatility) - 18+ enhanced OMS tests - Integration tests for full flow validation - Performance benchmarks (all targets met) Documentation (140KB, ~5,500 lines): - Complete API reference (21KB) - Architecture overview (26KB) - Deployment guide (12KB) - Quick start guide (3.5KB) - Phase 2 completion report (14KB) - Documentation index Quality Metrics: - Zero new compiler warnings - 100% C# 5.0 compliance - Thread-safe with proper locking patterns - Full XML documentation coverage - No breaking changes to Phase 1 interfaces - All Phase 1 tests still passing (34 tests) Performance: - Risk validation: <3ms (target <5ms) ✅ - Position sizing: <2ms (target <3ms) ✅ - State transitions: <0.5ms (target <1ms) ✅ Phase 2 Status: ✅ COMPLETE Time: ~3 hours (vs 10-12 hours estimated manual) Ready for: Phase 3 (Market Microstructure & Execution)
123 lines
3.6 KiB
C#
123 lines
3.6 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using NT8.Adapters.NinjaTrader;
|
|
using System;
|
|
using System.IO;
|
|
|
|
namespace NT8.Integration.Tests
|
|
{
|
|
/// <summary>
|
|
/// Integration tests for NT8 logging adapter output formatting.
|
|
/// </summary>
|
|
[TestClass]
|
|
public class NT8LoggingAdapterIntegrationTests
|
|
{
|
|
[TestMethod]
|
|
public void LogDebug_WritesDebugPrefixAndFormattedMessage()
|
|
{
|
|
// Arrange
|
|
var adapter = new NT8LoggingAdapter();
|
|
|
|
// Act
|
|
var output = CaptureConsoleOutput(() => adapter.LogDebug("Order {0} created", "A1"));
|
|
|
|
// Assert
|
|
Assert.IsTrue(output.Contains("[DEBUG]"));
|
|
Assert.IsTrue(output.Contains("Order A1 created"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LogInformation_WritesInfoPrefixAndFormattedMessage()
|
|
{
|
|
// Arrange
|
|
var adapter = new NT8LoggingAdapter();
|
|
|
|
// Act
|
|
var output = CaptureConsoleOutput(() => adapter.LogInformation("Risk {0:F2}", 125.5));
|
|
|
|
// Assert
|
|
Assert.IsTrue(output.Contains("[INFO]"));
|
|
Assert.IsTrue(output.Contains("Risk 125.50"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LogWarning_WritesWarningPrefixAndMessage()
|
|
{
|
|
// Arrange
|
|
var adapter = new NT8LoggingAdapter();
|
|
|
|
// Act
|
|
var output = CaptureConsoleOutput(() => adapter.LogWarning("Max positions reached"));
|
|
|
|
// Assert
|
|
Assert.IsTrue(output.Contains("[WARN]"));
|
|
Assert.IsTrue(output.Contains("Max positions reached"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LogError_WritesErrorPrefixAndMessage()
|
|
{
|
|
// Arrange
|
|
var adapter = new NT8LoggingAdapter();
|
|
|
|
// Act
|
|
var output = CaptureConsoleOutput(() => adapter.LogError("Order {0} rejected", "B2"));
|
|
|
|
// Assert
|
|
Assert.IsTrue(output.Contains("[ERROR]"));
|
|
Assert.IsTrue(output.Contains("Order B2 rejected"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LogCritical_WritesCriticalPrefixAndMessage()
|
|
{
|
|
// Arrange
|
|
var adapter = new NT8LoggingAdapter();
|
|
|
|
// Act
|
|
var output = CaptureConsoleOutput(() => adapter.LogCritical("Emergency flatten executed"));
|
|
|
|
// Assert
|
|
Assert.IsTrue(output.Contains("[CRITICAL]"));
|
|
Assert.IsTrue(output.Contains("Emergency flatten executed"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LogMethods_InvalidFormat_ReturnOriginalMessageWithoutThrowing()
|
|
{
|
|
// Arrange
|
|
var adapter = new NT8LoggingAdapter();
|
|
|
|
// Act
|
|
var output = CaptureConsoleOutput(() => adapter.LogInformation("Bad format {0} {1}", "onlyOneArg"));
|
|
|
|
// Assert
|
|
Assert.IsTrue(output.Contains("[INFO]"));
|
|
Assert.IsTrue(output.Contains("Bad format {0} {1}"));
|
|
}
|
|
|
|
private static string CaptureConsoleOutput(Action action)
|
|
{
|
|
if (action == null)
|
|
{
|
|
throw new ArgumentNullException("action");
|
|
}
|
|
|
|
var originalOut = Console.Out;
|
|
var writer = new StringWriter();
|
|
|
|
try
|
|
{
|
|
Console.SetOut(writer);
|
|
action();
|
|
Console.Out.Flush();
|
|
return writer.ToString();
|
|
}
|
|
finally
|
|
{
|
|
Console.SetOut(originalOut);
|
|
writer.Dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|