Add copy trading functionality with StartCopyTrading endpoint and related models. Implemented position copying from master bot and subscription to copy trading stream in LiveTradingBotGrain. Updated TradingBotConfig to support copy trading parameters.

This commit is contained in:
2025-11-16 14:54:17 +07:00
parent 428e36d744
commit 1e15d5f23b
10 changed files with 711 additions and 173 deletions

View File

@@ -146,6 +146,35 @@ public class BotController : BaseController
}
}
/// <summary>
/// Starts a copy trading bot that mirrors trades from a master bot.
/// </summary>
/// <param name="request">The request containing copy trading parameters.</param>
/// <returns>A string indicating the result of the start operation.</returns>
[HttpPost]
[Route("StartCopyTrading")]
public async Task<ActionResult<string>> StartCopyTrading(StartCopyTradingRequest request)
{
try
{
var user = await GetUser();
if (user == null)
{
return Unauthorized("User not found");
}
var result = await _mediator.Send(new StartCopyTradingCommand(request.MasterBotIdentifier, request.BotTradingBalance, user));
await NotifyBotSubscriberAsync();
return Ok(result);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error starting copy trading bot");
return StatusCode(500, $"Error starting copy trading bot: {ex.Message}");
}
}
/// <summary>
/// Saves a bot configuration without starting it.
/// </summary>
@@ -963,4 +992,20 @@ public class StartBotRequest
public class SaveBotRequest : StartBotRequest
{
}
/// <summary>
/// Request model for starting a copy trading bot
/// </summary>
public class StartCopyTradingRequest
{
/// <summary>
/// The identifier of the master bot to copy trades from
/// </summary>
public Guid MasterBotIdentifier { get; set; }
/// <summary>
/// The trading balance for the copy trading bot
/// </summary>
public decimal BotTradingBalance { get; set; }
}