Update doc and todo (#4)

* Updade doc

* Updade doc
This commit is contained in:
Oda
2024-07-20 21:33:50 +07:00
committed by GitHub
parent a43e560d3a
commit 743d04e6c5
12 changed files with 483 additions and 71 deletions

View File

@@ -10,6 +10,11 @@ using static Managing.Common.Enums;
namespace Managing.Api.Controllers;
/// <summary>
/// Controller for managing backtest operations.
/// Provides endpoints for creating, retrieving, and deleting backtests.
/// Requires authorization for access.
/// </summary>
[ApiController]
[Authorize]
[Route("[controller]")]
@@ -22,6 +27,14 @@ public class BacktestController : ControllerBase
private readonly IAccountService _accountService;
private readonly IMoneyManagementService _moneyManagementService;
/// <summary>
/// Initializes a new instance of the <see cref="BacktestController"/> class.
/// </summary>
/// <param name="hubContext">The SignalR hub context for real-time communication.</param>
/// <param name="backtester">The service for backtesting strategies.</param>
/// <param name="scenarioService">The service for managing scenarios.</param>
/// <param name="accountService">The service for account management.</param>
/// <param name="moneyManagementService">The service for money management strategies.</param>
public BacktestController(
IHubContext<BotHub> hubContext,
IBacktester backtester,
@@ -36,18 +49,31 @@ public class BacktestController : ControllerBase
_moneyManagementService = moneyManagementService;
}
/// <summary>
/// Retrieves all backtests.
/// </summary>
/// <returns>A list of backtests.</returns>
[HttpGet]
public ActionResult<IEnumerable<Backtest>> Backtests()
{
return Ok(_backtester.GetBacktests());
}
/// <summary>
/// Deletes a specific backtest by ID.
/// </summary>
/// <param name="id">The ID of the backtest to delete.</param>
/// <returns>An ActionResult indicating the outcome of the operation.</returns>
[HttpDelete]
public ActionResult DeleteBacktest(string id)
{
return Ok(_backtester.DeleteBacktest(id));
}
/// <summary>
/// Deletes all backtests.
/// </summary>
/// <returns>An ActionResult indicating the outcome of the operation.</returns>
[HttpDelete]
[Route("deleteAll")]
public ActionResult DeleteBacktests()
@@ -55,6 +81,21 @@ public class BacktestController : ControllerBase
return Ok(_backtester.DeleteBacktests());
}
/// <summary>
/// Runs a backtest with the specified parameters.
/// </summary>
/// <param name="accountName">The name of the account to use for the backtest.</param>
/// <param name="botType">The type of bot to use for the backtest.</param>
/// <param name="ticker">The ticker symbol to backtest.</param>
/// <param name="scenarioName">The name of the scenario to use for the backtest.</param>
/// <param name="timeframe">The timeframe for the backtest.</param>
/// <param name="watchOnly">Whether to only watch the backtest without executing trades.</param>
/// <param name="days">The number of days to backtest.</param>
/// <param name="balance">The starting balance for the backtest.</param>
/// <param name="moneyManagementName">The name of the money management strategy to use.</param>
/// <param name="moneyManagement">The money management strategy details, if not using a named strategy.</param>
/// <param name="save">Whether to save the backtest results.</param>
/// <returns>The result of the backtest.</returns>
[HttpPost]
[Route("Run")]
public async Task<ActionResult<Backtest>> Run(string accountName,
@@ -124,10 +165,14 @@ public class BacktestController : ControllerBase
return Ok(backtestResult);
}
/// <summary>
/// Notifies subscribers about the backtesting results via SignalR.
/// </summary>
/// <param name="backtesting">The backtest result to notify subscribers about.</param>
private async Task NotifyBacktesingSubscriberAsync(Backtest backtesting)
{
if(backtesting != null){
await _hubContext.Clients.All.SendAsync("BacktestsSubscription", backtesting);
}
}
}
}