Update bot market type

This commit is contained in:
2025-12-11 23:32:06 +07:00
parent 35df25915f
commit a254db6d24
20 changed files with 1986 additions and 44 deletions

View File

@@ -50,6 +50,10 @@ public class BacktestEntity
[Required]
public int Timeframe { get; set; }
// Stored trading type as enum numeric value for direct filtering
[Required]
public int TradingType { get; set; }
// Comma-separated indicator types for filtering, e.g., "EMA_CROSS,MACD_CROSS"
[Column(TypeName = "text")]
public string IndicatorsCsv { get; set; } = string.Empty;

View File

@@ -13,6 +13,8 @@ public class BotEntity
public Ticker Ticker { get; set; }
public TradingType TradingType { get; set; }
public int UserId { get; set; }
[ForeignKey("UserId")] public UserEntity User { get; set; }

View File

@@ -161,6 +161,7 @@ public class ManagingDbContext : DbContext
entity.Property(e => e.Name).IsRequired().HasMaxLength(255);
entity.Property(e => e.Ticker).HasMaxLength(32);
entity.Property(e => e.Timeframe).IsRequired();
entity.Property(e => e.TradingType).IsRequired();
entity.Property(e => e.IndicatorsCsv).HasColumnType("text");
entity.Property(e => e.IndicatorsCount).IsRequired();
entity.Property(e => e.PositionsJson).HasColumnType("jsonb");
@@ -522,6 +523,8 @@ public class ManagingDbContext : DbContext
entity.HasKey(e => e.Identifier);
entity.Property(e => e.Identifier).IsRequired().HasMaxLength(255);
entity.Property(e => e.Name).IsRequired().HasMaxLength(255);
entity.Property(e => e.Ticker).IsRequired().HasConversion<string>();
entity.Property(e => e.TradingType).IsRequired().HasConversion<string>();
entity.Property(e => e.Status).IsRequired().HasConversion<string>();
entity.Property(e => e.CreateDate).IsRequired();
entity.Property(e => e.StartupTime).IsRequired();

View File

@@ -438,6 +438,8 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
baseQuery = baseQuery.Where(b => b.Duration >= filter.DurationMin.Value);
if (filter.DurationMax.HasValue)
baseQuery = baseQuery.Where(b => b.Duration <= filter.DurationMax.Value);
if (filter.TradingType.HasValue)
baseQuery = baseQuery.Where(b => b.TradingType == (int)filter.TradingType.Value);
}
var entities = await baseQuery.ToListAsync().ConfigureAwait(false);
@@ -503,6 +505,8 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
baseQuery = baseQuery.Where(b => b.Duration >= filter.DurationMin.Value);
if (filter.DurationMax.HasValue)
baseQuery = baseQuery.Where(b => b.Duration <= filter.DurationMax.Value);
if (filter.TradingType.HasValue)
baseQuery = baseQuery.Where(b => b.TradingType == (int)filter.TradingType.Value);
}
var afterQueryMs = stopwatch.ElapsedMilliseconds;
@@ -642,6 +646,8 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
baseQuery = baseQuery.Where(b => b.Duration >= filter.DurationMin.Value);
if (filter.DurationMax.HasValue)
baseQuery = baseQuery.Where(b => b.Duration <= filter.DurationMax.Value);
if (filter.TradingType.HasValue)
baseQuery = baseQuery.Where(b => b.TradingType == (int)filter.TradingType.Value);
}
var afterQueryMs = stopwatch.ElapsedMilliseconds;

View File

@@ -350,6 +350,7 @@ public static class PostgreSqlMappers
Name = backtest.Config?.Name ?? string.Empty,
Ticker = backtest.Config?.Ticker.ToString() ?? string.Empty,
Timeframe = (int)backtest.Config.Timeframe,
TradingType = (int)backtest.Config.TradingType,
IndicatorsCsv = string.Join(',', backtest.Config.Scenario.Indicators.Select(i => i.Type.ToString())),
IndicatorsCount = backtest.Config.Scenario.Indicators.Count,
PositionsJson = JsonConvert.SerializeObject(backtest.Positions.Values.ToList(), jsonSettings),
@@ -750,6 +751,7 @@ public static class PostgreSqlMappers
CreateDate = entity.CreateDate,
Name = entity.Name,
Ticker = entity.Ticker,
TradingType = entity.TradingType,
StartupTime = entity.StartupTime,
LastStartTime = entity.LastStartTime,
LastStopTime = entity.LastStopTime,
@@ -782,6 +784,7 @@ public static class PostgreSqlMappers
CreateDate = bot.CreateDate,
Name = bot.Name,
Ticker = bot.Ticker,
TradingType = bot.TradingType,
StartupTime = bot.StartupTime,
LastStartTime = bot.LastStartTime,
LastStopTime = bot.LastStopTime,