Fix bot things 2

This commit is contained in:
2025-02-11 02:06:35 +07:00
parent 898ff85eed
commit d7731dda0e
10 changed files with 164 additions and 121 deletions

View File

@@ -1,5 +1,6 @@
using Managing.Api.Models.Requests;
using Managing.Api.Models.Responses;
using Managing.Application.Abstractions;
using Managing.Application.Abstractions.Services;
using Managing.Application.Hubs;
using Managing.Application.ManageBot.Commands;
@@ -25,6 +26,7 @@ public class BotController : ControllerBase
private readonly ILogger<BotController> _logger;
private readonly IHubContext<BotHub> _hubContext;
private readonly IBacktester _backtester;
private readonly IBotService _botService;
/// <summary>
/// Initializes a new instance of the <see cref="BotController"/> class.
@@ -34,12 +36,13 @@ public class BotController : ControllerBase
/// <param name="hubContext">SignalR hub context for real-time communication.</param>
/// <param name="backtester">Backtester for running backtests on bots.</param>
public BotController(ILogger<BotController> logger, IMediator mediator, IHubContext<BotHub> hubContext,
IBacktester backtester)
IBacktester backtester, IBotService botService)
{
_logger = logger;
_mediator = mediator;
_hubContext = hubContext;
_backtester = backtester;
_botService = botService;
}
/// <summary>
@@ -86,11 +89,8 @@ public class BotController : ControllerBase
[Route("Delete")]
public async Task<ActionResult<bool>> Delete(string botName)
{
var result = await _mediator.Send(new DeleteBotCommand(botName));
_logger.LogInformation($"{botName} is now deleted");
var result = await _botService.DeleteBot(botName);
await NotifyBotSubscriberAsync();
return Ok(result);
}

View File

@@ -51,16 +51,19 @@ public class DataController : ControllerBase
/// <summary>
/// Retrieves tickers for a given account and timeframe, utilizing caching to improve performance.
/// </summary>
/// <param name="accountName">The name of the account to retrieve tickers for.</param>
/// <param name="timeframe">The timeframe for which to retrieve tickers.</param>
/// <returns>An array of tickers.</returns>
[HttpPost("GetTickers")]
public async Task<ActionResult<Ticker[]>> GetTickers(string accountName, Timeframe timeframe)
public async Task<ActionResult<Ticker[]>> GetTickers(Timeframe timeframe)
{
var account = await _accountService.GetAccount(accountName, true, false);
var cacheKey = string.Concat(accountName, timeframe.ToString());
var tickers = _cacheService.GetOrSave(cacheKey,
() => { return _exchangeService.GetTickers(account, timeframe).Result; }, TimeSpan.FromHours(2));
var cacheKey = string.Concat(timeframe.ToString());
var tickers = _cacheService.GetValue<List<Ticker>>(cacheKey);
if (tickers == null)
{
tickers = await _exchangeService.GetTickers(timeframe);
_cacheService.SaveValue(cacheKey, tickers, TimeSpan.FromHours(2));
}
return Ok(tickers);
}