docker files fixes from liaqat
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Managing.Application.ManageBot.Commands;
|
||||
|
||||
public class DeleteBotCommand : IRequest<bool>
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public DeleteBotCommand(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using MediatR;
|
||||
|
||||
namespace Managing.Application.ManageBot.Commands
|
||||
{
|
||||
public class GetActiveBotsCommand : IRequest<List<ITradingBot>>
|
||||
{
|
||||
public GetActiveBotsCommand()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Managing.Application.ManageBot.Commands
|
||||
{
|
||||
public class ToggleIsForWatchingCommand : IRequest<string>
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public ToggleIsForWatchingCommand(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using MediatR;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.ManageBot.Commands
|
||||
{
|
||||
public class StartBotCommand : IRequest<string>
|
||||
{
|
||||
public string Name { get; }
|
||||
public BotType BotType { get; }
|
||||
public Ticker Ticker { get; internal set; }
|
||||
public Timeframe Timeframe { get; internal set; }
|
||||
public bool IsForWatchingOnly { get; internal set; }
|
||||
public string Scenario { get; internal set; }
|
||||
public string AccountName { get; internal set; }
|
||||
public string MoneyManagementName { get; internal set; }
|
||||
|
||||
public StartBotCommand(BotType botType,
|
||||
string name,
|
||||
Ticker ticker,
|
||||
string scenario,
|
||||
Timeframe timeframe,
|
||||
string accountName,
|
||||
string moneyManagementName,
|
||||
bool isForWatchingOnly = false)
|
||||
{
|
||||
BotType = botType;
|
||||
Name = name;
|
||||
Scenario = scenario;
|
||||
Ticker = ticker;
|
||||
Timeframe = timeframe;
|
||||
IsForWatchingOnly = isForWatchingOnly;
|
||||
AccountName = accountName;
|
||||
MoneyManagementName = moneyManagementName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using MediatR;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.ManageBot.Commands
|
||||
{
|
||||
public class StopBotCommand : IRequest<string>
|
||||
{
|
||||
public string Name { get; }
|
||||
public BotType BotType { get; }
|
||||
|
||||
public StopBotCommand(BotType botType, string name)
|
||||
{
|
||||
BotType = botType;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using MediatR;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.ManageBot.Commands
|
||||
{
|
||||
public class RestartBotCommand : IRequest<string>
|
||||
{
|
||||
public string Name { get; }
|
||||
public BotType BotType { get; }
|
||||
|
||||
public RestartBotCommand(BotType botType, string name)
|
||||
{
|
||||
BotType = botType;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.ManageBot.Commands;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Managing.Application.ManageBot;
|
||||
|
||||
public class DeleteBotCommandHandler : IRequestHandler<DeleteBotCommand, bool>
|
||||
{
|
||||
private readonly ILogger<DeleteBotCommandHandler> _log;
|
||||
private readonly ITaskCache _taskCache;
|
||||
|
||||
public DeleteBotCommandHandler(ITaskCache taskCache, ILogger<DeleteBotCommandHandler> log)
|
||||
{
|
||||
_taskCache = taskCache;
|
||||
_log = log;
|
||||
}
|
||||
|
||||
public Task<bool> Handle(DeleteBotCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
_taskCache.Invalidate(request.Name);
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.LogError(e.Message);
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.ManageBot.Commands;
|
||||
using Managing.Core;
|
||||
using MediatR;
|
||||
|
||||
namespace Managing.Application.ManageBot
|
||||
{
|
||||
public class GetActiveBotsCommandHandler : IRequestHandler<GetActiveBotsCommand, List<ITradingBot>>
|
||||
{
|
||||
private readonly ITaskCache taskCache;
|
||||
|
||||
public GetActiveBotsCommandHandler(ITaskCache taskCache)
|
||||
{
|
||||
this.taskCache = taskCache;
|
||||
}
|
||||
|
||||
public Task<List<ITradingBot>> Handle(GetActiveBotsCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var cachedTask = taskCache.GetCache<AsyncLazy<ITradingBot>>();
|
||||
var result = new List<ITradingBot>();
|
||||
|
||||
foreach (var item in cachedTask)
|
||||
{
|
||||
result.Add(item.Value.Result);
|
||||
}
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.ManageBot.Commands;
|
||||
using Managing.Domain.Bots;
|
||||
using MediatR;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.ManageBot
|
||||
{
|
||||
public class RestartBotCommandHandler : IRequestHandler<RestartBotCommand, string>
|
||||
{
|
||||
private readonly ITaskCache _taskCache;
|
||||
|
||||
public RestartBotCommandHandler(ITaskCache taskCache)
|
||||
{
|
||||
_taskCache = taskCache;
|
||||
}
|
||||
|
||||
public Task<string> Handle(RestartBotCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
switch (request.BotType)
|
||||
{
|
||||
case BotType.SimpleBot:
|
||||
var simpleBot = _taskCache.Get<IBot>(request.Name);
|
||||
simpleBot.Restart();
|
||||
return Task.FromResult(simpleBot.GetStatus());
|
||||
case BotType.ScalpingBot:
|
||||
var scalpingBot = _taskCache.Get<ITradingBot>(request.Name);
|
||||
scalpingBot.Restart();
|
||||
return Task.FromResult(scalpingBot.GetStatus());
|
||||
case BotType.FlippingBot:
|
||||
var flippingBot = _taskCache.Get<ITradingBot>(request.Name);
|
||||
flippingBot.Restart();
|
||||
return Task.FromResult(flippingBot.GetStatus());
|
||||
default:
|
||||
return Task.FromResult(BotStatus.Down.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src/Managing.Application/ManageBot/StartBotCommandHandler.cs
Normal file
42
src/Managing.Application/ManageBot/StartBotCommandHandler.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
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 ITaskCache _taskCache;
|
||||
private readonly IMoneyManagementService _moneyManagementService;
|
||||
|
||||
public StartBotCommandHandler(IBotFactory botFactory, ITaskCache taskCache, IMoneyManagementService moneyManagementService)
|
||||
{
|
||||
_botFactory = botFactory;
|
||||
_taskCache = taskCache;
|
||||
_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:
|
||||
Func<Task<IBot>> simpleBot = () => Task.FromResult(_botFactory.CreateSimpleBot(request.Name, null));
|
||||
return Task.FromResult(_taskCache.AddOrGetExisting(request.Name, simpleBot).Result.GetStatus());
|
||||
case BotType.ScalpingBot:
|
||||
Func<Task<ITradingBot>> scalpingBot = () => Task.FromResult(_botFactory.CreateScalpingBot(request.AccountName, moneyManagement, request.Name, request.Ticker, request.Scenario, request.Timeframe, request.IsForWatchingOnly));
|
||||
return Task.FromResult(_taskCache.AddOrGetExisting(request.Name, scalpingBot).Result.GetStatus());
|
||||
case BotType.FlippingBot:
|
||||
Func<Task<ITradingBot>> flippingBot = () => Task.FromResult(_botFactory.CreateFlippingBot(request.AccountName, moneyManagement, request.Name, request.Ticker, request.Scenario, request.Timeframe, request.IsForWatchingOnly));
|
||||
return Task.FromResult(_taskCache.AddOrGetExisting(request.Name, flippingBot).Result.GetStatus());
|
||||
};
|
||||
|
||||
return Task.FromResult(botStatus.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/Managing.Application/ManageBot/StopBotCommandHandler.cs
Normal file
39
src/Managing.Application/ManageBot/StopBotCommandHandler.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.ManageBot.Commands;
|
||||
using Managing.Domain.Bots;
|
||||
using MediatR;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.ManageBot
|
||||
{
|
||||
public class StopBotCommandHandler : IRequestHandler<StopBotCommand, string>
|
||||
{
|
||||
private readonly ITaskCache _taskCache;
|
||||
|
||||
public StopBotCommandHandler(ITaskCache taskCache)
|
||||
{
|
||||
_taskCache = taskCache;
|
||||
}
|
||||
|
||||
public Task<string> Handle(StopBotCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
switch (request.BotType)
|
||||
{
|
||||
case BotType.SimpleBot:
|
||||
var simpleBot = _taskCache.Get<IBot>(request.Name);
|
||||
simpleBot.Stop();
|
||||
return Task.FromResult(simpleBot.GetStatus());
|
||||
case BotType.ScalpingBot:
|
||||
var scalpingBot = _taskCache.Get<ITradingBot>(request.Name);
|
||||
scalpingBot.Stop();
|
||||
return Task.FromResult(scalpingBot.GetStatus());
|
||||
case BotType.FlippingBot:
|
||||
var flippingBot = _taskCache.Get<ITradingBot>(request.Name);
|
||||
flippingBot.Stop();
|
||||
return Task.FromResult(flippingBot.GetStatus());
|
||||
default:
|
||||
return Task.FromResult(BotStatus.Down.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.ManageBot.Commands;
|
||||
using MediatR;
|
||||
|
||||
namespace Managing.Application.ManageBot
|
||||
{
|
||||
public class ToggleIsForWatchingCommandHandler : IRequestHandler<ToggleIsForWatchingCommand, string>
|
||||
{
|
||||
private readonly ITaskCache _taskCache;
|
||||
|
||||
public ToggleIsForWatchingCommandHandler(ITaskCache taskCache)
|
||||
{
|
||||
_taskCache = taskCache;
|
||||
}
|
||||
|
||||
public async Task<string> Handle(ToggleIsForWatchingCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var bot = _taskCache.Get<ITradingBot>(request.Name);
|
||||
await bot.ToggleIsForWatchOnly();
|
||||
return bot.GetStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user