Enhance user settings management by adding new properties and updating related functionality
This commit introduces additional user settings properties, including TrendStrongAgreementThreshold, SignalAgreementThreshold, AllowSignalTrendOverride, and DefaultExchange, to the User entity and associated DTOs. The UserController and UserService are updated to handle these new settings, allowing users to customize their trading configurations more effectively. Database migrations are also included to ensure proper schema updates for the new fields.
This commit is contained in:
@@ -14,7 +14,8 @@ namespace Managing.Infrastructure.Databases.Migrations
|
||||
name: "AutoswapAmount",
|
||||
table: "Users",
|
||||
type: "numeric(18,8)",
|
||||
nullable: true);
|
||||
nullable: true,
|
||||
defaultValue: 3m);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "EnableAutoswap",
|
||||
@@ -34,25 +35,29 @@ namespace Managing.Infrastructure.Databases.Migrations
|
||||
name: "LowEthAmountAlert",
|
||||
table: "Users",
|
||||
type: "numeric(18,8)",
|
||||
nullable: true);
|
||||
nullable: true,
|
||||
defaultValue: 1.5m);
|
||||
|
||||
migrationBuilder.AddColumn<decimal>(
|
||||
name: "MaxTxnGasFeePerPosition",
|
||||
table: "Users",
|
||||
type: "numeric(18,8)",
|
||||
nullable: true);
|
||||
nullable: true,
|
||||
defaultValue: 1.5m);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxWaitingTimeForPositionToGetFilledSeconds",
|
||||
table: "Users",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
nullable: true,
|
||||
defaultValue: 600);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "MinimumConfidence",
|
||||
table: "Users",
|
||||
type: "text",
|
||||
nullable: true);
|
||||
nullable: true,
|
||||
defaultValue: "Medium");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
1773
src/Managing.Infrastructure.Database/Migrations/20251229225934_SetUserSettingsDefaults.Designer.cs
generated
Normal file
1773
src/Managing.Infrastructure.Database/Migrations/20251229225934_SetUserSettingsDefaults.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,116 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Managing.Infrastructure.Databases.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class SetUserSettingsDefaults : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Set default values for existing NULL values
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""LowEthAmountAlert"" = 1.5
|
||||
WHERE ""LowEthAmountAlert"" IS NULL;
|
||||
");
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""AutoswapAmount"" = 3
|
||||
WHERE ""AutoswapAmount"" IS NULL;
|
||||
");
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""MaxWaitingTimeForPositionToGetFilledSeconds"" = 600
|
||||
WHERE ""MaxWaitingTimeForPositionToGetFilledSeconds"" IS NULL;
|
||||
");
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""MaxTxnGasFeePerPosition"" = 1.5
|
||||
WHERE ""MaxTxnGasFeePerPosition"" IS NULL;
|
||||
");
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""MinimumConfidence"" = 'Medium'
|
||||
WHERE ""MinimumConfidence"" IS NULL;
|
||||
");
|
||||
|
||||
// Alter columns to set default values for future inserts
|
||||
migrationBuilder.AlterColumn<decimal>(
|
||||
name: "LowEthAmountAlert",
|
||||
table: "Users",
|
||||
type: "numeric(18,8)",
|
||||
nullable: true,
|
||||
defaultValue: 1.5m);
|
||||
|
||||
migrationBuilder.AlterColumn<decimal>(
|
||||
name: "AutoswapAmount",
|
||||
table: "Users",
|
||||
type: "numeric(18,8)",
|
||||
nullable: true,
|
||||
defaultValue: 3m);
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "MaxWaitingTimeForPositionToGetFilledSeconds",
|
||||
table: "Users",
|
||||
type: "integer",
|
||||
nullable: true,
|
||||
defaultValue: 600);
|
||||
|
||||
migrationBuilder.AlterColumn<decimal>(
|
||||
name: "MaxTxnGasFeePerPosition",
|
||||
table: "Users",
|
||||
type: "numeric(18,8)",
|
||||
nullable: true,
|
||||
defaultValue: 1.5m);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "MinimumConfidence",
|
||||
table: "Users",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
defaultValue: "Medium");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Remove default values (revert to nullable without defaults)
|
||||
migrationBuilder.AlterColumn<decimal>(
|
||||
name: "LowEthAmountAlert",
|
||||
table: "Users",
|
||||
type: "numeric(18,8)",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<decimal>(
|
||||
name: "AutoswapAmount",
|
||||
table: "Users",
|
||||
type: "numeric(18,8)",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "MaxWaitingTimeForPositionToGetFilledSeconds",
|
||||
table: "Users",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<decimal>(
|
||||
name: "MaxTxnGasFeePerPosition",
|
||||
table: "Users",
|
||||
type: "numeric(18,8)",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "MinimumConfidence",
|
||||
table: "Users",
|
||||
type: "text",
|
||||
nullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
1785
src/Managing.Infrastructure.Database/Migrations/20251229231215_AddIndicatorComboConfigSettings.Designer.cs
generated
Normal file
1785
src/Managing.Infrastructure.Database/Migrations/20251229231215_AddIndicatorComboConfigSettings.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Managing.Infrastructure.Databases.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddIndicatorComboConfigSettings : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Add columns with defaults
|
||||
migrationBuilder.AddColumn<decimal>(
|
||||
name: "TrendStrongAgreementThreshold",
|
||||
table: "Users",
|
||||
type: "numeric(5,4)",
|
||||
nullable: true,
|
||||
defaultValue: 0.66m);
|
||||
|
||||
migrationBuilder.AddColumn<decimal>(
|
||||
name: "SignalAgreementThreshold",
|
||||
table: "Users",
|
||||
type: "numeric(5,4)",
|
||||
nullable: true,
|
||||
defaultValue: 0.5m);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "AllowSignalTrendOverride",
|
||||
table: "Users",
|
||||
type: "boolean",
|
||||
nullable: true,
|
||||
defaultValue: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "DefaultExchange",
|
||||
table: "Users",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
defaultValue: "GmxV2");
|
||||
|
||||
// Update existing NULL values to defaults
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""TrendStrongAgreementThreshold"" = 0.66
|
||||
WHERE ""TrendStrongAgreementThreshold"" IS NULL;
|
||||
");
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""SignalAgreementThreshold"" = 0.5
|
||||
WHERE ""SignalAgreementThreshold"" IS NULL;
|
||||
");
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""AllowSignalTrendOverride"" = true
|
||||
WHERE ""AllowSignalTrendOverride"" IS NULL;
|
||||
");
|
||||
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""DefaultExchange"" = 'GmxV2'
|
||||
WHERE ""DefaultExchange"" IS NULL;
|
||||
");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TrendStrongAgreementThreshold",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "SignalAgreementThreshold",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "AllowSignalTrendOverride",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DefaultExchange",
|
||||
table: "Users");
|
||||
}
|
||||
}
|
||||
}
|
||||
1785
src/Managing.Infrastructure.Database/Migrations/20251229232332_UpdateDefaultExchangeToGmxV2.Designer.cs
generated
Normal file
1785
src/Managing.Infrastructure.Database/Migrations/20251229232332_UpdateDefaultExchangeToGmxV2.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,47 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Managing.Infrastructure.Databases.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class UpdateDefaultExchangeToGmxV2 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Update existing Binance values to GmxV2
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""DefaultExchange"" = 'GmxV2'
|
||||
WHERE ""DefaultExchange"" = 'Binance' OR ""DefaultExchange"" IS NULL;
|
||||
");
|
||||
|
||||
// Update the default value for future inserts
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "DefaultExchange",
|
||||
table: "Users",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
defaultValue: "GmxV2");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Revert to Binance
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Users""
|
||||
SET ""DefaultExchange"" = 'Binance'
|
||||
WHERE ""DefaultExchange"" = 'GmxV2';
|
||||
");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "DefaultExchange",
|
||||
table: "Users",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
defaultValue: "Binance");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1425,6 +1425,9 @@ namespace Managing.Infrastructure.Databases.Migrations
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)");
|
||||
|
||||
b.Property<bool?>("AllowSignalTrendOverride")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<decimal?>("AutoswapAmount")
|
||||
.HasColumnType("decimal(18,8)");
|
||||
|
||||
@@ -1432,6 +1435,9 @@ namespace Managing.Infrastructure.Databases.Migrations
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("character varying(500)");
|
||||
|
||||
b.Property<string>("DefaultExchange")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("EnableAutoswap")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
@@ -1464,10 +1470,16 @@ namespace Managing.Infrastructure.Databases.Migrations
|
||||
b.Property<string>("OwnerWalletAddress")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<decimal?>("SignalAgreementThreshold")
|
||||
.HasColumnType("decimal(5,4)");
|
||||
|
||||
b.Property<string>("TelegramChannel")
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)");
|
||||
|
||||
b.Property<decimal?>("TrendStrongAgreementThreshold")
|
||||
.HasColumnType("decimal(5,4)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AgentName");
|
||||
|
||||
@@ -19,14 +19,20 @@ public class UserEntity
|
||||
public DateTimeOffset? LastConnectionDate { get; set; }
|
||||
public bool IsAdmin { get; set; }
|
||||
|
||||
// User Settings
|
||||
[Column(TypeName = "decimal(18,8)")] public decimal? LowEthAmountAlert { get; set; }
|
||||
// User Settings - Trading Configuration
|
||||
[Column(TypeName = "decimal(18,8)")] public decimal? LowEthAmountAlert { get; set; } = 1.5m; // Default: MinimumTradeEthBalanceUsd
|
||||
public bool EnableAutoswap { get; set; } = false;
|
||||
[Column(TypeName = "decimal(18,8)")] public decimal? AutoswapAmount { get; set; }
|
||||
public int? MaxWaitingTimeForPositionToGetFilledSeconds { get; set; }
|
||||
[Column(TypeName = "decimal(18,8)")] public decimal? MaxTxnGasFeePerPosition { get; set; }
|
||||
[Column(TypeName = "decimal(18,8)")] public decimal? AutoswapAmount { get; set; } = 3m; // Default: AutoSwapAmount
|
||||
public int? MaxWaitingTimeForPositionToGetFilledSeconds { get; set; } = 600; // Default: 10 minutes (600 seconds)
|
||||
[Column(TypeName = "decimal(18,8)")] public decimal? MaxTxnGasFeePerPosition { get; set; } = 1.5m; // Default: MaximumGasFeeUsd
|
||||
public bool IsGmxEnabled { get; set; } = false;
|
||||
public Confidence? MinimumConfidence { get; set; }
|
||||
|
||||
// User Settings - Indicator Combo Configuration
|
||||
public Confidence? MinimumConfidence { get; set; } = Confidence.Medium; // Default: Medium confidence for context indicators
|
||||
[Column(TypeName = "decimal(5,4)")] public decimal? TrendStrongAgreementThreshold { get; set; } = 0.66m; // Default: 66% agreement required
|
||||
[Column(TypeName = "decimal(5,4)")] public decimal? SignalAgreementThreshold { get; set; } = 0.5m; // Default: 50% agreement required
|
||||
public bool? AllowSignalTrendOverride { get; set; } = true; // Default: Allow signal strategies to override trends
|
||||
public TradingExchanges? DefaultExchange { get; set; } = TradingExchanges.GmxV2; // Default exchange
|
||||
|
||||
// Navigation properties
|
||||
public virtual ICollection<AccountEntity> Accounts { get; set; } = new List<AccountEntity>();
|
||||
|
||||
@@ -103,6 +103,8 @@ public class ManagingDbContext : DbContext
|
||||
entity.Property(e => e.TelegramChannel).HasMaxLength(255);
|
||||
entity.Property(e => e.MinimumConfidence)
|
||||
.HasConversion<string>(); // Store enum as string
|
||||
entity.Property(e => e.DefaultExchange)
|
||||
.HasConversion<string>(); // Store enum as string
|
||||
|
||||
// Create indexes for performance
|
||||
entity.HasIndex(e => e.Name).IsUnique();
|
||||
|
||||
@@ -141,6 +141,10 @@ public static class PostgreSqlMappers
|
||||
MaxTxnGasFeePerPosition = entity.MaxTxnGasFeePerPosition,
|
||||
IsGmxEnabled = entity.IsGmxEnabled,
|
||||
MinimumConfidence = entity.MinimumConfidence,
|
||||
TrendStrongAgreementThreshold = entity.TrendStrongAgreementThreshold,
|
||||
SignalAgreementThreshold = entity.SignalAgreementThreshold,
|
||||
AllowSignalTrendOverride = entity.AllowSignalTrendOverride,
|
||||
DefaultExchange = entity.DefaultExchange,
|
||||
Accounts = entity.Accounts?.Select(MapAccountWithoutUser).ToList() ?? new List<Account>()
|
||||
};
|
||||
}
|
||||
@@ -183,7 +187,11 @@ public static class PostgreSqlMappers
|
||||
MaxWaitingTimeForPositionToGetFilledSeconds = user.MaxWaitingTimeForPositionToGetFilledSeconds,
|
||||
MaxTxnGasFeePerPosition = user.MaxTxnGasFeePerPosition,
|
||||
IsGmxEnabled = user.IsGmxEnabled,
|
||||
MinimumConfidence = user.MinimumConfidence
|
||||
MinimumConfidence = user.MinimumConfidence,
|
||||
TrendStrongAgreementThreshold = user.TrendStrongAgreementThreshold,
|
||||
SignalAgreementThreshold = user.SignalAgreementThreshold,
|
||||
AllowSignalTrendOverride = user.AllowSignalTrendOverride,
|
||||
DefaultExchange = user.DefaultExchange
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -264,6 +264,10 @@ public class PostgreSqlUserRepository : BaseRepositoryWithLogging, IUserReposito
|
||||
existingUser.MaxTxnGasFeePerPosition = user.MaxTxnGasFeePerPosition;
|
||||
existingUser.IsGmxEnabled = user.IsGmxEnabled;
|
||||
existingUser.MinimumConfidence = user.MinimumConfidence;
|
||||
existingUser.TrendStrongAgreementThreshold = user.TrendStrongAgreementThreshold;
|
||||
existingUser.SignalAgreementThreshold = user.SignalAgreementThreshold;
|
||||
existingUser.AllowSignalTrendOverride = user.AllowSignalTrendOverride;
|
||||
existingUser.DefaultExchange = user.DefaultExchange;
|
||||
|
||||
_context.Users.Update(existingUser);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user