docker files fixes from liaqat
This commit is contained in:
20
src/Managing.Domain/Scenarios/Scenario.cs
Normal file
20
src/Managing.Domain/Scenarios/Scenario.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Managing.Domain.Strategies;
|
||||
|
||||
namespace Managing.Domain.Scenarios
|
||||
{
|
||||
public class Scenario
|
||||
{
|
||||
public Scenario(string name)
|
||||
{
|
||||
Name = name;
|
||||
Strategies = new List<Strategy>();
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public List<Strategy> Strategies { get; set; }
|
||||
public void AddStrategy(Strategy strategy)
|
||||
{
|
||||
Strategies.Add(strategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
148
src/Managing.Domain/Scenarios/ScenarioHelpers.cs
Normal file
148
src/Managing.Domain/Scenarios/ScenarioHelpers.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using Managing.Application.Strategies;
|
||||
using Managing.Domain.Strategies;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Domain.Scenarios;
|
||||
|
||||
public static class ScenarioHelpers
|
||||
{
|
||||
public static IEnumerable<IStrategy> GetStrategiesFromScenario(Scenario scenario)
|
||||
{
|
||||
var strategies = new List<IStrategy>();
|
||||
foreach (var strategy in scenario.Strategies)
|
||||
{
|
||||
IStrategy result = strategy.Type switch
|
||||
{
|
||||
StrategyType.StDev => new StDevContext(strategy.Name, strategy.Timeframe, strategy.Period.Value),
|
||||
StrategyType.RsiDivergence => new RSIDivergenceStrategy(strategy.Name, strategy.Timeframe, strategy.Period.Value),
|
||||
StrategyType.RsiDivergenceConfirm => new RSIDivergenceConfirmStrategy(strategy.Name, strategy.Timeframe, strategy.Period.Value),
|
||||
StrategyType.MacdCross => new MACDCrossStrategy(strategy.Name, strategy.Timeframe, strategy.FastPeriods.Value, strategy.SlowPeriods.Value, strategy.SignalPeriods.Value),
|
||||
StrategyType.EmaCross => new EmaCrossStrategy(strategy.Name, strategy.Timeframe, strategy.Period.Value),
|
||||
StrategyType.ThreeWhiteSoldiers => new ThreeWhiteSoldiersStrategy(strategy.Name, strategy.Timeframe, strategy.Period.Value),
|
||||
StrategyType.SuperTrend => new SuperTrendStrategy(strategy.Name, strategy.Timeframe, strategy.Period.Value, strategy.Multiplier.Value),
|
||||
StrategyType.ChandelierExit => new ChandelierExitStrategy(strategy.Name, strategy.Timeframe, strategy.Period.Value, strategy.Multiplier.Value),
|
||||
StrategyType.EmaTrend => new EmaTrendStrategy(strategy.Name, strategy.Timeframe, strategy.Period.Value),
|
||||
StrategyType.StochRsiTrend => new StochRsiTrendStrategy(strategy.Name, strategy.Timeframe, strategy.Period.Value, strategy.StochPeriods.Value, strategy.SignalPeriods.Value, strategy.SmoothPeriods.Value),
|
||||
StrategyType.Stc => new STCStrategy(strategy.Name, strategy.Timeframe, strategy.CyclePeriods.Value, strategy.FastPeriods.Value, strategy.SlowPeriods.Value),
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
|
||||
strategies.Add(result);
|
||||
}
|
||||
|
||||
return strategies;
|
||||
}
|
||||
|
||||
public static Strategy BuildStrategy(
|
||||
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 = new Strategy(name, timeframe, type);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case StrategyType.RsiDivergence:
|
||||
case StrategyType.RsiDivergenceConfirm:
|
||||
case StrategyType.EmaTrend:
|
||||
case StrategyType.EmaCross:
|
||||
case StrategyType.StDev:
|
||||
if (!period.HasValue)
|
||||
{
|
||||
throw new Exception($"Missing period for {strategy.Type} strategy type");
|
||||
}
|
||||
else
|
||||
{
|
||||
strategy.Period = period.Value;
|
||||
}
|
||||
break;
|
||||
case StrategyType.MacdCross:
|
||||
if (!fastPeriods.HasValue || !slowPeriods.HasValue || !signalPeriods.HasValue)
|
||||
{
|
||||
throw new Exception($"Missing fastPeriods or slowPeriods or signalPeriods, for {strategy.Type} strategy type");
|
||||
}
|
||||
else
|
||||
{
|
||||
strategy.FastPeriods = fastPeriods;
|
||||
strategy.SlowPeriods = slowPeriods;
|
||||
strategy.SignalPeriods = signalPeriods;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case StrategyType.ThreeWhiteSoldiers:
|
||||
break;
|
||||
case StrategyType.SuperTrend:
|
||||
case StrategyType.ChandelierExit:
|
||||
if (!period.HasValue || !multiplier.HasValue)
|
||||
{
|
||||
throw new Exception($"Missing period or multiplier, for {strategy.Type} strategy type");
|
||||
}
|
||||
else
|
||||
{
|
||||
strategy.Period = period;
|
||||
strategy.Multiplier = multiplier;
|
||||
}
|
||||
break;
|
||||
case StrategyType.StochRsiTrend:
|
||||
if (!period.HasValue
|
||||
|| !stochPeriods.HasValue
|
||||
|| !signalPeriods.HasValue
|
||||
|| !smoothPeriods.HasValue)
|
||||
{
|
||||
throw new Exception($"Missing period, stochPeriods, signalPeriods, smoothPeriods for {strategy.Type} strategy type");
|
||||
}
|
||||
else
|
||||
{
|
||||
strategy.Period = period;
|
||||
strategy.StochPeriods = stochPeriods;
|
||||
strategy.SignalPeriods = signalPeriods;
|
||||
strategy.SmoothPeriods = smoothPeriods;
|
||||
}
|
||||
break;
|
||||
case StrategyType.Stc:
|
||||
if (!fastPeriods.HasValue || !slowPeriods.HasValue || !cyclePeriods.HasValue)
|
||||
{
|
||||
throw new Exception($"Missing fastPeriods or slowPeriods or cyclePeriods, for {strategy.Type} strategy type");
|
||||
}
|
||||
else
|
||||
{
|
||||
strategy.FastPeriods = fastPeriods;
|
||||
strategy.SlowPeriods = slowPeriods;
|
||||
strategy.CyclePeriods = cyclePeriods;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return strategy;
|
||||
}
|
||||
|
||||
public static SignalType GetSignalType(StrategyType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
StrategyType.RsiDivergence => SignalType.Signal,
|
||||
StrategyType.RsiDivergenceConfirm => SignalType.Signal,
|
||||
StrategyType.MacdCross => SignalType.Signal,
|
||||
StrategyType.EmaCross => SignalType.Signal,
|
||||
StrategyType.ThreeWhiteSoldiers => SignalType.Signal,
|
||||
StrategyType.SuperTrend => SignalType.Signal,
|
||||
StrategyType.ChandelierExit => SignalType.Signal,
|
||||
StrategyType.EmaTrend => SignalType.Trend,
|
||||
StrategyType.Composite => SignalType.Signal,
|
||||
StrategyType.StochRsiTrend => SignalType.Trend,
|
||||
StrategyType.Stc => SignalType.Signal,
|
||||
StrategyType.StDev => SignalType.Context,
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user