53 lines
2.3 KiB
C#
53 lines
2.3 KiB
C#
using Managing.Domain.Bots;
|
|
using MediatR;
|
|
using static Managing.Common.Enums;
|
|
using Managing.Application.Abstractions;
|
|
using Managing.Application.ManageBot.Commands;
|
|
|
|
namespace Managing.Application.ManageBot
|
|
{
|
|
public class StartBotCommandHandler : IRequestHandler<StartBotCommand, string>
|
|
{
|
|
private readonly IBotFactory _botFactory;
|
|
private readonly IBotService _botService;
|
|
private readonly IMoneyManagementService _moneyManagementService;
|
|
|
|
public StartBotCommandHandler(IBotFactory botFactory, IBotService botService,
|
|
IMoneyManagementService moneyManagementService)
|
|
{
|
|
_botFactory = botFactory;
|
|
_botService = botService;
|
|
_moneyManagementService = moneyManagementService;
|
|
}
|
|
|
|
public Task<string> Handle(StartBotCommand request, CancellationToken cancellationToken)
|
|
{
|
|
BotStatus botStatus = BotStatus.Down;
|
|
var moneyManagement = _moneyManagementService.GetMoneyMangement(request.MoneyManagementName).Result;
|
|
switch (request.BotType)
|
|
{
|
|
case BotType.SimpleBot:
|
|
var bot = _botFactory.CreateSimpleBot(request.Name, null);
|
|
bot.Start();
|
|
_botService.AddSimpleBotToCache(bot);
|
|
return Task.FromResult(bot.GetStatus());
|
|
case BotType.ScalpingBot:
|
|
var sBot = _botFactory.CreateScalpingBot(request.AccountName, moneyManagement, request.Name,
|
|
request.Ticker, request.Scenario, request.Timeframe, request.IsForWatchingOnly);
|
|
sBot.Start();
|
|
_botService.AddTradingBotToCache(sBot);
|
|
return Task.FromResult(sBot.GetStatus());
|
|
case BotType.FlippingBot:
|
|
var fBot = _botFactory.CreateFlippingBot(request.AccountName, moneyManagement, request.Name,
|
|
request.Ticker, request.Scenario, request.Timeframe, request.IsForWatchingOnly);
|
|
fBot.Start();
|
|
_botService.AddTradingBotToCache(fBot);
|
|
return Task.FromResult(fBot.GetStatus());
|
|
}
|
|
|
|
;
|
|
|
|
return Task.FromResult(botStatus.ToString());
|
|
}
|
|
}
|
|
} |