Update bot config on front and back

This commit is contained in:
2025-06-04 15:42:21 +07:00
parent f41af96406
commit 756cd5fb11
14 changed files with 422 additions and 369 deletions

View File

@@ -6,6 +6,7 @@ using Managing.Application.Abstractions.Services;
using Managing.Application.Backtesting;
using Managing.Application.Bots.Base;
using Managing.Core;
using Managing.Domain.Bots;
using Managing.Domain.Candles;
using Managing.Domain.MoneyManagements;
using Managing.Domain.Scenarios;
@@ -42,7 +43,7 @@ namespace Managing.Application.Tests
_tradingService.Object,
botService);
_backtester = new Backtester(_exchangeService, _botFactory, backtestRepository, backtestLogger,
scenarioService);
scenarioService, _accountService.Object);
_elapsedTimes = new List<double>();
}
@@ -58,10 +59,25 @@ namespace Managing.Application.Tests
var localCandles =
FileHelpers.ReadJson<List<Candle>>($"{ticker.ToString()}-{timeframe.ToString()}-candles.json");
var config = new TradingBotConfig
{
AccountName = _account.Name,
MoneyManagement = MoneyManagement,
Ticker = ticker,
ScenarioName = scenario.Name,
Timeframe = timeframe,
IsForWatchingOnly = false,
BotTradingBalance = 1000,
BotType = BotType.FlippingBot,
IsForBacktest = true,
CooldownPeriod = 1,
MaxLossStreak = 0,
FlipPosition = true,
Name = "Test"
};
// Act
var backtestResult = await _backtester.RunFlippingBotBacktest(_account, MoneyManagement, ticker, scenario,
timeframe, 1000, new DateTime().AddDays(-3), DateTime.UtcNow,
initialCandles: localCandles.TakeLast(500).ToList());
var backtestResult = await _backtester.RunFlippingBotBacktest(config, localCandles.TakeLast(500).ToList());
var json = JsonConvert.SerializeObject(backtestResult, Formatting.None);
File.WriteAllText($"{ticker.ToString()}-{timeframe.ToString()}-{Guid.NewGuid()}.json", json);
@@ -90,9 +106,25 @@ namespace Managing.Application.Tests
var strategy = ScenarioHelpers.BuildStrategy(StrategyType.RsiDivergence, "RsiDiv", period: 5);
scenario.AddStrategy(strategy);
var config = new TradingBotConfig
{
AccountName = _account.Name,
MoneyManagement = MoneyManagement,
Ticker = ticker,
ScenarioName = scenario.Name,
Timeframe = timeframe,
IsForWatchingOnly = false,
BotTradingBalance = 1000,
BotType = BotType.ScalpingBot,
IsForBacktest = true,
CooldownPeriod = 1,
MaxLossStreak = 0,
FlipPosition = false,
Name = "Test"
};
// Act
var backtestResult = await _backtester.RunScalpingBotBacktest(_account, MoneyManagement, ticker, scenario,
timeframe, 1000, DateTime.UtcNow.AddDays(-6), DateTime.UtcNow, null);
var backtestResult = await _backtester.RunScalpingBotBacktest(config, DateTime.UtcNow.AddDays(-6), DateTime.UtcNow, null, false, null);
//WriteCsvReport(backtestResult.GetStringReport());
// Assert
@@ -120,9 +152,25 @@ namespace Managing.Application.Tests
TakeProfit = 0.02m
};
var config = new TradingBotConfig
{
AccountName = _account.Name,
MoneyManagement = moneyManagement,
Ticker = ticker,
ScenarioName = scenario.Name,
Timeframe = timeframe,
IsForWatchingOnly = false,
BotTradingBalance = 1000,
BotType = BotType.ScalpingBot,
IsForBacktest = true,
CooldownPeriod = 1,
MaxLossStreak = 0,
FlipPosition = false,
Name = "Test"
};
// Act
var backtestResult = await _backtester.RunScalpingBotBacktest(_account, moneyManagement, ticker, scenario,
timeframe, 1000, DateTime.UtcNow.AddDays(-6), DateTime.UtcNow, null);
var backtestResult = await _backtester.RunScalpingBotBacktest(config, DateTime.UtcNow.AddDays(-6), DateTime.UtcNow, null, false, null);
WriteCsvReport(backtestResult.GetStringReport());
// Assert
@@ -191,10 +239,38 @@ namespace Managing.Application.Tests
var backtestResult = botType switch
{
BotType.SimpleBot => throw new NotImplementedException(),
BotType.ScalpingBot => _backtester.RunScalpingBotBacktest(_account, moneyManagement,
scenario, timeframe, candles, 1000, null).Result,
BotType.FlippingBot => _backtester.RunFlippingBotBacktest(_account, moneyManagement,
scenario, timeframe, candles, 1000, null).Result,
BotType.ScalpingBot => _backtester.RunScalpingBotBacktest(new TradingBotConfig
{
AccountName = _account.Name,
MoneyManagement = moneyManagement,
Ticker = ticker,
ScenarioName = scenario.Name,
Timeframe = timeframe,
IsForWatchingOnly = false,
BotTradingBalance = 1000,
BotType = BotType.ScalpingBot,
IsForBacktest = true,
CooldownPeriod = 1,
MaxLossStreak = 0,
FlipPosition = false,
Name = "Test"
}, candles, null).Result,
BotType.FlippingBot => _backtester.RunFlippingBotBacktest(new TradingBotConfig
{
AccountName = _account.Name,
MoneyManagement = moneyManagement,
Ticker = ticker,
ScenarioName = scenario.Name,
Timeframe = timeframe,
IsForWatchingOnly = false,
BotTradingBalance = 1000,
BotType = BotType.FlippingBot,
IsForBacktest = true,
CooldownPeriod = 1,
MaxLossStreak = 0,
FlipPosition = true,
Name = "Test"
}, candles, null).Result,
_ => throw new NotImplementedException(),
};
timer.Stop();
@@ -299,10 +375,38 @@ namespace Managing.Application.Tests
var backtestResult = botType switch
{
BotType.SimpleBot => throw new NotImplementedException(),
BotType.ScalpingBot => _backtester.RunScalpingBotBacktest(_account, moneyManagement,
scenario, timeframe, candles, 1000, null).Result,
BotType.FlippingBot => _backtester.RunFlippingBotBacktest(_account, moneyManagement,
scenario, timeframe, candles, 1000, null).Result,
BotType.ScalpingBot => _backtester.RunScalpingBotBacktest(new TradingBotConfig
{
AccountName = _account.Name,
MoneyManagement = moneyManagement,
Ticker = ticker,
ScenarioName = scenario.Name,
Timeframe = timeframe,
IsForWatchingOnly = false,
BotTradingBalance = 1000,
BotType = BotType.ScalpingBot,
IsForBacktest = true,
CooldownPeriod = 1,
MaxLossStreak = 0,
FlipPosition = false,
Name = "Test"
}, candles, null).Result,
BotType.FlippingBot => _backtester.RunFlippingBotBacktest(new TradingBotConfig
{
AccountName = _account.Name,
MoneyManagement = moneyManagement,
Ticker = ticker,
ScenarioName = scenario.Name,
Timeframe = timeframe,
IsForWatchingOnly = false,
BotTradingBalance = 1000,
BotType = BotType.FlippingBot,
IsForBacktest = true,
CooldownPeriod = 1,
MaxLossStreak = 0,
FlipPosition = true,
Name = "Test"
}, candles, null).Result,
_ => throw new NotImplementedException(),
};