docker files fixes from liaqat
This commit is contained in:
144
src/Managing.Application/Scenarios/ScenarioService.cs
Normal file
144
src/Managing.Application/Scenarios/ScenarioService.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Domain.Scenarios;
|
||||
using Managing.Domain.Strategies;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MongoDB.Driver;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.Scenarios
|
||||
{
|
||||
public class ScenarioService : IScenarioService
|
||||
{
|
||||
private readonly ILogger<ScenarioService> _logger;
|
||||
private readonly ITradingService _tradingService;
|
||||
|
||||
public ScenarioService(ILogger<ScenarioService> logger, ITradingService tradingService)
|
||||
{
|
||||
_logger = logger;
|
||||
_tradingService = tradingService;
|
||||
}
|
||||
|
||||
public Scenario CreateScenario(string name, List<string> strategies)
|
||||
{
|
||||
var scenario = new Scenario(name);
|
||||
|
||||
foreach (var strategy in strategies)
|
||||
{
|
||||
scenario.AddStrategy(_tradingService.GetStrategyByName(strategy));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_tradingService.InsertScenario(scenario);
|
||||
}
|
||||
catch (MongoCommandException ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
throw new Exception("Cannot create scenario");
|
||||
}
|
||||
|
||||
return scenario;
|
||||
}
|
||||
|
||||
public Strategy CreateStrategy(
|
||||
StrategyType type,
|
||||
Timeframe timeframe,
|
||||
string name,
|
||||
int? period = null,
|
||||
int? fastPeriods = null,
|
||||
int? slowPeriods = null,
|
||||
int? signalPeriods = null,
|
||||
double? multiplier = null,
|
||||
int? stochPeriods = null,
|
||||
int? smoothPeriods = null,
|
||||
int? cyclePeriods = null)
|
||||
{
|
||||
var strategy = ScenarioHelpers.BuildStrategy(
|
||||
type,
|
||||
timeframe,
|
||||
name,
|
||||
period,
|
||||
fastPeriods,
|
||||
slowPeriods,
|
||||
signalPeriods,
|
||||
multiplier,
|
||||
stochPeriods,
|
||||
smoothPeriods,
|
||||
cyclePeriods);
|
||||
_tradingService.InsertStrategy(strategy);
|
||||
return strategy;
|
||||
}
|
||||
|
||||
public IEnumerable<Scenario> GetScenarios()
|
||||
{
|
||||
return _tradingService.GetScenarios();
|
||||
}
|
||||
|
||||
public Scenario GetScenario(string name)
|
||||
{
|
||||
return _tradingService.GetScenarioByName(name);
|
||||
}
|
||||
|
||||
public IEnumerable<Strategy> GetStrategies()
|
||||
{
|
||||
return _tradingService.GetStrategies();
|
||||
}
|
||||
|
||||
public bool DeleteScenario(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_tradingService.DeleteScenario(name);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DeleteStrategy(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_tradingService.DeleteStrategy(name);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DeleteStrategies()
|
||||
{
|
||||
try
|
||||
{
|
||||
_tradingService.DeleteStrategies();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeleteScenarios()
|
||||
{
|
||||
try
|
||||
{
|
||||
_tradingService.DeleteScenarios();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user