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.
This commit is contained in:
@@ -106,19 +106,24 @@ public class MessengerService : IMessengerService
|
|||||||
var message = $"🔒 Closing : {position.OriginDirection} {position.Open.Ticker} \n" +
|
var message = $"🔒 Closing : {position.OriginDirection} {position.Open.Ticker} \n" +
|
||||||
$"📈 Open Price : {position.Open.Price} \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))
|
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";
|
message += $"💰 Closing Price : {closingPrice.Value} \n";
|
||||||
}
|
|
||||||
|
|
||||||
if (position.TakeProfit2?.Status.Equals(Enums.TradeStatus.Filled) == true)
|
|
||||||
{
|
|
||||||
message += $"🎯 TP2 Hit: {position.TakeProfit2.Price} \n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pnl = position.ProfitAndLoss?.Net ?? 0;
|
var pnl = position.ProfitAndLoss?.Net ?? 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user