Add stats for kaigen
This commit is contained in:
@@ -6,6 +6,7 @@ using Managing.Domain.MoneyManagements;
|
||||
using Managing.Domain.Strategies;
|
||||
using Managing.Domain.Strategies.Base;
|
||||
using Managing.Domain.Trades;
|
||||
using Managing.Domain.Users;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.Abstractions
|
||||
@@ -26,6 +27,7 @@ namespace Managing.Application.Abstractions
|
||||
BotType BotType { get; set; }
|
||||
Dictionary<DateTime, decimal> WalletBalances { get; set; }
|
||||
Dictionary<StrategyType, StrategiesResultBase> StrategiesValues { get; set; }
|
||||
User User { get; set; }
|
||||
|
||||
Task Run();
|
||||
Task ToggleIsForWatchOnly();
|
||||
|
||||
@@ -48,6 +48,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
public Scenario Scenario { get; set; }
|
||||
public Dictionary<DateTime, decimal> WalletBalances { get; set; }
|
||||
public Dictionary<StrategyType, StrategiesResultBase> StrategiesValues { get; set; }
|
||||
public DateTime StartupTime { get; set; }
|
||||
|
||||
public TradingBot(
|
||||
string accountName,
|
||||
@@ -139,6 +140,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
else
|
||||
{
|
||||
Account = account;
|
||||
// Set the User property from the account
|
||||
User = account.User;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -806,7 +809,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
AccountName = AccountName,
|
||||
IsForWatchingOnly = IsForWatchingOnly,
|
||||
WalletBalances = WalletBalances,
|
||||
MoneyManagement = MoneyManagement
|
||||
MoneyManagement = MoneyManagement,
|
||||
StartupTime = DateTime.Now
|
||||
};
|
||||
BotService.SaveOrUpdateBotBackup(Name, BotType, JsonConvert.SerializeObject(data));
|
||||
}
|
||||
@@ -823,6 +827,12 @@ public class TradingBot : Bot, ITradingBot
|
||||
ScenarioName = data.ScenarioName;
|
||||
AccountName = data.AccountName;
|
||||
IsForWatchingOnly = data.IsForWatchingOnly;
|
||||
|
||||
// Restore the startup time if it was previously saved
|
||||
if (data.StartupTime != DateTime.MinValue)
|
||||
{
|
||||
StartupTime = data.StartupTime;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -883,4 +893,5 @@ public class TradingBotBackup
|
||||
public bool IsForWatchingOnly { get; set; }
|
||||
public Dictionary<DateTime, decimal> WalletBalances { get; set; }
|
||||
public MoneyManagement MoneyManagement { get; set; }
|
||||
public DateTime StartupTime { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using MediatR;
|
||||
|
||||
namespace Managing.Application.ManageBot.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Command to retrieve all strategies owned by a specific user
|
||||
/// </summary>
|
||||
public class GetUserStrategiesCommand : IRequest<List<ITradingBot>>
|
||||
{
|
||||
public string UserName { get; }
|
||||
|
||||
public GetUserStrategiesCommand(string userName)
|
||||
{
|
||||
UserName = userName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using MediatR;
|
||||
|
||||
namespace Managing.Application.ManageBot.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Command to retrieve a specific strategy owned by a user
|
||||
/// </summary>
|
||||
public class GetUserStrategyCommand : IRequest<ITradingBot>
|
||||
{
|
||||
/// <summary>
|
||||
/// The username of the agent/user that owns the strategy
|
||||
/// </summary>
|
||||
public string AgentName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the strategy/bot to retrieve
|
||||
/// </summary>
|
||||
public string StrategyName { get; }
|
||||
|
||||
public GetUserStrategyCommand(string agentName, string strategyName)
|
||||
{
|
||||
AgentName = agentName;
|
||||
StrategyName = strategyName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.ManageBot.Commands;
|
||||
using MediatR;
|
||||
|
||||
namespace Managing.Application.ManageBot
|
||||
{
|
||||
public class GetUserStrategiesCommandHandler : IRequestHandler<GetUserStrategiesCommand, List<ITradingBot>>
|
||||
{
|
||||
private readonly IBotService _botService;
|
||||
|
||||
public GetUserStrategiesCommandHandler(IBotService botService)
|
||||
{
|
||||
_botService = botService;
|
||||
}
|
||||
|
||||
public Task<List<ITradingBot>> Handle(GetUserStrategiesCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var allActiveBots = _botService.GetActiveBots();
|
||||
var userBots = allActiveBots
|
||||
.Where(bot => bot.User != null && bot.User.Name == request.UserName)
|
||||
.ToList();
|
||||
|
||||
return Task.FromResult(userBots);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.ManageBot.Commands;
|
||||
using MediatR;
|
||||
|
||||
namespace Managing.Application.ManageBot
|
||||
{
|
||||
/// <summary>
|
||||
/// Handler for retrieving a specific strategy owned by a user
|
||||
/// </summary>
|
||||
public class GetUserStrategyCommandHandler : IRequestHandler<GetUserStrategyCommand, ITradingBot>
|
||||
{
|
||||
private readonly IBotService _botService;
|
||||
|
||||
public GetUserStrategyCommandHandler(IBotService botService)
|
||||
{
|
||||
_botService = botService;
|
||||
}
|
||||
|
||||
public Task<ITradingBot> Handle(GetUserStrategyCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var allActiveBots = _botService.GetActiveBots();
|
||||
|
||||
// Find the specific strategy that matches both user and strategy name
|
||||
var strategy = allActiveBots
|
||||
.FirstOrDefault(bot =>
|
||||
bot.User != null &&
|
||||
bot.User.Name == request.AgentName &&
|
||||
bot.Name == request.StrategyName);
|
||||
|
||||
return Task.FromResult(strategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user