Update position worker (#11)

* Update position worker

* Update todo
This commit is contained in:
Oda
2025-02-20 12:06:15 +07:00
committed by GitHub
parent d7731dda0e
commit 160fd02aac
9 changed files with 199 additions and 133 deletions

View File

@@ -39,13 +39,14 @@ public class TradingController : ControllerBase
ICommandHandler<OpenPositionRequest, Position> openTradeCommandHandler,
ICommandHandler<ClosePositionCommand, Position> closeTradeCommandHandler,
ITradingService tradingService,
IMediator mediator)
IMediator mediator, IMoneyManagementService moneyManagementService)
{
_logger = logger;
_openTradeCommandHandler = openTradeCommandHandler;
_closeTradeCommandHandler = closeTradeCommandHandler;
_tradingService = tradingService;
_mediator = mediator;
_moneyManagementService = moneyManagementService;
}
/// <summary>
@@ -112,7 +113,7 @@ public class TradingController : ControllerBase
/// <param name="moneyManagement">The money management strategy details (optional).</param>
/// <param name="openPrice">The opening price for the trade (optional).</param>
/// <returns>The opened position.</returns>
[HttpGet("OpenPosition")]
[HttpPost("OpenPosition")]
public async Task<ActionResult<Position>> Trade(
string accountName,
string moneyManagementName,
@@ -120,7 +121,7 @@ public class TradingController : ControllerBase
Ticker ticker,
RiskLevel riskLevel,
bool isForPaperTrading,
MoneyManagement? moneyManagement = null,
MoneyManagement? moneyManagement = null,
decimal? openPrice = null)
{
if (string.IsNullOrEmpty(accountName))
@@ -130,10 +131,11 @@ public class TradingController : ControllerBase
if (string.IsNullOrEmpty(moneyManagementName) && moneyManagement == null)
{
throw new ArgumentException($"'{nameof(moneyManagementName)}' cannot be null or empty.", nameof(moneyManagementName));
throw new ArgumentException($"'{nameof(moneyManagementName)}' cannot be null or empty.",
nameof(moneyManagementName));
}
if (moneyManagement == null)
if (moneyManagement != null)
{
moneyManagement = await _moneyManagementService.GetMoneyMangement(moneyManagementName);
}