Update messaging
This commit is contained in:
@@ -81,6 +81,22 @@ public class MessengerService : IMessengerService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SendClosedPosition(Position position, User user)
|
||||
{
|
||||
var message = BuildClosePositionMessage(position);
|
||||
await _discordService.SendMessage(message);
|
||||
await _webhookService.SendMessage(message, user.TelegramChannel);
|
||||
}
|
||||
|
||||
private string BuildClosePositionMessage(Position position)
|
||||
{
|
||||
return $"Closing : {position.OriginDirection} {position.Open.Ticker} \n" +
|
||||
$"Open Price : {position.Open.Price} \n" +
|
||||
$"Closing Price : {position.Open.Price} \n" +
|
||||
$"Quantity :{position.Open.Quantity} \n" +
|
||||
$"PNL : {position.ProfitAndLoss.Realized} $";
|
||||
}
|
||||
|
||||
public async Task SendMessage(string message, string telegramChannel)
|
||||
{
|
||||
await _webhookService.SendMessage(message, telegramChannel);
|
||||
@@ -91,27 +107,28 @@ public class MessengerService : IMessengerService
|
||||
var direction = position.OriginDirection.ToString();
|
||||
var status = position.Status.ToString();
|
||||
|
||||
var message = $"🎯 Position {status}\n" +
|
||||
var message = $"🎯 {status} Position \n" +
|
||||
$"Symbol: {position.Ticker}\n" +
|
||||
$"Direction: {direction}\n" +
|
||||
$"Identifier: {position.Identifier}\n" +
|
||||
$"Initiator: {position.Initiator}\n" +
|
||||
$"Date: {position.Date:yyyy-MM-dd HH:mm:ss}";
|
||||
|
||||
if (position.Open != null)
|
||||
{
|
||||
message += $"\nOpen Trade: {position.Open.Quantity} @ {position.Open.Price:F4}";
|
||||
message += $"\nOpen Trade: {position.Open.Quantity:F5} @ {position.Open.Price:F5}";
|
||||
}
|
||||
|
||||
if (position.StopLoss != null){
|
||||
message += $"\nStop Loss: {position.StopLoss.Quantity:F5} @ {position.StopLoss.Price:F5}";
|
||||
}
|
||||
|
||||
if (position.TakeProfit1 != null){
|
||||
message += $"\nTake Profit 1: {position.TakeProfit1.Quantity:F5} @ {position.TakeProfit1.Price:F5}";
|
||||
}
|
||||
|
||||
if (position.ProfitAndLoss != null)
|
||||
{
|
||||
var pnlEmoji = position.ProfitAndLoss.Realized >= 0 ? "✅" : "❌";
|
||||
message += $"\nPnL: {pnlEmoji} ${position.ProfitAndLoss.Realized:F2}";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(position.SignalIdentifier))
|
||||
{
|
||||
message += $"\nSignal: {position.SignalIdentifier}";
|
||||
message += $"\nPnL: {pnlEmoji} ${position.ProfitAndLoss.Realized:F5}";
|
||||
}
|
||||
|
||||
return message;
|
||||
@@ -194,47 +211,6 @@ public class MessengerService : IMessengerService
|
||||
}
|
||||
}
|
||||
|
||||
private string BuildBacktestConfigMessage(Backtest backtest)
|
||||
{
|
||||
var config = backtest.Config;
|
||||
|
||||
// Get indicators list as comma-separated string
|
||||
var indicators = config.Scenario?.Indicators != null && config.Scenario.Indicators.Any()
|
||||
? string.Join(", ", config.Scenario.Indicators.Select(i => i.Type.ToString()))
|
||||
: "N/A";
|
||||
|
||||
// MoneyManagement summary
|
||||
var mmSl = config.MoneyManagement != null ? (config.MoneyManagement.StopLoss * 100).ToString("F2") : "N/A";
|
||||
var mmTp = config.MoneyManagement != null ? (config.MoneyManagement.TakeProfit * 100).ToString("F2") : "N/A";
|
||||
var mmLev = config.MoneyManagement != null ? config.MoneyManagement.Leverage.ToString("F2") : "N/A";
|
||||
|
||||
return $"🚀 Excellent Backtest Results! 🚀\n\n" +
|
||||
$"🔹 {config.Ticker} | ⏱️ {config.Timeframe}\n" +
|
||||
$"💰 {config.BotTradingBalance:C}\n" +
|
||||
$"🛡️ SL: {mmSl}% | 🎯 TP: {mmTp}% | 📈 Lev: {mmLev}x\n" +
|
||||
$"🧩 {indicators}\n" +
|
||||
$"📅 {backtest.StartDate:yyyy-MM-dd} to {backtest.EndDate:yyyy-MM-dd}";
|
||||
}
|
||||
|
||||
private string BuildBacktestResultsMessage(Backtest backtest)
|
||||
{
|
||||
var config = backtest.Config;
|
||||
var score = backtest.Score;
|
||||
var winRate = backtest.WinRate;
|
||||
var tradeCount = backtest.Positions?.Count ?? 0;
|
||||
var finalPnl = backtest.FinalPnl;
|
||||
var growthPercentage = backtest.GrowthPercentage;
|
||||
var maxDrawdown = backtest.Statistics?.MaxDrawdownPc ?? 0;
|
||||
var sharpeRatio = (backtest.Statistics?.SharpeRatio * 100) ?? 0;
|
||||
|
||||
return $"📈 Performance Metrics:\n" +
|
||||
$"⭐ Score: {score:F1}/100 | 🏆 Win Rate: {winRate:F1}%\n" +
|
||||
$"📊 Trades: {tradeCount} | 💰 PnL: ${finalPnl:F2}\n" +
|
||||
$"📈 Growth: {growthPercentage:F1}% | 📉 DD: {maxDrawdown:F1}%\n" +
|
||||
$"📊 Sharpe: {sharpeRatio:F2}\n\n" +
|
||||
$"🆔 ID: {backtest.Id}";
|
||||
}
|
||||
|
||||
private string BuildBacktestMessage(Backtest backtest)
|
||||
{
|
||||
var config = backtest.Config;
|
||||
|
||||
Reference in New Issue
Block a user