From 94f86c893730c3902c723998a0383930a580d1a6 Mon Sep 17 00:00:00 2001 From: cryptooda Date: Tue, 6 Jan 2026 00:51:36 +0700 Subject: [PATCH] Refactor closing price determination in MessengerService - Introduced a new variable to capture the closing price based on filled stop loss or take profit trades, improving clarity in the closing message. - Enhanced message formatting to include the closing price when applicable, providing better feedback on trade outcomes. - Streamlined conditional checks for filled trades to ensure accurate reporting of closing prices. --- .../Shared/MessengerService.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Managing.Application/Shared/MessengerService.cs b/src/Managing.Application/Shared/MessengerService.cs index b5ea66d6..401cfa8c 100644 --- a/src/Managing.Application/Shared/MessengerService.cs +++ b/src/Managing.Application/Shared/MessengerService.cs @@ -106,19 +106,24 @@ public class MessengerService : IMessengerService var message = $"🔒 Closing : {position.OriginDirection} {position.Open.Ticker} \n" + $"📈 Open Price : {position.Open.Price} \n"; + // Determine closing price from whichever trade was filled + decimal? closingPrice = null; if (position.StopLoss.Status.Equals(Enums.TradeStatus.Filled)) { - message += $"🛑 SL Hit: {position.StopLoss.Price} \n"; + closingPrice = position.StopLoss.Price; + } + else if (position.TakeProfit1.Status.Equals(Enums.TradeStatus.Filled)) + { + closingPrice = position.TakeProfit1.Price; + } + else if (position.TakeProfit2?.Status.Equals(Enums.TradeStatus.Filled) == true) + { + closingPrice = position.TakeProfit2.Price; } - if (position.TakeProfit1.Status.Equals(Enums.TradeStatus.Filled)) + if (closingPrice.HasValue) { - message += $"🎯 TP1 Hit: {position.TakeProfit1.Price} \n"; - } - - if (position.TakeProfit2?.Status.Equals(Enums.TradeStatus.Filled) == true) - { - message += $"🎯 TP2 Hit: {position.TakeProfit2.Price} \n"; + message += $"💰 Closing Price : {closingPrice.Value} \n"; } var pnl = position.ProfitAndLoss?.Net ?? 0;