Add signalr

This commit is contained in:
2025-07-21 19:54:04 +07:00
parent a32e9c33a8
commit 83ed78a1fa
11 changed files with 441 additions and 10 deletions

View File

@@ -2,6 +2,7 @@
using Managing.Application.Abstractions.Repositories;
using Managing.Application.Abstractions.Services;
using Managing.Application.Bots;
using Managing.Application.Hubs;
using Managing.Core.FixedSizedQueue;
using Managing.Domain.Accounts;
using Managing.Domain.Backtests;
@@ -13,8 +14,10 @@ using Managing.Domain.Strategies;
using Managing.Domain.Strategies.Base;
using Managing.Domain.Users;
using Managing.Domain.Workflows;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using static Managing.Common.Enums;
using LightBacktestResponse = Managing.Domain.Backtests.LightBacktest; // Use the domain model for notification
namespace Managing.Application.Backtesting
{
@@ -28,6 +31,7 @@ namespace Managing.Application.Backtesting
private readonly IAccountService _accountService;
private readonly IMessengerService _messengerService;
private readonly IKaigenService _kaigenService;
private readonly IHubContext<BacktestHub> _hubContext;
public Backtester(
IExchangeService exchangeService,
@@ -37,7 +41,8 @@ namespace Managing.Application.Backtesting
IScenarioService scenarioService,
IAccountService accountService,
IMessengerService messengerService,
IKaigenService kaigenService)
IKaigenService kaigenService,
IHubContext<BacktestHub> hubContext)
{
_exchangeService = exchangeService;
_botFactory = botFactory;
@@ -47,6 +52,7 @@ namespace Managing.Application.Backtesting
_accountService = accountService;
_messengerService = messengerService;
_kaigenService = kaigenService;
_hubContext = hubContext;
}
public Backtest RunSimpleBotBacktest(Workflow workflow, bool save = false)
@@ -604,5 +610,14 @@ namespace Managing.Application.Backtesting
{
return _backtestRepository.GetPendingBundleBacktestRequests();
}
/// <summary>
/// Sends a LightBacktestResponse to all SignalR subscribers of a bundle request.
/// </summary>
public async Task SendBundleBacktestUpdateAsync(string requestId, LightBacktestResponse response)
{
if (string.IsNullOrWhiteSpace(requestId) || response == null) return;
await _hubContext.Clients.Group($"bundle-{requestId}").SendAsync("BundleBacktestUpdate", response);
}
}
}