Rename strategy to indicators
This commit is contained in:
@@ -2,11 +2,10 @@
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Domain.Scenarios;
|
||||
using Managing.Domain.Strategies;
|
||||
using Managing.Domain.Users;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MongoDB.Driver;
|
||||
using static Managing.Common.Enums;
|
||||
using System.Collections.Generic;
|
||||
using Managing.Domain.Users;
|
||||
|
||||
namespace Managing.Application.Scenarios
|
||||
{
|
||||
@@ -27,7 +26,7 @@ namespace Managing.Application.Scenarios
|
||||
|
||||
foreach (var strategy in strategies)
|
||||
{
|
||||
scenario.AddStrategy(_tradingService.GetStrategyByName(strategy));
|
||||
scenario.AddIndicator(_tradingService.GetStrategyByName(strategy));
|
||||
}
|
||||
|
||||
try
|
||||
@@ -43,8 +42,8 @@ namespace Managing.Application.Scenarios
|
||||
return scenario;
|
||||
}
|
||||
|
||||
public Strategy CreateStrategy(
|
||||
StrategyType type,
|
||||
public Indicator CreateStrategy(
|
||||
IndicatorType type,
|
||||
string name,
|
||||
int? period = null,
|
||||
int? fastPeriods = null,
|
||||
@@ -55,7 +54,7 @@ namespace Managing.Application.Scenarios
|
||||
int? smoothPeriods = null,
|
||||
int? cyclePeriods = null)
|
||||
{
|
||||
var strategy = ScenarioHelpers.BuildStrategy(
|
||||
var strategy = ScenarioHelpers.BuildIndicator(
|
||||
type,
|
||||
name,
|
||||
period,
|
||||
@@ -80,7 +79,7 @@ namespace Managing.Application.Scenarios
|
||||
return _tradingService.GetScenarioByName(name);
|
||||
}
|
||||
|
||||
public IEnumerable<Strategy> GetStrategies()
|
||||
public IEnumerable<Indicator> GetStrategies()
|
||||
{
|
||||
return _tradingService.GetStrategies();
|
||||
}
|
||||
@@ -146,10 +145,10 @@ namespace Managing.Application.Scenarios
|
||||
try
|
||||
{
|
||||
var scenario = _tradingService.GetScenarioByName(name);
|
||||
scenario.Strategies.Clear();
|
||||
scenario.Indicators.Clear();
|
||||
foreach (var strategy in strategies)
|
||||
{
|
||||
scenario.AddStrategy(_tradingService.GetStrategyByName(strategy));
|
||||
scenario.AddIndicator(_tradingService.GetStrategyByName(strategy));
|
||||
}
|
||||
|
||||
scenario.LoopbackPeriod = loopbackPeriod ?? 1;
|
||||
@@ -163,14 +162,14 @@ namespace Managing.Application.Scenarios
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdateStrategy(StrategyType strategyType, string name, int? period, int? fastPeriods,
|
||||
public bool UpdateStrategy(IndicatorType indicatorType, string name, int? period, int? fastPeriods,
|
||||
int? slowPeriods,
|
||||
int? signalPeriods, double? multiplier, int? stochPeriods, int? smoothPeriods, int? cyclePeriods)
|
||||
{
|
||||
try
|
||||
{
|
||||
var strategy = _tradingService.GetStrategyByName(name);
|
||||
strategy.Type = strategyType;
|
||||
strategy.Type = indicatorType;
|
||||
strategy.Period = period;
|
||||
strategy.FastPeriods = fastPeriods;
|
||||
strategy.SlowPeriods = slowPeriods;
|
||||
@@ -203,13 +202,13 @@ namespace Managing.Application.Scenarios
|
||||
{
|
||||
User = user
|
||||
};
|
||||
|
||||
|
||||
foreach (var strategyName in strategies)
|
||||
{
|
||||
var strategy = _tradingService.GetStrategyByName(strategyName);
|
||||
if (strategy != null && strategy.User?.Name == user.Name)
|
||||
{
|
||||
scenario.AddStrategy(strategy);
|
||||
scenario.AddIndicator(strategy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,13 +216,13 @@ namespace Managing.Application.Scenarios
|
||||
return scenario;
|
||||
}
|
||||
|
||||
public IEnumerable<Strategy> GetStrategiesByUser(User user)
|
||||
public IEnumerable<Indicator> GetIndicatorsByUser(User user)
|
||||
{
|
||||
var strategies = _tradingService.GetStrategies();
|
||||
return strategies.Where(s => s.User?.Name == user.Name);
|
||||
}
|
||||
|
||||
public bool DeleteStrategyByUser(User user, string name)
|
||||
public bool DeleteIndicatorByUser(User user, string name)
|
||||
{
|
||||
var strategy = _tradingService.GetStrategyByName(name);
|
||||
if (strategy != null && strategy.User?.Name == user.Name)
|
||||
@@ -231,6 +230,7 @@ namespace Managing.Application.Scenarios
|
||||
_tradingService.DeleteStrategy(strategy.Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -242,6 +242,7 @@ namespace Managing.Application.Scenarios
|
||||
_tradingService.DeleteScenario(scenario.Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -251,35 +252,35 @@ namespace Managing.Application.Scenarios
|
||||
return scenario != null && scenario.User?.Name == user.Name ? scenario : null;
|
||||
}
|
||||
|
||||
public Strategy CreateStrategyForUser(User user, StrategyType type, string name, int? period = null,
|
||||
int? fastPeriods = null, int? slowPeriods = null, int? signalPeriods = null,
|
||||
double? multiplier = null, int? stochPeriods = null, int? smoothPeriods = null,
|
||||
public Indicator CreateIndicatorForUser(User user, IndicatorType type, 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)
|
||||
{
|
||||
// Create a new strategy using the existing implementation
|
||||
var strategy = CreateStrategy(type, name, period, fastPeriods, slowPeriods, signalPeriods,
|
||||
var strategy = CreateStrategy(type, name, period, fastPeriods, slowPeriods, signalPeriods,
|
||||
multiplier, stochPeriods, smoothPeriods, cyclePeriods);
|
||||
|
||||
|
||||
// Set the user
|
||||
strategy.User = user;
|
||||
|
||||
|
||||
// Update the strategy to save the user property
|
||||
_tradingService.UpdateStrategy(strategy);
|
||||
|
||||
|
||||
return strategy;
|
||||
}
|
||||
|
||||
public bool DeleteStrategiesByUser(User user)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
var strategies = GetStrategiesByUser(user);
|
||||
|
||||
var strategies = GetIndicatorsByUser(user);
|
||||
|
||||
foreach (var strategy in strategies)
|
||||
{
|
||||
_tradingService.DeleteStrategy(strategy.Name);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -294,12 +295,12 @@ namespace Managing.Application.Scenarios
|
||||
try
|
||||
{
|
||||
var scenarios = GetScenariosByUser(user);
|
||||
|
||||
|
||||
foreach (var scenario in scenarios)
|
||||
{
|
||||
_tradingService.DeleteScenario(scenario.Name);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -317,7 +318,7 @@ namespace Managing.Application.Scenarios
|
||||
return false;
|
||||
}
|
||||
|
||||
scenario.Strategies.Clear();
|
||||
scenario.Indicators.Clear();
|
||||
scenario.LoopbackPeriod = loopbackPeriod ?? 1;
|
||||
|
||||
foreach (var strategyName in strategies)
|
||||
@@ -325,7 +326,7 @@ namespace Managing.Application.Scenarios
|
||||
var strategy = _tradingService.GetStrategyByName(strategyName);
|
||||
if (strategy != null && strategy.User?.Name == user.Name)
|
||||
{
|
||||
scenario.AddStrategy(strategy);
|
||||
scenario.AddIndicator(strategy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,8 +334,8 @@ namespace Managing.Application.Scenarios
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool UpdateStrategyByUser(User user, StrategyType strategyType, string name, int? period,
|
||||
int? fastPeriods, int? slowPeriods, int? signalPeriods, double? multiplier,
|
||||
public bool UpdateIndicatorByUser(User user, IndicatorType indicatorType, string name, int? period,
|
||||
int? fastPeriods, int? slowPeriods, int? signalPeriods, double? multiplier,
|
||||
int? stochPeriods, int? smoothPeriods, int? cyclePeriods)
|
||||
{
|
||||
var strategy = _tradingService.GetStrategyByName(name);
|
||||
@@ -344,9 +345,9 @@ namespace Managing.Application.Scenarios
|
||||
}
|
||||
|
||||
// Use the existing update strategy logic
|
||||
var result = UpdateStrategy(strategyType, name, period, fastPeriods, slowPeriods,
|
||||
var result = UpdateStrategy(indicatorType, name, period, fastPeriods, slowPeriods,
|
||||
signalPeriods, multiplier, stochPeriods, smoothPeriods, cyclePeriods);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user