Add average time

This commit is contained in:
2025-06-01 14:59:55 +07:00
parent faafedbdd9
commit 8f8bdf8d69
3 changed files with 91 additions and 3 deletions

View File

@@ -799,6 +799,26 @@ public class TradingBot : Bot, ITradingBot
{
if (Positions.Any(p => p.Identifier == position.Identifier))
{
// Update the close date for the trade that actually closed the position
var currentCandle = Config.IsForBacktest
? OptimizedCandles.LastOrDefault()
: ExchangeService.GetCandle(Account, Config.Ticker, DateTime.UtcNow);
if (currentCandle != null && position.ProfitAndLoss != null)
{
// Determine which trade closed the position based on realized P&L
if (position.ProfitAndLoss.Realized > 0)
{
// Profitable close = Take Profit
position.TakeProfit1.SetDate(currentCandle.Date);
}
else
{
// Loss or breakeven close = Stop Loss
position.StopLoss.SetDate(currentCandle.Date);
}
}
await SetPositionStatus(position.SignalIdentifier, PositionStatus.Finished);
Logger.LogInformation(
$"Position {position.SignalIdentifier} type correctly close. Pnl on position : {position.ProfitAndLoss?.Realized}");