Balance for bot (#20)
* Add bot balance * Update amount to trade * fix initial trading balance * Update MM modal * fix backtest * stop bot if no more balance * Add constant for minimum trading * Add constant
This commit is contained in:
@@ -93,17 +93,6 @@ public class BacktestController : BaseController
|
||||
return Ok(_backtester.DeleteBacktestByUser(user, id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all backtests.
|
||||
/// </summary>
|
||||
/// <returns>An ActionResult indicating the outcome of the operation.</returns>
|
||||
[HttpDelete]
|
||||
[Route("deleteAll")]
|
||||
public ActionResult DeleteBacktests()
|
||||
{
|
||||
return Ok(_backtester.DeleteBacktests());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a backtest with the specified parameters.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using Managing.Application.Abstractions;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Hubs;
|
||||
using Managing.Application.ManageBot.Commands;
|
||||
using Managing.Common;
|
||||
using Managing.Domain.Trades;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -123,9 +124,16 @@ public class BotController : BaseController
|
||||
return BadRequest("Money management not found");
|
||||
}
|
||||
|
||||
// Validate initialTradingBalance
|
||||
if (request.InitialTradingBalance <= Constants.GMX.Config.MinimumPositionAmount)
|
||||
{
|
||||
return BadRequest(
|
||||
$"Initial trading balance must be greater than {Constants.GMX.Config.MinimumPositionAmount}");
|
||||
}
|
||||
|
||||
var result = await _mediator.Send(new StartBotCommand(request.BotType, request.BotName, request.Ticker,
|
||||
request.Scenario, request.Timeframe, request.AccountName, request.MoneyManagementName, user,
|
||||
request.IsForWatchOnly));
|
||||
request.IsForWatchOnly, request.InitialTradingBalance));
|
||||
|
||||
await NotifyBotSubscriberAsync();
|
||||
return Ok(result);
|
||||
@@ -430,7 +438,7 @@ public class BotController : BaseController
|
||||
|
||||
var activeBots = _botService.GetActiveBots();
|
||||
var bot = activeBots.FirstOrDefault(b => b.Name == request.BotName) as ApplicationTradingBot;
|
||||
|
||||
|
||||
if (bot == null)
|
||||
{
|
||||
return NotFound($"Bot {request.BotName} not found or is not a trading bot");
|
||||
@@ -474,7 +482,7 @@ public class BotController : BaseController
|
||||
|
||||
var activeBots = _botService.GetActiveBots();
|
||||
var bot = activeBots.FirstOrDefault(b => b.Name == request.BotName) as ApplicationTradingBot;
|
||||
|
||||
|
||||
if (bot == null)
|
||||
{
|
||||
return NotFound($"Bot {request.BotName} not found or is not a trading bot");
|
||||
@@ -508,7 +516,7 @@ public class BotController : BaseController
|
||||
|
||||
// Close the position at market price
|
||||
await bot.CloseTrade(signal, position, position.Open, lastCandle.Close, true);
|
||||
|
||||
|
||||
await NotifyBotSubscriberAsync();
|
||||
return Ok(position);
|
||||
}
|
||||
@@ -529,7 +537,7 @@ public class ClosePositionRequest
|
||||
/// The name of the bot
|
||||
/// </summary>
|
||||
public string BotName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The ID of the position to close
|
||||
/// </summary>
|
||||
|
||||
@@ -150,6 +150,7 @@ public class TradingController : BaseController
|
||||
PositionInitiator.User,
|
||||
DateTime.UtcNow,
|
||||
user,
|
||||
100m, // Default trading balance for user-initiated trades
|
||||
isForPaperTrading: isForPaperTrading,
|
||||
price: openPrice);
|
||||
var result = await _openTradeCommandHandler.Handle(command);
|
||||
|
||||
@@ -5,21 +5,20 @@ namespace Managing.Api.Models.Requests
|
||||
{
|
||||
public class StartBotRequest
|
||||
{
|
||||
[Required] public BotType BotType { get; set; }
|
||||
[Required] public string BotName { get; set; }
|
||||
[Required] public Ticker Ticker { get; set; }
|
||||
[Required] public Timeframe Timeframe { get; set; }
|
||||
[Required] public bool IsForWatchOnly { get; set; }
|
||||
[Required] public string Scenario { get; set; }
|
||||
[Required] public string AccountName { get; set; }
|
||||
[Required] public string MoneyManagementName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initial trading balance in USD for the bot
|
||||
/// </summary>
|
||||
[Required]
|
||||
public BotType BotType { get; set; }
|
||||
[Required]
|
||||
public string BotName { get; set; }
|
||||
[Required]
|
||||
public Ticker Ticker { get; set; }
|
||||
[Required]
|
||||
public Timeframe Timeframe { get; set; }
|
||||
[Required]
|
||||
public bool IsForWatchOnly { get; set; }
|
||||
[Required]
|
||||
public string Scenario { get; set; }
|
||||
[Required]
|
||||
public string AccountName { get; set; }
|
||||
[Required]
|
||||
public string MoneyManagementName { get; set; }
|
||||
[Range(10.00, double.MaxValue, ErrorMessage = "Initial trading balance must be greater than ten")]
|
||||
public decimal InitialTradingBalance { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user