Rename strategy to indicators
This commit is contained in:
@@ -9,12 +9,12 @@ namespace Managing.Application.Abstractions
|
||||
{
|
||||
IEnumerable<Scenario> GetScenarios();
|
||||
Scenario CreateScenario(string name, List<string> strategies, int? loopbackPeriod = 1);
|
||||
IEnumerable<Strategy> GetStrategies();
|
||||
IEnumerable<Indicator> GetStrategies();
|
||||
bool DeleteStrategy(string name);
|
||||
bool DeleteScenario(string name);
|
||||
Scenario GetScenario(string name);
|
||||
|
||||
Strategy CreateStrategy(StrategyType type,
|
||||
Indicator CreateStrategy(IndicatorType type,
|
||||
string name,
|
||||
int? period = null,
|
||||
int? fastPeriods = null,
|
||||
@@ -29,18 +29,18 @@ namespace Managing.Application.Abstractions
|
||||
bool DeleteScenarios();
|
||||
bool UpdateScenario(string name, List<string> strategies, int? loopbackPeriod);
|
||||
|
||||
bool UpdateStrategy(StrategyType strategyType, string name, int? period, int? fastPeriods, int? slowPeriods,
|
||||
bool UpdateStrategy(IndicatorType indicatorType, string name, int? period, int? fastPeriods, int? slowPeriods,
|
||||
int? signalPeriods, double? multiplier, int? stochPeriods, int? smoothPeriods, int? cyclePeriods);
|
||||
|
||||
IEnumerable<Scenario> GetScenariosByUser(User user);
|
||||
Scenario CreateScenarioForUser(User user, string name, List<string> strategies, int? loopbackPeriod = 1);
|
||||
IEnumerable<Strategy> GetStrategiesByUser(User user);
|
||||
bool DeleteStrategyByUser(User user, string name);
|
||||
IEnumerable<Indicator> GetIndicatorsByUser(User user);
|
||||
bool DeleteIndicatorByUser(User user, string name);
|
||||
bool DeleteScenarioByUser(User user, string name);
|
||||
Scenario GetScenarioByUser(User user, string name);
|
||||
|
||||
Strategy CreateStrategyForUser(User user,
|
||||
StrategyType type,
|
||||
|
||||
Indicator CreateIndicatorForUser(User user,
|
||||
IndicatorType type,
|
||||
string name,
|
||||
int? period = null,
|
||||
int? fastPeriods = null,
|
||||
@@ -50,12 +50,13 @@ namespace Managing.Application.Abstractions
|
||||
int? stochPeriods = null,
|
||||
int? smoothPeriods = null,
|
||||
int? cyclePeriods = null);
|
||||
|
||||
|
||||
bool DeleteStrategiesByUser(User user);
|
||||
bool DeleteScenariosByUser(User user);
|
||||
bool UpdateScenarioByUser(User user, string name, List<string> strategies, int? loopbackPeriod);
|
||||
|
||||
bool UpdateStrategyByUser(User user, StrategyType strategyType, string name, int? period, int? fastPeriods,
|
||||
int? slowPeriods, int? signalPeriods, double? multiplier, int? stochPeriods, int? smoothPeriods, int? cyclePeriods);
|
||||
|
||||
bool UpdateIndicatorByUser(User user, IndicatorType indicatorType, string name, int? period, int? fastPeriods,
|
||||
int? slowPeriods, int? signalPeriods, double? multiplier, int? stochPeriods, int? smoothPeriods,
|
||||
int? cyclePeriods);
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,13 @@ namespace Managing.Application.Abstractions
|
||||
{
|
||||
TradingBotConfig Config { get; set; }
|
||||
Account Account { get; set; }
|
||||
HashSet<IStrategy> Strategies { get; set; }
|
||||
HashSet<IIndicator> Indicators { get; set; }
|
||||
FixedSizeQueue<Candle> OptimizedCandles { get; set; }
|
||||
HashSet<Candle> Candles { get; set; }
|
||||
HashSet<Signal> Signals { get; set; }
|
||||
List<Position> Positions { get; set; }
|
||||
Dictionary<DateTime, decimal> WalletBalances { get; set; }
|
||||
Dictionary<StrategyType, StrategiesResultBase> StrategiesValues { get; set; }
|
||||
Dictionary<IndicatorType, IndicatorsResultBase> IndicatorsValues { get; set; }
|
||||
DateTime StartupTime { get; set; }
|
||||
DateTime PreloadSince { get; set; }
|
||||
int PreloadedCandlesCount { get; set; }
|
||||
@@ -32,10 +32,10 @@ namespace Managing.Application.Abstractions
|
||||
int GetWinRate();
|
||||
decimal GetProfitAndLoss();
|
||||
decimal GetTotalFees();
|
||||
void LoadStrategies(IEnumerable<IStrategy> strategies);
|
||||
void LoadIndicators(IEnumerable<IIndicator> indicators);
|
||||
void LoadScenario(string scenarioName);
|
||||
void LoadScenario(Scenario scenario);
|
||||
void UpdateStrategiesValues();
|
||||
void UpdateIndicatorsValues();
|
||||
Task LoadAccount();
|
||||
Task<Position> OpenPositionManually(TradeDirection direction);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Managing.Application.Backtesting
|
||||
IExchangeService exchangeService,
|
||||
IBotFactory botFactory,
|
||||
IBacktestRepository backtestRepository,
|
||||
ILogger<Backtester> logger,
|
||||
ILogger<Backtester> logger,
|
||||
IScenarioService scenarioService,
|
||||
IAccountService accountService)
|
||||
{
|
||||
@@ -74,9 +74,9 @@ namespace Managing.Application.Backtesting
|
||||
{
|
||||
var account = await GetAccountFromConfig(config);
|
||||
var candles = GetCandles(account, config.Ticker, config.Timeframe, startDate, endDate);
|
||||
|
||||
|
||||
var result = await RunBacktestWithCandles(config, candles, user);
|
||||
|
||||
|
||||
// Set start and end dates
|
||||
result.StartDate = startDate;
|
||||
result.EndDate = endDate;
|
||||
@@ -115,9 +115,9 @@ namespace Managing.Application.Backtesting
|
||||
{
|
||||
// Set FlipPosition based on BotType
|
||||
config.FlipPosition = config.BotType == BotType.FlippingBot;
|
||||
|
||||
|
||||
var tradingBot = _botFactory.CreateBacktestTradingBot(config);
|
||||
|
||||
|
||||
// Load scenario - prefer Scenario object over ScenarioName
|
||||
if (config.Scenario != null)
|
||||
{
|
||||
@@ -129,9 +129,10 @@ namespace Managing.Application.Backtesting
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Either Scenario object or ScenarioName must be provided in TradingBotConfig");
|
||||
throw new ArgumentException(
|
||||
"Either Scenario object or ScenarioName must be provided in TradingBotConfig");
|
||||
}
|
||||
|
||||
|
||||
tradingBot.User = user;
|
||||
await tradingBot.LoadAccount();
|
||||
|
||||
@@ -153,9 +154,9 @@ namespace Managing.Application.Backtesting
|
||||
return account;
|
||||
}
|
||||
|
||||
return new Account
|
||||
{
|
||||
Name = config.AccountName,
|
||||
return new Account
|
||||
{
|
||||
Name = config.AccountName,
|
||||
Exchange = TradingExchanges.GmxV2
|
||||
};
|
||||
}
|
||||
@@ -191,7 +192,7 @@ namespace Managing.Application.Backtesting
|
||||
}
|
||||
|
||||
bot.Candles = new HashSet<Candle>(candles);
|
||||
bot.UpdateStrategiesValues();
|
||||
bot.UpdateIndicatorsValues();
|
||||
|
||||
var strategies = _scenarioService.GetStrategies();
|
||||
var strategiesValues = GetStrategiesValues(strategies, candles);
|
||||
@@ -228,21 +229,21 @@ namespace Managing.Application.Backtesting
|
||||
WalletBalances = bot.WalletBalances.ToList(),
|
||||
Statistics = stats,
|
||||
OptimizedMoneyManagement = optimizedMoneyManagement,
|
||||
StrategiesValues = AggregateValues(strategiesValues, bot.StrategiesValues),
|
||||
StrategiesValues = AggregateValues(strategiesValues, bot.IndicatorsValues),
|
||||
Score = score
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Dictionary<StrategyType, StrategiesResultBase> AggregateValues(
|
||||
Dictionary<StrategyType, StrategiesResultBase> strategiesValues,
|
||||
Dictionary<StrategyType, StrategiesResultBase> botStrategiesValues)
|
||||
private Dictionary<IndicatorType, IndicatorsResultBase> AggregateValues(
|
||||
Dictionary<IndicatorType, IndicatorsResultBase> strategiesValues,
|
||||
Dictionary<IndicatorType, IndicatorsResultBase> botStrategiesValues)
|
||||
{
|
||||
// Foreach strategy type, only retrieve the values where the strategy is not present already in the bot
|
||||
// Then, add the values to the bot values
|
||||
|
||||
var result = new Dictionary<StrategyType, StrategiesResultBase>();
|
||||
var result = new Dictionary<IndicatorType, IndicatorsResultBase>();
|
||||
foreach (var strategy in strategiesValues)
|
||||
{
|
||||
// if (!botStrategiesValues.ContainsKey(strategy.Key))
|
||||
@@ -259,10 +260,10 @@ namespace Managing.Application.Backtesting
|
||||
return result;
|
||||
}
|
||||
|
||||
private Dictionary<StrategyType, StrategiesResultBase> GetStrategiesValues(IEnumerable<Strategy> strategies,
|
||||
private Dictionary<IndicatorType, IndicatorsResultBase> GetStrategiesValues(IEnumerable<Indicator> strategies,
|
||||
List<Candle> candles)
|
||||
{
|
||||
var strategiesValues = new Dictionary<StrategyType, StrategiesResultBase>();
|
||||
var strategiesValues = new Dictionary<IndicatorType, IndicatorsResultBase>();
|
||||
var fixedCandles = new FixedSizeQueue<Candle>(10000);
|
||||
foreach (var candle in candles)
|
||||
{
|
||||
@@ -273,7 +274,7 @@ namespace Managing.Application.Backtesting
|
||||
{
|
||||
try
|
||||
{
|
||||
var s = ScenarioHelpers.BuildStrategy(strategy, 10000);
|
||||
var s = ScenarioHelpers.BuildIndicator(strategy, 10000);
|
||||
s.Candles = fixedCandles;
|
||||
strategiesValues[strategy.Type] = s.GetStrategyValues();
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ public class TradingBot : Bot, ITradingBot
|
||||
|
||||
public TradingBotConfig Config { get; set; }
|
||||
public Account Account { get; set; }
|
||||
public HashSet<IStrategy> Strategies { get; set; }
|
||||
public HashSet<IIndicator> Indicators { get; set; }
|
||||
public FixedSizeQueue<Candle> OptimizedCandles { get; set; }
|
||||
public HashSet<Candle> Candles { get; set; }
|
||||
public HashSet<Signal> Signals { get; set; }
|
||||
public List<Position> Positions { get; set; }
|
||||
public Dictionary<DateTime, decimal> WalletBalances { get; set; }
|
||||
public Dictionary<StrategyType, StrategiesResultBase> StrategiesValues { get; set; }
|
||||
public Dictionary<IndicatorType, IndicatorsResultBase> IndicatorsValues { get; set; }
|
||||
public DateTime StartupTime { get; set; }
|
||||
public DateTime PreloadSince { get; set; }
|
||||
public int PreloadedCandlesCount { get; set; }
|
||||
@@ -71,13 +71,13 @@ public class TradingBot : Bot, ITradingBot
|
||||
|
||||
Config = config;
|
||||
|
||||
Strategies = new HashSet<IStrategy>();
|
||||
Indicators = new HashSet<IIndicator>();
|
||||
Signals = new HashSet<Signal>();
|
||||
OptimizedCandles = new FixedSizeQueue<Candle>(600);
|
||||
Candles = new HashSet<Candle>();
|
||||
Positions = new List<Position>();
|
||||
WalletBalances = new Dictionary<DateTime, decimal>();
|
||||
StrategiesValues = new Dictionary<StrategyType, StrategiesResultBase>();
|
||||
IndicatorsValues = new Dictionary<IndicatorType, IndicatorsResultBase>();
|
||||
|
||||
if (!Config.IsForBacktest)
|
||||
{
|
||||
@@ -141,7 +141,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
else
|
||||
{
|
||||
Scenario = scenario;
|
||||
LoadStrategies(ScenarioHelpers.GetStrategiesFromScenario(scenario));
|
||||
LoadIndicators(ScenarioHelpers.GetIndicatorsFromScenario(scenario));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,15 +155,15 @@ public class TradingBot : Bot, ITradingBot
|
||||
else
|
||||
{
|
||||
Scenario = scenario;
|
||||
LoadStrategies(ScenarioHelpers.GetStrategiesFromScenario(scenario));
|
||||
LoadIndicators(ScenarioHelpers.GetIndicatorsFromScenario(scenario));
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadStrategies(IEnumerable<IStrategy> strategies)
|
||||
public void LoadIndicators(IEnumerable<IIndicator> indicators)
|
||||
{
|
||||
foreach (var strategy in strategies)
|
||||
foreach (var strategy in indicators)
|
||||
{
|
||||
Strategies.Add(strategy);
|
||||
Indicators.Add(strategy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
if (!Config.IsForBacktest)
|
||||
{
|
||||
SaveBackup();
|
||||
UpdateStrategiesValues();
|
||||
UpdateIndicatorsValues();
|
||||
}
|
||||
|
||||
UpdateWalletBalances();
|
||||
@@ -219,11 +219,11 @@ public class TradingBot : Bot, ITradingBot
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateStrategiesValues()
|
||||
public void UpdateIndicatorsValues()
|
||||
{
|
||||
foreach (var strategy in Strategies)
|
||||
foreach (var strategy in Indicators)
|
||||
{
|
||||
StrategiesValues[strategy.Type] = ((Strategy)strategy).GetStrategyValues();
|
||||
IndicatorsValues[strategy.Type] = ((Indicator)strategy).GetStrategyValues();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
|
||||
private async Task UpdateSignals(FixedSizeQueue<Candle> candles)
|
||||
{
|
||||
var signal = TradingBox.GetSignal(candles.ToHashSet(), Strategies, Signals, Scenario.LoopbackPeriod);
|
||||
var signal = TradingBox.GetSignal(candles.ToHashSet(), Indicators, Signals, Scenario.LoopbackPeriod);
|
||||
if (signal == null) return;
|
||||
|
||||
signal.User = Account.User;
|
||||
@@ -325,7 +325,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
candle: positionCandle,
|
||||
date: position.Open.Date,
|
||||
exchange: Account.Exchange,
|
||||
strategyType: StrategyType.Stc, // Use a valid strategy type for recreated signals
|
||||
indicatorType: IndicatorType.Stc, // Use a valid strategy type for recreated signals
|
||||
signalType: SignalType.Signal
|
||||
);
|
||||
|
||||
@@ -1311,7 +1311,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
// Create a fake signal for manual position opening
|
||||
var signal = new Signal(Config.Ticker, direction, Confidence.Low, lastCandle, lastCandle.Date,
|
||||
TradingExchanges.GmxV2,
|
||||
StrategyType.Stc, SignalType.Signal);
|
||||
IndicatorType.Stc, SignalType.Signal);
|
||||
signal.Status = SignalStatus.WaitingForPosition; // Ensure status is correct
|
||||
signal.User = Account.User; // Assign user
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class SettingsService : ISettingsService
|
||||
private void SetupStochSTCTrend()
|
||||
{
|
||||
var name = "STCTrend";
|
||||
var strategy = _scenarioService.CreateStrategy(StrategyType.Stc,
|
||||
var strategy = _scenarioService.CreateStrategy(IndicatorType.Stc,
|
||||
name,
|
||||
fastPeriods: 23,
|
||||
slowPeriods: 50,
|
||||
@@ -112,7 +112,7 @@ public class SettingsService : ISettingsService
|
||||
private void SetupMacd()
|
||||
{
|
||||
var name = "MacdCross";
|
||||
var strategy = _scenarioService.CreateStrategy(StrategyType.MacdCross,
|
||||
var strategy = _scenarioService.CreateStrategy(IndicatorType.MacdCross,
|
||||
name,
|
||||
fastPeriods: 12,
|
||||
slowPeriods: 26,
|
||||
@@ -123,7 +123,7 @@ public class SettingsService : ISettingsService
|
||||
private void SetupRsiDiv()
|
||||
{
|
||||
var name = "RsiDiv6";
|
||||
var strategy = _scenarioService.CreateStrategy(StrategyType.RsiDivergence,
|
||||
var strategy = _scenarioService.CreateStrategy(IndicatorType.RsiDivergence,
|
||||
name,
|
||||
period: 6);
|
||||
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
|
||||
@@ -132,7 +132,7 @@ public class SettingsService : ISettingsService
|
||||
private void SetupRsiDivConfirm()
|
||||
{
|
||||
var name = "RsiDivConfirm6";
|
||||
var strategy = _scenarioService.CreateStrategy(StrategyType.RsiDivergenceConfirm,
|
||||
var strategy = _scenarioService.CreateStrategy(IndicatorType.RsiDivergenceConfirm,
|
||||
name,
|
||||
period: 6);
|
||||
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
|
||||
@@ -141,7 +141,7 @@ public class SettingsService : ISettingsService
|
||||
private void SetupSuperTrend()
|
||||
{
|
||||
var name = "SuperTrend";
|
||||
var strategy = _scenarioService.CreateStrategy(StrategyType.SuperTrend,
|
||||
var strategy = _scenarioService.CreateStrategy(IndicatorType.SuperTrend,
|
||||
name,
|
||||
period: 10,
|
||||
multiplier: 3);
|
||||
@@ -151,7 +151,7 @@ public class SettingsService : ISettingsService
|
||||
private void SetupChandelierExit()
|
||||
{
|
||||
var name = "ChandelierExit";
|
||||
var strategy = _scenarioService.CreateStrategy(StrategyType.ChandelierExit,
|
||||
var strategy = _scenarioService.CreateStrategy(IndicatorType.ChandelierExit,
|
||||
name,
|
||||
period: 22,
|
||||
multiplier: 3);
|
||||
@@ -161,7 +161,7 @@ public class SettingsService : ISettingsService
|
||||
private void SetupStochRsiTrend()
|
||||
{
|
||||
var name = "StochRsiTrend";
|
||||
var strategy = _scenarioService.CreateStrategy(StrategyType.StochRsiTrend,
|
||||
var strategy = _scenarioService.CreateStrategy(IndicatorType.StochRsiTrend,
|
||||
name,
|
||||
period: 14,
|
||||
stochPeriods: 14,
|
||||
@@ -173,7 +173,7 @@ public class SettingsService : ISettingsService
|
||||
private void SetupEmaTrend()
|
||||
{
|
||||
var name = "Ema200Trend";
|
||||
var strategy = _scenarioService.CreateStrategy(StrategyType.EmaTrend,
|
||||
var strategy = _scenarioService.CreateStrategy(IndicatorType.EmaTrend,
|
||||
name,
|
||||
period: 200);
|
||||
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
|
||||
@@ -182,7 +182,7 @@ public class SettingsService : ISettingsService
|
||||
private void SetupEmaCross()
|
||||
{
|
||||
var name = "Ema200Cross";
|
||||
var strategy = _scenarioService.CreateStrategy(StrategyType.EmaCross,
|
||||
var strategy = _scenarioService.CreateStrategy(IndicatorType.EmaCross,
|
||||
name,
|
||||
period: 200);
|
||||
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
|
||||
@@ -212,9 +212,9 @@ public class SettingsService : ISettingsService
|
||||
await _moneyManagementService.CreateOrUpdateMoneyManagement(user, defaultMoneyManagement);
|
||||
|
||||
// Create default Strategy (StcTrend)
|
||||
var defaultStrategy = _scenarioService.CreateStrategyForUser(
|
||||
var defaultStrategy = _scenarioService.CreateIndicatorForUser(
|
||||
user,
|
||||
StrategyType.Stc,
|
||||
IndicatorType.Stc,
|
||||
"Stc",
|
||||
period: null,
|
||||
fastPeriods: 23,
|
||||
|
||||
@@ -55,12 +55,12 @@ public class TradingService : ITradingService
|
||||
|
||||
public void DeleteStrategies()
|
||||
{
|
||||
_tradingRepository.DeleteStrategies();
|
||||
_tradingRepository.DeleteIndicators();
|
||||
}
|
||||
|
||||
public void DeleteStrategy(string name)
|
||||
{
|
||||
_tradingRepository.DeleteStrategy(name);
|
||||
_tradingRepository.DeleteIndicator(name);
|
||||
}
|
||||
|
||||
public Position GetPositionByIdentifier(string identifier)
|
||||
@@ -89,12 +89,12 @@ public class TradingService : ITradingService
|
||||
return _tradingRepository.GetScenarios();
|
||||
}
|
||||
|
||||
public IEnumerable<Strategy> GetStrategies()
|
||||
public IEnumerable<Indicator> GetStrategies()
|
||||
{
|
||||
return _tradingRepository.GetStrategies();
|
||||
return _tradingRepository.GetIndicators();
|
||||
}
|
||||
|
||||
public Strategy GetStrategyByName(string strategy)
|
||||
public Indicator GetStrategyByName(string strategy)
|
||||
{
|
||||
return _tradingRepository.GetStrategyByName(strategy);
|
||||
}
|
||||
@@ -114,9 +114,9 @@ public class TradingService : ITradingService
|
||||
_tradingRepository.InsertSignal(signal);
|
||||
}
|
||||
|
||||
public void InsertStrategy(Strategy strategy)
|
||||
public void InsertStrategy(Indicator indicator)
|
||||
{
|
||||
_tradingRepository.InsertStrategy(strategy);
|
||||
_tradingRepository.InsertStrategy(indicator);
|
||||
}
|
||||
|
||||
public async Task<Position> ManagePosition(Account account, Position position)
|
||||
@@ -276,9 +276,9 @@ public class TradingService : ITradingService
|
||||
_tradingRepository.UpdateScenario(scenario);
|
||||
}
|
||||
|
||||
public void UpdateStrategy(Strategy strategy)
|
||||
public void UpdateStrategy(Indicator indicator)
|
||||
{
|
||||
_tradingRepository.UpdateStrategy(strategy);
|
||||
_tradingRepository.UpdateStrategy(indicator);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Position>> GetBrokerPositions(Account account)
|
||||
@@ -385,7 +385,8 @@ public class TradingService : ITradingService
|
||||
if (string.IsNullOrEmpty(publicAddress))
|
||||
{
|
||||
_logger.LogWarning("Attempted to initialize Privy wallet with null or empty public address");
|
||||
return new PrivyInitAddressResponse { Success = false, Error = "Public address cannot be null or empty" };
|
||||
return new PrivyInitAddressResponse
|
||||
{ Success = false, Error = "Public address cannot be null or empty" };
|
||||
}
|
||||
|
||||
return await _evmManager.InitAddress(publicAddress);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class RsiDiv : FlowBase
|
||||
MapParameters();
|
||||
var candles = JsonConvert.DeserializeObject<HashSet<Candle>>(input);
|
||||
|
||||
var strategy = new RsiDivergenceStrategy(Name, RsiDivParameters.Period);
|
||||
var strategy = new RsiDivergenceIndicator(Name, RsiDivParameters.Period);
|
||||
strategy.UpdateCandles(candles);
|
||||
strategy.Run();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user