Add min and max balance filters to bot management
- Introduced optional parameters for minimum and maximum BotTradingBalance in BotController, DataController, and related services. - Updated interfaces and repository methods to support filtering by BotTradingBalance. - Enhanced TradingBotResponse and BotEntity models to include BotTradingBalance property. - Adjusted database schema to accommodate new BotTradingBalance field. - Ensured proper mapping and handling of BotTradingBalance in PostgreSQL repository and mappers.
This commit is contained in:
1791
src/Managing.Infrastructure.Database/Migrations/20260101142151_AddBotTradingBalanceToBots.Designer.cs
generated
Normal file
1791
src/Managing.Infrastructure.Database/Migrations/20260101142151_AddBotTradingBalanceToBots.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 AddBotTradingBalanceToBots : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<decimal>(
|
||||
name: "BotTradingBalance",
|
||||
table: "Bots",
|
||||
type: "numeric",
|
||||
nullable: false,
|
||||
defaultValue: 0m);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "BotTradingBalance",
|
||||
table: "Bots");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -305,6 +305,9 @@ namespace Managing.Infrastructure.Databases.Migrations
|
||||
b.Property<long>("AccumulatedRunTimeSeconds")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<decimal>("BotTradingBalance")
|
||||
.HasColumnType("numeric");
|
||||
|
||||
b.Property<DateTime>("CreateDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ public class BotEntity
|
||||
public decimal Fees { get; set; }
|
||||
public int LongPositionCount { get; set; }
|
||||
public int ShortPositionCount { get; set; }
|
||||
|
||||
public decimal BotTradingBalance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user ID of the master bot's owner when this bot is for copy trading
|
||||
|
||||
@@ -205,6 +205,8 @@ public class PostgreSqlBotRepository : IBotRepository
|
||||
string? name = null,
|
||||
string? ticker = null,
|
||||
string? agentName = null,
|
||||
decimal? minBalance = null,
|
||||
decimal? maxBalance = null,
|
||||
BotSortableColumn sortBy = BotSortableColumn.CreateDate,
|
||||
SortDirection sortDirection = SortDirection.Desc,
|
||||
bool showOnlyProfitable = false)
|
||||
@@ -237,6 +239,17 @@ public class PostgreSqlBotRepository : IBotRepository
|
||||
query = query.Where(b => b.User != null && EF.Functions.ILike(b.User.AgentName, $"%{agentName}%"));
|
||||
}
|
||||
|
||||
// Apply balance filtering if specified
|
||||
if (minBalance.HasValue)
|
||||
{
|
||||
query = query.Where(b => b.BotTradingBalance >= minBalance.Value);
|
||||
}
|
||||
|
||||
if (maxBalance.HasValue)
|
||||
{
|
||||
query = query.Where(b => b.BotTradingBalance <= maxBalance.Value);
|
||||
}
|
||||
|
||||
// Apply profitable bots filtering if specified
|
||||
if (showOnlyProfitable)
|
||||
{
|
||||
@@ -275,6 +288,9 @@ public class PostgreSqlBotRepository : IBotRepository
|
||||
BotSortableColumn.AgentName => sortDirection == SortDirection.Asc
|
||||
? query.OrderBy(b => b.User.AgentName)
|
||||
: query.OrderByDescending(b => b.User.AgentName),
|
||||
BotSortableColumn.BotTradingBalance => sortDirection == SortDirection.Asc
|
||||
? query.OrderBy(b => b.BotTradingBalance)
|
||||
: query.OrderByDescending(b => b.BotTradingBalance),
|
||||
_ => sortDirection == SortDirection.Asc
|
||||
? query.OrderBy(b => b.CreateDate)
|
||||
: query.OrderByDescending(b => b.CreateDate)
|
||||
|
||||
@@ -793,6 +793,7 @@ public static class PostgreSqlMappers
|
||||
Fees = entity.Fees,
|
||||
LongPositionCount = entity.LongPositionCount,
|
||||
ShortPositionCount = entity.ShortPositionCount,
|
||||
BotTradingBalance = entity.BotTradingBalance,
|
||||
MasterBotUserId = entity.MasterBotUserId,
|
||||
MasterBotUser = entity.MasterBotUser != null ? Map(entity.MasterBotUser) : null
|
||||
};
|
||||
@@ -826,6 +827,7 @@ public static class PostgreSqlMappers
|
||||
Fees = bot.Fees,
|
||||
LongPositionCount = bot.LongPositionCount,
|
||||
ShortPositionCount = bot.ShortPositionCount,
|
||||
BotTradingBalance = bot.BotTradingBalance,
|
||||
MasterBotUserId = bot.MasterBotUserId,
|
||||
UpdatedAt = DateTime.UtcNow
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user