Add PositionCount property to Backtest models and responses
- Introduced PositionCount to Backtest, LightBacktest, and their respective response models. - Updated BacktestController and BacktestExecutor to include PositionCount in responses. - Modified database schema to accommodate new PositionCount field in relevant entities.
This commit is contained in:
@@ -316,7 +316,8 @@ public class BacktestController : BaseController
|
||||
Score = b.Score,
|
||||
ScoreMessage = b.ScoreMessage,
|
||||
InitialBalance = b.InitialBalance,
|
||||
NetPnl = b.NetPnl
|
||||
NetPnl = b.NetPnl,
|
||||
PositionCount = b.PositionCount
|
||||
}),
|
||||
TotalCount = totalCount,
|
||||
CurrentPage = page,
|
||||
@@ -457,7 +458,8 @@ public class BacktestController : BaseController
|
||||
Score = b.Score,
|
||||
ScoreMessage = b.ScoreMessage,
|
||||
InitialBalance = b.InitialBalance,
|
||||
NetPnl = b.NetPnl
|
||||
NetPnl = b.NetPnl,
|
||||
PositionCount = b.PositionCount
|
||||
}),
|
||||
TotalCount = totalCount,
|
||||
CurrentPage = page,
|
||||
|
||||
@@ -22,6 +22,7 @@ public class LightBacktestResponse
|
||||
[Required] public string ScoreMessage { get; set; } = string.Empty;
|
||||
[Required] public decimal InitialBalance { get; set; }
|
||||
[Required] public decimal NetPnl { get; set; }
|
||||
[Required] public int PositionCount { get; set; }
|
||||
}
|
||||
|
||||
public static class LightBacktestResponseMapper
|
||||
@@ -45,7 +46,8 @@ public static class LightBacktestResponseMapper
|
||||
Score = b.Score,
|
||||
ScoreMessage = b.ScoreMessage,
|
||||
InitialBalance = b.InitialBalance,
|
||||
NetPnl = b.NetPnl
|
||||
NetPnl = b.NetPnl,
|
||||
PositionCount = b.PositionCount
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -410,6 +410,7 @@ public class BacktestExecutor
|
||||
EndDate = candles.LastOrDefault()!.OpenTime,
|
||||
InitialBalance = initialBalance,
|
||||
NetPnl = netPnl, // Net PnL after fees
|
||||
PositionCount = tradingBot.Positions.Count,
|
||||
};
|
||||
|
||||
if (save && user != null)
|
||||
@@ -526,7 +527,8 @@ public class BacktestExecutor
|
||||
Score = backtest.Score,
|
||||
ScoreMessage = backtest.ScoreMessage,
|
||||
InitialBalance = backtest.InitialBalance,
|
||||
NetPnl = backtest.NetPnl
|
||||
NetPnl = backtest.NetPnl,
|
||||
PositionCount = backtest.PositionCount
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ public class Backtest
|
||||
public string ScoreMessage { get; set; } = string.Empty;
|
||||
[Required] public decimal InitialBalance { get; set; }
|
||||
[Required] public decimal NetPnl { get; set; }
|
||||
[Required] public int PositionCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new TradingBotConfig based on this backtest's configuration for starting a live bot.
|
||||
|
||||
@@ -27,4 +27,5 @@ public class LightBacktest
|
||||
[Id(14)] public string Ticker { get; set; } = string.Empty;
|
||||
[Id(15)] public decimal InitialBalance { get; set; }
|
||||
[Id(16)] public decimal NetPnl { get; set; }
|
||||
[Id(17)] public int PositionCount { get; set; }
|
||||
}
|
||||
1729
src/Managing.Infrastructure.Database/Migrations/20251118131323_AddPositionCountToBacktests.Designer.cs
generated
Normal file
1729
src/Managing.Infrastructure.Database/Migrations/20251118131323_AddPositionCountToBacktests.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Managing.Infrastructure.Databases.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddPositionCountToBacktests : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "PositionCount",
|
||||
table: "Backtests",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "PositionCount",
|
||||
table: "Backtests");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,6 +217,9 @@ namespace Managing.Infrastructure.Databases.Migrations
|
||||
b.Property<decimal>("NetPnl")
|
||||
.HasColumnType("decimal(18,8)");
|
||||
|
||||
b.Property<int>("PositionCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("PositionsJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb");
|
||||
|
||||
@@ -128,4 +128,7 @@ public class BacktestEntity
|
||||
[Required]
|
||||
[Column(TypeName = "decimal(18,8)")]
|
||||
public decimal NetPnl { get; set; }
|
||||
|
||||
[Required]
|
||||
public int PositionCount { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user