Compare commits
2 Commits
a87152effb
...
ee4da1b607
| Author | SHA1 | Date | |
|---|---|---|---|
| ee4da1b607 | |||
| a283ef4673 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -85,3 +85,10 @@ Thumbs.db
|
||||
tools/output/
|
||||
market-data/*.csv
|
||||
replay-data/
|
||||
|
||||
# Deployment backups (local only)
|
||||
deployment/backups/
|
||||
|
||||
# Build artifacts in deployment
|
||||
*.dll
|
||||
*.pdb
|
||||
|
||||
44
commit-now.ps1
Normal file
44
commit-now.ps1
Normal file
@@ -0,0 +1,44 @@
|
||||
# commit-now.ps1 - Stage and commit all current changes to Gitea
|
||||
# Run from: C:\dev\nt8-sdk
|
||||
|
||||
Set-Location "C:\dev\nt8-sdk"
|
||||
|
||||
Write-Host "`n=== Current Git Status ===" -ForegroundColor Cyan
|
||||
git status
|
||||
|
||||
Write-Host "`n=== Recent Commits ===" -ForegroundColor Cyan
|
||||
git log --oneline -5
|
||||
|
||||
Write-Host "`n=== Staging all changes ===" -ForegroundColor Cyan
|
||||
git add -A
|
||||
|
||||
Write-Host "`n=== Staged Files ===" -ForegroundColor Cyan
|
||||
git status
|
||||
|
||||
$commitMessage = @"
|
||||
chore: checkpoint before NT8 execution wiring fix
|
||||
|
||||
Current state: Strategy builds and loads correctly, passes 240+ tests,
|
||||
backtest (Strategy Analyzer) works but zero trades execute on live/SIM.
|
||||
|
||||
Root cause identified: NT8OrderAdapter.ExecuteInNT8() is a stub - it logs
|
||||
to an internal list but never calls EnterLong/EnterShort/SetStopLoss/
|
||||
SetProfitTarget. Fix is ready in TASK_01_WIRE_NT8_EXECUTION.md.
|
||||
|
||||
Task files added (ready for Kilocode):
|
||||
- TASK_01_WIRE_NT8_EXECUTION.md (CRITICAL - INT8ExecutionBridge + wiring)
|
||||
- TASK_02_EMERGENCY_KILL_SWITCH.md (CRITICAL - kill switch + verbose logging)
|
||||
- TASK_03_WIRE_CIRCUIT_BREAKER.md (HIGH - wire ExecutionCircuitBreaker)
|
||||
|
||||
Build Status: All 240+ tests passing, zero errors
|
||||
Next: Run Kilocode against TASK_01, TASK_02, TASK_03 in order
|
||||
"@
|
||||
|
||||
Write-Host "`n=== Committing ===" -ForegroundColor Cyan
|
||||
git commit -m $commitMessage
|
||||
|
||||
Write-Host "`n=== Pushing to Gitea ===" -ForegroundColor Cyan
|
||||
git push
|
||||
|
||||
Write-Host "`n=== Done! ===" -ForegroundColor Green
|
||||
git log --oneline -3
|
||||
@@ -12,7 +12,6 @@ set "CORE_BIN=%PROJECT_ROOT%\src\NT8.Core\bin\Release\net48"
|
||||
set "ADAPTERS_BIN=%PROJECT_ROOT%\src\NT8.Adapters\bin\Release\net48"
|
||||
set "WRAPPERS_SRC=%PROJECT_ROOT%\src\NT8.Adapters\Wrappers"
|
||||
set "BACKUP_ROOT=%SCRIPT_DIR%backups"
|
||||
set "MANIFEST_FILE=%BACKUP_DIR%\manifest.txt"
|
||||
|
||||
echo ============================================================
|
||||
echo NT8 SDK Deployment
|
||||
@@ -47,7 +46,8 @@ if not exist "%NT8_STRATEGIES%" (
|
||||
|
||||
for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd_HHmmss"') do set "STAMP=%%i"
|
||||
set "BACKUP_DIR=%BACKUP_ROOT%\%STAMP%"
|
||||
mkdir "%BACKUP_DIR%" >nul 2>&1
|
||||
set "MANIFEST_FILE=%BACKUP_ROOT%\%STAMP%\manifest.txt"
|
||||
mkdir "%BACKUP_ROOT%\%STAMP%" >nul 2>&1
|
||||
|
||||
echo Backing up existing NT8 SDK files...
|
||||
if exist "%NT8_CUSTOM%\NT8.Core.dll" copy /Y "%NT8_CUSTOM%\NT8.Core.dll" "%BACKUP_DIR%\NT8.Core.dll" >nul
|
||||
@@ -88,6 +88,19 @@ if errorlevel 1 (
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set "STRATEGIES_SRC=%PROJECT_ROOT%\src\NT8.Adapters\Strategies"
|
||||
copy /Y "%STRATEGIES_SRC%\NT8StrategyBase.cs" "%NT8_STRATEGIES%\NT8StrategyBase.cs" >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Failed to copy NT8StrategyBase.cs
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
copy /Y "%STRATEGIES_SRC%\SimpleORBNT8.cs" "%NT8_STRATEGIES%\SimpleORBNT8.cs" >nul
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Failed to copy SimpleORBNT8.cs
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Verifying deployment files...
|
||||
if not exist "%NT8_CUSTOM%\NT8.Core.dll" (
|
||||
echo ERROR: Verification failed for NT8.Core.dll
|
||||
|
||||
@@ -11,7 +11,6 @@ using NinjaTrader.Gui.Tools;
|
||||
using NinjaTrader.NinjaScript;
|
||||
using NinjaTrader.NinjaScript.Indicators;
|
||||
using NinjaTrader.NinjaScript.Strategies;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using NT8.Adapters.NinjaTrader;
|
||||
using NT8.Core.Common.Interfaces;
|
||||
using NT8.Core.Common.Models;
|
||||
@@ -152,7 +151,7 @@ namespace NinjaTrader.NinjaScript.Strategies
|
||||
catch (Exception ex)
|
||||
{
|
||||
Print(string.Format("[SDK ERROR] Initialization failed: {0}", ex.Message));
|
||||
Log(string.Format("[SDK ERROR] {0}", ex.ToString()), LogLevel.Error);
|
||||
Log(string.Format("[SDK ERROR] {0}", ex.ToString()), NinjaTrader.Cbi.LogLevel.Error);
|
||||
_sdkInitialized = false;
|
||||
}
|
||||
}
|
||||
@@ -236,7 +235,7 @@ namespace NinjaTrader.NinjaScript.Strategies
|
||||
_logger.LogError("OnBarUpdate failed: {0}", ex.Message);
|
||||
|
||||
Print(string.Format("[SDK ERROR] OnBarUpdate: {0}", ex.Message));
|
||||
Log(string.Format("[SDK ERROR] {0}", ex.ToString()), LogLevel.Error);
|
||||
Log(string.Format("[SDK ERROR] {0}", ex.ToString()), NinjaTrader.Cbi.LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +320,7 @@ namespace NinjaTrader.NinjaScript.Strategies
|
||||
_riskManager = new BasicRiskManager(_logger);
|
||||
_positionSizer = new BasicPositionSizer(_logger);
|
||||
_circuitBreaker = new ExecutionCircuitBreaker(
|
||||
NullLogger<ExecutionCircuitBreaker>.Instance,
|
||||
_logger,
|
||||
failureThreshold: 3,
|
||||
timeout: TimeSpan.FromSeconds(30));
|
||||
_executionAdapter = new NT8ExecutionAdapter();
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
[assembly: InternalsVisibleTo("NT8.Core.Tests")]
|
||||
[assembly: InternalsVisibleTo("NT8.Integration.Tests")]
|
||||
|
||||
namespace NT8.Core.Execution
|
||||
{
|
||||
/// <summary>
|
||||
@@ -11,6 +15,7 @@ namespace NT8.Core.Execution
|
||||
public class ExecutionCircuitBreaker
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly NT8.Core.Logging.ILogger _sdkLogger;
|
||||
private readonly object _lock = new object();
|
||||
|
||||
private CircuitBreakerStatus _status;
|
||||
@@ -21,24 +26,49 @@ namespace NT8.Core.Execution
|
||||
private readonly int _failureThreshold;
|
||||
private readonly TimeSpan _retryTimeout;
|
||||
|
||||
// Track execution times for latency monitoring
|
||||
private readonly Queue<TimeSpan> _executionTimes;
|
||||
private readonly int _latencyWindowSize;
|
||||
|
||||
// Track order rejections
|
||||
private readonly Queue<DateTime> _rejectionTimes;
|
||||
private readonly int _rejectionWindowSize;
|
||||
|
||||
// Log helpers — route through whichever logger is available
|
||||
private void LogDebug(string message) { if (_logger != null) _logger.LogDebug(message); else if (_sdkLogger != null) _sdkLogger.LogDebug(message); }
|
||||
private void LogInfo(string message) { if (_logger != null) _logger.LogInformation(message); else if (_sdkLogger != null) _sdkLogger.LogInformation(message); }
|
||||
private void LogWarn(string message) { if (_logger != null) _logger.LogWarning(message); else if (_sdkLogger != null) _sdkLogger.LogWarning(message); }
|
||||
private void LogErr(string message) { if (_logger != null) _logger.LogError(message); else if (_sdkLogger != null) _sdkLogger.LogError(message); }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for ExecutionCircuitBreaker
|
||||
/// Constructor accepting NT8.Core.Logging.ILogger.
|
||||
/// Use this overload from NinjaScript (.cs) files — no Microsoft.Extensions.Logging reference required.
|
||||
/// </summary>
|
||||
/// <param name="logger">Logger instance</param>
|
||||
/// <param name="failureThreshold">Number of failures to trigger circuit breaker</param>
|
||||
/// <param name="timeout">How long to stay open before half-open</param>
|
||||
/// <param name="retryTimeout">Time to wait between retries</param>
|
||||
/// <param name="latencyWindowSize">Size of latency tracking window</param>
|
||||
/// <param name="rejectionWindowSize">Size of rejection tracking window</param>
|
||||
public ExecutionCircuitBreaker(
|
||||
NT8.Core.Logging.ILogger sdkLogger,
|
||||
int failureThreshold = 3,
|
||||
TimeSpan? timeout = null,
|
||||
TimeSpan? retryTimeout = null,
|
||||
int latencyWindowSize = 100,
|
||||
int rejectionWindowSize = 10)
|
||||
{
|
||||
_sdkLogger = sdkLogger;
|
||||
_logger = null;
|
||||
_status = CircuitBreakerStatus.Closed;
|
||||
_failureCount = 0;
|
||||
_lastFailureTime = DateTime.MinValue;
|
||||
_timeout = timeout ?? TimeSpan.FromSeconds(30);
|
||||
_retryTimeout = retryTimeout ?? TimeSpan.FromSeconds(5);
|
||||
_failureThreshold = failureThreshold;
|
||||
_latencyWindowSize = latencyWindowSize;
|
||||
_rejectionWindowSize = rejectionWindowSize;
|
||||
_executionTimes = new Queue<TimeSpan>();
|
||||
_rejectionTimes = new Queue<DateTime>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor accepting Microsoft.Extensions.Logging.ILogger.
|
||||
/// Use this overload from DLL projects and unit tests.
|
||||
/// </summary>
|
||||
internal ExecutionCircuitBreaker(
|
||||
ILogger<ExecutionCircuitBreaker> logger,
|
||||
int failureThreshold = 3,
|
||||
TimeSpan? timeout = null,
|
||||
@@ -50,6 +80,7 @@ namespace NT8.Core.Execution
|
||||
throw new ArgumentNullException("logger");
|
||||
|
||||
_logger = logger;
|
||||
_sdkLogger = null;
|
||||
_status = CircuitBreakerStatus.Closed;
|
||||
_failureCount = 0;
|
||||
_lastFailureTime = DateTime.MinValue;
|
||||
@@ -58,15 +89,11 @@ namespace NT8.Core.Execution
|
||||
_failureThreshold = failureThreshold;
|
||||
_latencyWindowSize = latencyWindowSize;
|
||||
_rejectionWindowSize = rejectionWindowSize;
|
||||
|
||||
_executionTimes = new Queue<TimeSpan>();
|
||||
_rejectionTimes = new Queue<DateTime>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records execution time for monitoring
|
||||
/// </summary>
|
||||
/// <param name="latency">Execution latency</param>
|
||||
/// <summary>Records execution time for latency monitoring.</summary>
|
||||
public void RecordExecutionTime(TimeSpan latency)
|
||||
{
|
||||
try
|
||||
@@ -74,31 +101,21 @@ namespace NT8.Core.Execution
|
||||
lock (_lock)
|
||||
{
|
||||
_executionTimes.Enqueue(latency);
|
||||
|
||||
// Keep only the last N measurements
|
||||
while (_executionTimes.Count > _latencyWindowSize)
|
||||
{
|
||||
_executionTimes.Dequeue();
|
||||
}
|
||||
|
||||
// Check if we have excessive latency
|
||||
if (_status == CircuitBreakerStatus.Closed && HasExcessiveLatency())
|
||||
{
|
||||
TripCircuitBreaker("Excessive execution latency detected");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Failed to record execution time: {Message}", ex.Message);
|
||||
LogErr(string.Format("Failed to record execution time: {0}", ex.Message));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records order rejection for monitoring
|
||||
/// </summary>
|
||||
/// <param name="reason">Reason for rejection</param>
|
||||
/// <summary>Records an order rejection.</summary>
|
||||
public void RecordOrderRejection(string reason)
|
||||
{
|
||||
if (string.IsNullOrEmpty(reason))
|
||||
@@ -109,31 +126,21 @@ namespace NT8.Core.Execution
|
||||
lock (_lock)
|
||||
{
|
||||
_rejectionTimes.Enqueue(DateTime.UtcNow);
|
||||
|
||||
// Keep only the last N rejections
|
||||
while (_rejectionTimes.Count > _rejectionWindowSize)
|
||||
{
|
||||
_rejectionTimes.Dequeue();
|
||||
}
|
||||
|
||||
// Check if we have excessive rejections
|
||||
if (_status == CircuitBreakerStatus.Closed && HasExcessiveRejections())
|
||||
{
|
||||
TripCircuitBreaker(String.Format("Excessive order rejections: {0}", reason));
|
||||
}
|
||||
TripCircuitBreaker(string.Format("Excessive order rejections: {0}", reason));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Failed to record order rejection: {Message}", ex.Message);
|
||||
LogErr(string.Format("Failed to record order rejection: {0}", ex.Message));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if an order should be allowed based on circuit breaker state
|
||||
/// </summary>
|
||||
/// <returns>True if order should be allowed, false otherwise</returns>
|
||||
/// <summary>Returns true if an order should be allowed through.</summary>
|
||||
public bool ShouldAllowOrder()
|
||||
{
|
||||
try
|
||||
@@ -143,26 +150,20 @@ namespace NT8.Core.Execution
|
||||
switch (_status)
|
||||
{
|
||||
case CircuitBreakerStatus.Closed:
|
||||
// Normal operation
|
||||
return true;
|
||||
|
||||
case CircuitBreakerStatus.Open:
|
||||
// Check if we should transition to half-open
|
||||
if (DateTime.UtcNow >= _nextRetryTime)
|
||||
{
|
||||
_status = CircuitBreakerStatus.HalfOpen;
|
||||
_logger.LogWarning("Circuit breaker transitioning to Half-Open state");
|
||||
return true; // Allow one test order
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogDebug("Circuit breaker is Open - blocking order");
|
||||
return false; // Block orders
|
||||
LogWarn("Circuit breaker transitioning to Half-Open state");
|
||||
return true;
|
||||
}
|
||||
LogDebug("Circuit breaker is Open - blocking order");
|
||||
return false;
|
||||
|
||||
case CircuitBreakerStatus.HalfOpen:
|
||||
// In half-open, allow limited operations to test if system recovered
|
||||
_logger.LogDebug("Circuit breaker is Half-Open - allowing test order");
|
||||
LogDebug("Circuit breaker is Half-Open - allowing test order");
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -172,15 +173,12 @@ namespace NT8.Core.Execution
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Failed to check if order should be allowed: {Message}", ex.Message);
|
||||
LogErr(string.Format("Failed to check ShouldAllowOrder: {0}", ex.Message));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current state of the circuit breaker
|
||||
/// </summary>
|
||||
/// <returns>Current circuit breaker state</returns>
|
||||
/// <summary>Returns the current circuit breaker state.</summary>
|
||||
public CircuitBreakerState GetState()
|
||||
{
|
||||
try
|
||||
@@ -191,20 +189,17 @@ namespace NT8.Core.Execution
|
||||
_status != CircuitBreakerStatus.Closed,
|
||||
_status,
|
||||
GetStatusReason(),
|
||||
_failureCount
|
||||
);
|
||||
_failureCount);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Failed to get circuit breaker state: {Message}", ex.Message);
|
||||
LogErr(string.Format("Failed to get state: {0}", ex.Message));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the circuit breaker to closed state
|
||||
/// </summary>
|
||||
/// <summary>Resets the circuit breaker to Closed state.</summary>
|
||||
public void Reset()
|
||||
{
|
||||
try
|
||||
@@ -214,20 +209,17 @@ namespace NT8.Core.Execution
|
||||
_status = CircuitBreakerStatus.Closed;
|
||||
_failureCount = 0;
|
||||
_lastFailureTime = DateTime.MinValue;
|
||||
|
||||
_logger.LogInformation("Circuit breaker reset to Closed state");
|
||||
LogInfo("Circuit breaker reset to Closed state");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Failed to reset circuit breaker: {Message}", ex.Message);
|
||||
LogErr(string.Format("Failed to reset circuit breaker: {0}", ex.Message));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when an operation succeeds while in Half-Open state
|
||||
/// </summary>
|
||||
/// <summary>Call after a successful order submission.</summary>
|
||||
public void OnSuccess()
|
||||
{
|
||||
try
|
||||
@@ -237,20 +229,18 @@ namespace NT8.Core.Execution
|
||||
if (_status == CircuitBreakerStatus.HalfOpen)
|
||||
{
|
||||
Reset();
|
||||
_logger.LogInformation("Circuit breaker reset after successful test operation");
|
||||
LogInfo("Circuit breaker reset after successful test operation");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Failed to handle success in Half-Open state: {Message}", ex.Message);
|
||||
LogErr(string.Format("Failed to handle OnSuccess: {0}", ex.Message));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when an operation fails
|
||||
/// </summary>
|
||||
/// <summary>Call after a failed order submission.</summary>
|
||||
public void OnFailure()
|
||||
{
|
||||
try
|
||||
@@ -260,7 +250,6 @@ namespace NT8.Core.Execution
|
||||
_failureCount++;
|
||||
_lastFailureTime = DateTime.UtcNow;
|
||||
|
||||
// If we're in half-open and fail, go back to open
|
||||
if (_status == CircuitBreakerStatus.HalfOpen ||
|
||||
(_status == CircuitBreakerStatus.Closed && _failureCount >= _failureThreshold))
|
||||
{
|
||||
@@ -270,61 +259,35 @@ namespace NT8.Core.Execution
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Failed to handle failure: {Message}", ex.Message);
|
||||
LogErr(string.Format("Failed to handle OnFailure: {0}", ex.Message));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Trips the circuit breaker to open state
|
||||
/// </summary>
|
||||
/// <param name="reason">Reason for tripping</param>
|
||||
private void TripCircuitBreaker(string reason)
|
||||
{
|
||||
_status = CircuitBreakerStatus.Open;
|
||||
_nextRetryTime = DateTime.UtcNow.Add(_timeout);
|
||||
|
||||
_logger.LogWarning("Circuit breaker TRIPPED: {Reason}. Will retry at {Time}",
|
||||
reason, _nextRetryTime);
|
||||
LogWarn(string.Format("Circuit breaker TRIPPED: {0}. Will retry at {1}", reason, _nextRetryTime));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if we have excessive execution latency
|
||||
/// </summary>
|
||||
/// <returns>True if latency is excessive</returns>
|
||||
private bool HasExcessiveLatency()
|
||||
{
|
||||
if (_executionTimes.Count < 3) // Need minimum samples
|
||||
if (_executionTimes.Count < 3)
|
||||
return false;
|
||||
|
||||
// Calculate average latency
|
||||
var avgLatency = TimeSpan.FromMilliseconds(_executionTimes.Average(ts => ts.TotalMilliseconds));
|
||||
|
||||
// If average latency is more than 5 seconds, consider it excessive
|
||||
return avgLatency.TotalSeconds > 5.0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if we have excessive order rejections
|
||||
/// </summary>
|
||||
/// <returns>True if rejections are excessive</returns>
|
||||
private bool HasExcessiveRejections()
|
||||
{
|
||||
if (_rejectionTimes.Count < _rejectionWindowSize)
|
||||
return false;
|
||||
|
||||
// If all recent orders were rejected (100% rejection rate in window)
|
||||
var recentWindow = TimeSpan.FromMinutes(1); // Check last minute
|
||||
var recentWindow = TimeSpan.FromMinutes(1);
|
||||
var recentRejections = _rejectionTimes.Count(dt => DateTime.UtcNow - dt <= recentWindow);
|
||||
|
||||
// If we have maximum possible rejections in the window, it's excessive
|
||||
return recentRejections >= _rejectionWindowSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reason for current status
|
||||
/// </summary>
|
||||
/// <returns>Reason string</returns>
|
||||
private string GetStatusReason()
|
||||
{
|
||||
switch (_status)
|
||||
@@ -332,8 +295,7 @@ namespace NT8.Core.Execution
|
||||
case CircuitBreakerStatus.Closed:
|
||||
return "Normal operation";
|
||||
case CircuitBreakerStatus.Open:
|
||||
return String.Format("Tripped due to failures. Failures: {0}, Last: {1}",
|
||||
_failureCount, _lastFailureTime);
|
||||
return string.Format("Tripped due to failures. Count: {0}, Last: {1}", _failureCount, _lastFailureTime);
|
||||
case CircuitBreakerStatus.HalfOpen:
|
||||
return "Testing recovery after timeout";
|
||||
default:
|
||||
@@ -341,10 +303,7 @@ namespace NT8.Core.Execution
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets average execution time for monitoring
|
||||
/// </summary>
|
||||
/// <returns>Average execution time</returns>
|
||||
/// <summary>Returns average execution latency.</summary>
|
||||
public TimeSpan GetAverageExecutionTime()
|
||||
{
|
||||
try
|
||||
@@ -353,21 +312,17 @@ namespace NT8.Core.Execution
|
||||
{
|
||||
if (_executionTimes.Count == 0)
|
||||
return TimeSpan.Zero;
|
||||
|
||||
return TimeSpan.FromMilliseconds(_executionTimes.Average(ts => ts.TotalMilliseconds));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Failed to get average execution time: {Message}", ex.Message);
|
||||
LogErr(string.Format("Failed to get average execution time: {0}", ex.Message));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets rejection rate for monitoring
|
||||
/// </summary>
|
||||
/// <returns>Rejection rate as percentage</returns>
|
||||
/// <summary>Returns rejection rate as a percentage.</summary>
|
||||
public double GetRejectionRate()
|
||||
{
|
||||
try
|
||||
@@ -376,19 +331,14 @@ namespace NT8.Core.Execution
|
||||
{
|
||||
if (_rejectionTimes.Count == 0)
|
||||
return 0.0;
|
||||
|
||||
// Calculate rejections in last minute
|
||||
var oneMinuteAgo = DateTime.UtcNow.AddMinutes(-1);
|
||||
var recentRejections = _rejectionTimes.Count(dt => dt >= oneMinuteAgo);
|
||||
|
||||
// This is a simplified calculation - in practice you'd need to track
|
||||
// total attempts to calculate accurate rate
|
||||
return (double)recentRejections / _rejectionWindowSize * 100.0;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Failed to get rejection rate: {Message}", ex.Message);
|
||||
LogErr(string.Format("Failed to get rejection rate: {0}", ex.Message));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace NT8.Strategies.Examples
|
||||
private readonly double _stdDevMultiplier;
|
||||
|
||||
private ILogger _logger;
|
||||
private StrategyConfig _config;
|
||||
private ConfluenceScorer _scorer;
|
||||
private GradeFilter _gradeFilter;
|
||||
private RiskModeManager _riskModeManager;
|
||||
@@ -98,6 +99,7 @@ namespace NT8.Strategies.Examples
|
||||
try
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
_scorer = new ConfluenceScorer(_logger, 500);
|
||||
_gradeFilter = new GradeFilter();
|
||||
_riskModeManager = new RiskModeManager(_logger);
|
||||
@@ -151,6 +153,10 @@ namespace NT8.Strategies.Examples
|
||||
ResetSession(context.Session != null ? context.Session.SessionStart : context.CurrentTime.Date);
|
||||
}
|
||||
|
||||
// Only trade during RTH
|
||||
if (context.Session == null || !context.Session.IsRth)
|
||||
return null;
|
||||
|
||||
if (bar.Time <= _openingRangeEnd)
|
||||
{
|
||||
UpdateOpeningRange(bar);
|
||||
@@ -332,6 +338,13 @@ namespace NT8.Strategies.Examples
|
||||
|
||||
private StrategyIntent CreateIntent(string symbol, OrderSide side, double openingRange, double lastPrice)
|
||||
{
|
||||
var stopTicks = _config != null && _config.Parameters.ContainsKey("StopTicks")
|
||||
? (int)_config.Parameters["StopTicks"]
|
||||
: 8;
|
||||
var targetTicks = _config != null && _config.Parameters.ContainsKey("TargetTicks")
|
||||
? (int)_config.Parameters["TargetTicks"]
|
||||
: 16;
|
||||
|
||||
var metadata = new Dictionary<string, object>();
|
||||
metadata.Add("orb_high", _openingRangeHigh);
|
||||
metadata.Add("orb_low", _openingRangeLow);
|
||||
@@ -346,8 +359,8 @@ namespace NT8.Strategies.Examples
|
||||
side,
|
||||
OrderType.Market,
|
||||
null,
|
||||
8,
|
||||
16,
|
||||
stopTicks,
|
||||
targetTicks,
|
||||
0.75,
|
||||
"ORB breakout signal",
|
||||
metadata);
|
||||
|
||||
Reference in New Issue
Block a user