update messenger
This commit is contained in:
@@ -46,7 +46,58 @@ public class MessengerService : IMessengerService
|
||||
|
||||
public async Task SendPosition(Position position)
|
||||
{
|
||||
await _discordService.SendPosition(position);
|
||||
// Send to Discord with try-catch to not block
|
||||
try
|
||||
{
|
||||
await _discordService.SendPosition(position);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
|
||||
// Send to webhook (n8n/telegram)
|
||||
try
|
||||
{
|
||||
var message = BuildPositionMessage(position);
|
||||
await _webhookService.SendMessage(message, position.User?.TelegramChannel);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
private string BuildPositionMessage(Position position)
|
||||
{
|
||||
var direction = position.OriginDirection.ToString();
|
||||
var status = position.Status.ToString();
|
||||
|
||||
var message = $"🎯 Position {status}\n" +
|
||||
$"Symbol: {position.Ticker}\n" +
|
||||
$"Direction: {direction}\n" +
|
||||
$"Account: {position.AccountName}\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}";
|
||||
}
|
||||
|
||||
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}";
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public async Task SendSignal(string message, Enums.TradingExchanges exchange, Enums.Ticker ticker,
|
||||
|
||||
Reference in New Issue
Block a user