Rename strategy to indicators
This commit is contained in:
@@ -4,10 +4,10 @@ using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Infrastructure.Databases.MongoDb.Collections
|
||||
{
|
||||
[BsonCollection("Strategies")]
|
||||
public class StrategyDto : Document
|
||||
[BsonCollection("Indicators")]
|
||||
public class IndicatorDto : Document
|
||||
{
|
||||
public StrategyType Type { get; set; }
|
||||
public IndicatorType Type { get; set; }
|
||||
public Timeframe Timeframe { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int MinimumHistory { get; set; }
|
||||
@@ -22,4 +22,4 @@ namespace Managing.Infrastructure.Databases.MongoDb.Collections
|
||||
public SignalType SignalType { get; set; }
|
||||
public UserDto User { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Managing.Infrastructure.Databases.MongoDb.Collections
|
||||
public class ScenarioDto : Document
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<StrategyDto> Strategies { get; set; }
|
||||
public List<IndicatorDto> Indicators { get; set; }
|
||||
public int LoopbackPeriod { get; set; }
|
||||
public UserDto User { get; set; }
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Managing.Infrastructure.Databases.MongoDb.Collections
|
||||
public Ticker Ticker { get; set; }
|
||||
public SignalStatus Status { get; set; }
|
||||
public Timeframe Timeframe { get; set; }
|
||||
public StrategyType Type { get; set; }
|
||||
public IndicatorType Type { get; set; }
|
||||
public SignalType SignalType { get; set; }
|
||||
public UserDto User { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -370,7 +370,7 @@ public static class MongoMappers
|
||||
Ticker = signal.Ticker,
|
||||
Status = signal.Status,
|
||||
Timeframe = signal.Timeframe,
|
||||
Type = signal.StrategyType,
|
||||
Type = signal.IndicatorType,
|
||||
User = signal.User != null ? Map(signal.User) : null
|
||||
};
|
||||
}
|
||||
@@ -412,7 +412,7 @@ public static class MongoMappers
|
||||
return new ScenarioDto
|
||||
{
|
||||
Name = scenario.Name,
|
||||
Strategies = Map(scenario.Strategies),
|
||||
Indicators = Map(scenario.Indicators),
|
||||
LoopbackPeriod = scenario.LoopbackPeriod ?? 1,
|
||||
User = scenario.User != null ? Map(scenario.User) : null
|
||||
};
|
||||
@@ -430,64 +430,64 @@ public static class MongoMappers
|
||||
|
||||
var scenario = new Scenario(d.Name, d.LoopbackPeriod)
|
||||
{
|
||||
Strategies = d.Strategies.Select(s => Map(s)).ToList(),
|
||||
Indicators = d.Indicators.Select(s => Map(s)).ToList(),
|
||||
User = d.User != null ? Map(d.User) : null
|
||||
};
|
||||
return scenario;
|
||||
}
|
||||
|
||||
private static List<StrategyDto> Map(List<Strategy> strategies)
|
||||
private static List<IndicatorDto> Map(List<Indicator> indicators)
|
||||
{
|
||||
return strategies.ConvertAll(strategy => Map(strategy));
|
||||
return indicators.ConvertAll(strategy => Map(strategy));
|
||||
}
|
||||
|
||||
internal static Strategy Map(StrategyDto strategyDto)
|
||||
internal static Indicator Map(IndicatorDto indicatorDto)
|
||||
{
|
||||
if (strategyDto == null)
|
||||
if (indicatorDto == null)
|
||||
return null;
|
||||
|
||||
return new Strategy(strategyDto.Name, strategyDto.Type)
|
||||
return new Indicator(indicatorDto.Name, indicatorDto.Type)
|
||||
{
|
||||
SignalType = strategyDto.SignalType,
|
||||
MinimumHistory = strategyDto.MinimumHistory,
|
||||
Period = strategyDto.Period,
|
||||
FastPeriods = strategyDto.FastPeriods,
|
||||
SlowPeriods = strategyDto.SlowPeriods,
|
||||
SignalPeriods = strategyDto.SignalPeriods,
|
||||
Multiplier = strategyDto.Multiplier,
|
||||
SmoothPeriods = strategyDto.SmoothPeriods,
|
||||
StochPeriods = strategyDto.StochPeriods,
|
||||
CyclePeriods = strategyDto.CyclePeriods,
|
||||
User = strategyDto.User != null ? Map(strategyDto.User) : null
|
||||
SignalType = indicatorDto.SignalType,
|
||||
MinimumHistory = indicatorDto.MinimumHistory,
|
||||
Period = indicatorDto.Period,
|
||||
FastPeriods = indicatorDto.FastPeriods,
|
||||
SlowPeriods = indicatorDto.SlowPeriods,
|
||||
SignalPeriods = indicatorDto.SignalPeriods,
|
||||
Multiplier = indicatorDto.Multiplier,
|
||||
SmoothPeriods = indicatorDto.SmoothPeriods,
|
||||
StochPeriods = indicatorDto.StochPeriods,
|
||||
CyclePeriods = indicatorDto.CyclePeriods,
|
||||
User = indicatorDto.User != null ? Map(indicatorDto.User) : null
|
||||
};
|
||||
}
|
||||
|
||||
internal static StrategyDto Map(Strategy strategy)
|
||||
internal static IndicatorDto Map(Indicator indicator)
|
||||
{
|
||||
if (strategy == null)
|
||||
if (indicator == null)
|
||||
return null;
|
||||
|
||||
return new StrategyDto
|
||||
return new IndicatorDto
|
||||
{
|
||||
Name = strategy.Name,
|
||||
Type = strategy.Type,
|
||||
SignalType = strategy.SignalType,
|
||||
MinimumHistory = strategy.MinimumHistory,
|
||||
Period = strategy.Period,
|
||||
FastPeriods = strategy.FastPeriods,
|
||||
SlowPeriods = strategy.SlowPeriods,
|
||||
SignalPeriods = strategy.SignalPeriods,
|
||||
Multiplier = strategy.Multiplier,
|
||||
SmoothPeriods = strategy.SmoothPeriods,
|
||||
StochPeriods = strategy.StochPeriods,
|
||||
CyclePeriods = strategy.CyclePeriods,
|
||||
User = strategy.User != null ? Map(strategy.User) : null
|
||||
Name = indicator.Name,
|
||||
Type = indicator.Type,
|
||||
SignalType = indicator.SignalType,
|
||||
MinimumHistory = indicator.MinimumHistory,
|
||||
Period = indicator.Period,
|
||||
FastPeriods = indicator.FastPeriods,
|
||||
SlowPeriods = indicator.SlowPeriods,
|
||||
SignalPeriods = indicator.SignalPeriods,
|
||||
Multiplier = indicator.Multiplier,
|
||||
SmoothPeriods = indicator.SmoothPeriods,
|
||||
StochPeriods = indicator.StochPeriods,
|
||||
CyclePeriods = indicator.CyclePeriods,
|
||||
User = indicator.User != null ? Map(indicator.User) : null
|
||||
};
|
||||
}
|
||||
|
||||
internal static IEnumerable<Strategy> Map(IEnumerable<StrategyDto> strategies)
|
||||
internal static IEnumerable<Indicator> Map(IEnumerable<IndicatorDto> indicators)
|
||||
{
|
||||
return strategies.Select(strategy => Map(strategy));
|
||||
return indicators.Select(indicator => Map(indicator));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -567,8 +567,8 @@ public static class MongoMappers
|
||||
Scenario = new ScenarioDto
|
||||
{
|
||||
Name = spotlight.Scenario.Name,
|
||||
Strategies =
|
||||
spotlight.Scenario.Strategies.ConvertAll(
|
||||
Indicators =
|
||||
spotlight.Scenario.Indicators.ConvertAll(
|
||||
spotlightScenarioStrategy => Map(spotlightScenarioStrategy))
|
||||
},
|
||||
TickerSignals = spotlight.TickerSignals.ConvertAll(spotlightTickerSignal => new TickerSignalDto
|
||||
@@ -607,8 +607,8 @@ public static class MongoMappers
|
||||
{
|
||||
Scenario = new Scenario(name: spotlight.Scenario.Name)
|
||||
{
|
||||
Strategies =
|
||||
spotlight.Scenario.Strategies.ConvertAll(
|
||||
Indicators =
|
||||
spotlight.Scenario.Indicators.ConvertAll(
|
||||
spotlightScenarioStrategy => Map(spotlightScenarioStrategy))
|
||||
},
|
||||
TickerSignals = spotlight.TickerSignals.ConvertAll(spotlightTickerSignal => new TickerSignal
|
||||
|
||||
@@ -16,20 +16,20 @@ public class TradingRepository : ITradingRepository
|
||||
private readonly IMongoRepository<ScenarioDto> _scenarioRepository;
|
||||
private readonly IMongoRepository<SignalDto> _signalRepository;
|
||||
private readonly IMongoRepository<PositionDto> _positionRepository;
|
||||
private readonly IMongoRepository<StrategyDto> _strategyRepository;
|
||||
private readonly IMongoRepository<IndicatorDto> _indicatorRepository;
|
||||
private readonly IMongoRepository<FeeDto> _feeRepository;
|
||||
|
||||
public TradingRepository(
|
||||
IMongoRepository<ScenarioDto> scenarioRepository,
|
||||
IMongoRepository<SignalDto> signalRepository,
|
||||
IMongoRepository<PositionDto> positionRepository,
|
||||
IMongoRepository<StrategyDto> strategyRepository,
|
||||
IMongoRepository<IndicatorDto> indicatorRepository,
|
||||
IMongoRepository<FeeDto> feeRepository)
|
||||
{
|
||||
_scenarioRepository = scenarioRepository;
|
||||
_signalRepository = signalRepository;
|
||||
_positionRepository = positionRepository;
|
||||
_strategyRepository = strategyRepository;
|
||||
_indicatorRepository = indicatorRepository;
|
||||
_feeRepository = feeRepository;
|
||||
}
|
||||
|
||||
@@ -44,15 +44,15 @@ public class TradingRepository : ITradingRepository
|
||||
_scenarioRepository.DropCollection();
|
||||
}
|
||||
|
||||
public void DeleteStrategies()
|
||||
public void DeleteIndicators()
|
||||
{
|
||||
_strategyRepository.DropCollection();
|
||||
_indicatorRepository.DropCollection();
|
||||
}
|
||||
|
||||
public void DeleteStrategy(string name)
|
||||
public void DeleteIndicator(string name)
|
||||
{
|
||||
var strategy = _strategyRepository.FindOne(s => s.Name == name);
|
||||
_strategyRepository.DeleteById(strategy.Id.ToString());
|
||||
var strategy = _indicatorRepository.FindOne(s => s.Name == name);
|
||||
_indicatorRepository.DeleteById(strategy.Id.ToString());
|
||||
}
|
||||
|
||||
public Position GetPositionByIdentifier(string identifier)
|
||||
@@ -87,15 +87,15 @@ public class TradingRepository : ITradingRepository
|
||||
return scenarios.Select(s => MongoMappers.Map(s));
|
||||
}
|
||||
|
||||
public IEnumerable<Strategy> GetStrategies()
|
||||
public IEnumerable<Indicator> GetIndicators()
|
||||
{
|
||||
var strategies = _strategyRepository.FindAll();
|
||||
return strategies.Select(MongoMappers.Map);
|
||||
var indicators = _indicatorRepository.FindAll();
|
||||
return indicators.Select(MongoMappers.Map);
|
||||
}
|
||||
|
||||
public Strategy GetStrategyByName(string name)
|
||||
public Indicator GetStrategyByName(string name)
|
||||
{
|
||||
var strategy = _strategyRepository.FindOne(s => s.Name == name);
|
||||
var strategy = _indicatorRepository.FindOne(s => s.Name == name);
|
||||
return MongoMappers.Map(strategy);
|
||||
}
|
||||
|
||||
@@ -129,17 +129,17 @@ public class TradingRepository : ITradingRepository
|
||||
$"Scenario with name '{scenario.Name}' already exists for user '{scenario.User?.Name}'");
|
||||
}
|
||||
|
||||
var strategyDtos = new List<StrategyDto>();
|
||||
foreach (var strategy in scenario.Strategies)
|
||||
var strategyDtos = new List<IndicatorDto>();
|
||||
foreach (var strategy in scenario.Indicators)
|
||||
{
|
||||
var dto = _strategyRepository.FindOne(s => s.Name == strategy.Name);
|
||||
var dto = _indicatorRepository.FindOne(s => s.Name == strategy.Name);
|
||||
strategyDtos.Add(dto);
|
||||
}
|
||||
|
||||
var scenarioDto = new ScenarioDto
|
||||
{
|
||||
Name = scenario.Name,
|
||||
Strategies = strategyDtos,
|
||||
Indicators = strategyDtos,
|
||||
User = scenario.User != null ? MongoMappers.Map(scenario.User) : null
|
||||
};
|
||||
|
||||
@@ -165,21 +165,21 @@ public class TradingRepository : ITradingRepository
|
||||
_signalRepository.InsertOne(dto);
|
||||
}
|
||||
|
||||
public void InsertStrategy(Strategy strategy)
|
||||
public void InsertStrategy(Indicator indicator)
|
||||
{
|
||||
// Check if strategy already exists for the same user
|
||||
var existingStrategy = _strategyRepository.FindOne(s =>
|
||||
s.Name == strategy.Name &&
|
||||
(strategy.User == null || (s.User != null && s.User.Name == strategy.User.Name)));
|
||||
var existingStrategy = _indicatorRepository.FindOne(s =>
|
||||
s.Name == indicator.Name &&
|
||||
(indicator.User == null || (s.User != null && s.User.Name == indicator.User.Name)));
|
||||
|
||||
if (existingStrategy != null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Strategy with name '{strategy.Name}' already exists for user '{strategy.User?.Name}'");
|
||||
$"Strategy with name '{indicator.Name}' already exists for user '{indicator.User?.Name}'");
|
||||
}
|
||||
|
||||
var dto = MongoMappers.Map(strategy);
|
||||
_strategyRepository.InsertOne(dto);
|
||||
var dto = MongoMappers.Map(indicator);
|
||||
_indicatorRepository.InsertOne(dto);
|
||||
}
|
||||
|
||||
public void InsertFee(Fee fee)
|
||||
@@ -262,11 +262,11 @@ public class TradingRepository : ITradingRepository
|
||||
_scenarioRepository.Update(dto);
|
||||
}
|
||||
|
||||
public void UpdateStrategy(Strategy strategy)
|
||||
public void UpdateStrategy(Indicator indicator)
|
||||
{
|
||||
var s = _strategyRepository.FindOne(s => s.Name == strategy.Name);
|
||||
var dto = MongoMappers.Map(strategy);
|
||||
var s = _indicatorRepository.FindOne(s => s.Name == indicator.Name);
|
||||
var dto = MongoMappers.Map(indicator);
|
||||
dto.Id = s.Id;
|
||||
_strategyRepository.Update(dto);
|
||||
_indicatorRepository.Update(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user