diff --git a/src/Managing.Application/Bots/TradingBotBase.cs b/src/Managing.Application/Bots/TradingBotBase.cs index 924a5ac8..a48ccb2d 100644 --- a/src/Managing.Application/Bots/TradingBotBase.cs +++ b/src/Managing.Application/Bots/TradingBotBase.cs @@ -812,11 +812,14 @@ public class TradingBotBase : ITradingBot var currentTime = Config.IsForBacktest ? lastCandle.Date : DateTime.UtcNow; var currentPnl = positionForSignal.ProfitAndLoss?.Net ?? 0; - var pnlPercentage = TradingBox.CalculatePnLPercentage(currentPnl, positionForSignal.Open.Price, positionForSignal.Open.Quantity); + var pnlPercentage = TradingBox.CalculatePnLPercentage(currentPnl, positionForSignal.Open.Price, + positionForSignal.Open.Quantity); - var isPositionInProfit = TradingBox.IsPositionInProfit(positionForSignal.Open.Price, lastCandle.Close, positionForSignal.OriginDirection); + var isPositionInProfit = TradingBox.IsPositionInProfit(positionForSignal.Open.Price, lastCandle.Close, + positionForSignal.OriginDirection); - var hasExceededTimeLimit = TradingBox.HasPositionExceededTimeLimit(positionForSignal.Open.Date, currentTime, Config.MaxPositionTimeHours); + var hasExceededTimeLimit = TradingBox.HasPositionExceededTimeLimit(positionForSignal.Open.Date, + currentTime, Config.MaxPositionTimeHours); if (hasExceededTimeLimit) { @@ -1241,7 +1244,7 @@ public class TradingBotBase : ITradingBot .ToList(); var canOpen = TradingBox.CheckLossStreak(recentPositions, Config.MaxLossStreak, signal.Direction); - + if (!canOpen) { var lastPosition = recentPositions.First(); @@ -1699,7 +1702,7 @@ public class TradingBotBase : ITradingBot closingPrice = position.OriginDirection == TradeDirection.Long ? minPriceRecent // For LONG, SL hits at the low : maxPriceRecent; // For SHORT, SL hits at the high - + position.StopLoss.Price = closingPrice; } @@ -1738,7 +1741,7 @@ public class TradingBotBase : ITradingBot closingPrice = position.OriginDirection == TradeDirection.Long ? maxPriceRecent // For LONG, TP hits at the high : minPriceRecent; // FOR SHORT, TP hits at the low - + position.TakeProfit1.Price = closingPrice; } @@ -1852,7 +1855,8 @@ public class TradingBotBase : ITradingBot var entryPrice = position.Open.Price; var positionSize = TradingBox.CalculatePositionSize(position.Open.Quantity, position.Open.Leverage); - decimal pnl = TradingBox.CalculatePnL(entryPrice, closingPrice, position.Open.Quantity, position.Open.Leverage, position.OriginDirection); + decimal pnl = TradingBox.CalculatePnL(entryPrice, closingPrice, position.Open.Quantity, + position.Open.Leverage, position.OriginDirection); if (position.ProfitAndLoss == null) { @@ -1880,18 +1884,10 @@ public class TradingBotBase : ITradingBot $"Total Fees: `${position.GasFees + position.UiFees:F2}`\n" + $"Net P&L (after fees): `${position.ProfitAndLoss.Net:F2}`"; - if (Config.IsForBacktest) - { - // For backtest, use Console.WriteLine to see in test output - Console.WriteLine(logMessage); - } - else + if (!Config.IsForBacktest) { await LogDebug(logMessage); } - - // Fees are now tracked separately in UiFees and GasFees properties - // No need to subtract fees from PnL as they're tracked separately } SkipCandleBasedCalculation: @@ -2281,7 +2277,6 @@ public class TradingBotBase : ITradingBot /// The position to check /// The current time to compare against /// True if the position has exceeded the time limit, false otherwise - /// /// Updates the trading bot configuration with new settings. /// This method validates the new configuration and applies it to the running bot. @@ -2591,7 +2586,8 @@ public class TradingBotBase : ITradingBot } // Calculate cooldown end time based on last position closing time - var cooldownEndTime = TradingBox.CalculateCooldownEndTime(LastPositionClosingTime.Value, Config.Timeframe, Config.CooldownPeriod); + var cooldownEndTime = + TradingBox.CalculateCooldownEndTime(LastPositionClosingTime.Value, Config.Timeframe, Config.CooldownPeriod); var isInCooldown = (Config.IsForBacktest ? LastCandle.Date : DateTime.UtcNow) < cooldownEndTime; if (isInCooldown)