Fix Runtime by adding TotalRuntimeInSeconds

This commit is contained in:
2025-10-05 20:51:46 +07:00
parent 976c1a6580
commit f67ee330b3
18 changed files with 3142 additions and 50 deletions

View File

@@ -13,6 +13,11 @@ namespace Managing.Domain.Bots
public DateTime StartupTime { get; set; }
public DateTime CreateDate { get; set; }
// Runtime tracking fields
public DateTime? LastStartTime { get; set; }
public DateTime? LastStopTime { get; set; }
public long AccumulatedRunTimeSeconds { get; set; }
public int TradeWins { get; set; }
public int TradeLosses { get; set; }
public decimal Pnl { get; set; }
@@ -23,5 +28,21 @@ namespace Managing.Domain.Bots
public int LongPositionCount { get; set; }
public int ShortPositionCount { get; set; }
/// <summary>
/// Gets the total runtime in seconds, including the current session if the bot is running
/// </summary>
public long GetTotalRuntimeSeconds()
{
var totalSeconds = AccumulatedRunTimeSeconds;
// If bot is currently running, add current session time
if (Status == BotStatus.Running && LastStartTime.HasValue)
{
var currentSessionSeconds = (long)(DateTime.UtcNow - LastStartTime.Value).TotalSeconds;
totalSeconds += currentSessionSeconds;
}
return totalSeconds;
}
}
}