Price reminder and init approval

* Start price reminder grain

* Add config and init grain at startup

* Save init wallet when already init
This commit is contained in:
Oda
2025-09-13 02:29:14 +07:00
committed by GitHub
parent da50b30344
commit 56b4f14eb3
69 changed files with 2373 additions and 701 deletions

View File

@@ -12,7 +12,7 @@ public static class PriceHelpers
var price = new PriceDto
{
Exchange = candle.Exchange.ToString(),
Ticker = candle.Ticker,
Ticker = candle.Ticker.ToString(),
OpenTime = candle.OpenTime,
Open = candle.Open,
Close = candle.Close,
@@ -30,7 +30,7 @@ public static class PriceHelpers
return new Candle
{
Exchange = MiscExtensions.ParseEnum<TradingExchanges>(dto.Exchange),
Ticker = dto.Ticker,
Ticker = MiscExtensions.ParseEnum<Ticker>(dto.Ticker),
OpenTime = dto.OpenTime,
Open = dto.Open,
Close = dto.Close,

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Managing.Infrastructure.Databases.Migrations
{
/// <inheritdoc />
public partial class AddIsGmxInitializedToAccount : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsGmxInitialized",
table: "Accounts",
type: "boolean",
nullable: false,
defaultValue: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsGmxInitialized",
table: "Accounts");
}
}
}

View File

@@ -34,6 +34,11 @@ namespace Managing.Infrastructure.Databases.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsGmxInitialized")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false);
b.Property<string>("Key")
.IsRequired()
.HasMaxLength(500)

View File

@@ -8,12 +8,13 @@ namespace Managing.Infrastructure.Databases.PostgreSql.Entities;
public class AccountEntity
{
[Key] public int Id { get; set; }
[Required] public string Name { get; set; }
[Required] public required string Name { get; set; }
[Required] public TradingExchanges Exchange { get; set; }
[Required] public AccountType Type { get; set; }
[Required] public string? Key { get; set; }
public string? Secret { get; set; }
[Required] public int UserId { get; set; }
[Required] public bool IsGmxInitialized { get; set; } = false;
// Navigation properties
public UserEntity? User { get; set; }

View File

@@ -64,6 +64,9 @@ public class ManagingDbContext : DbContext
entity.Property(e => e.Type)
.IsRequired()
.HasConversion<string>(); // Store enum as string
entity.Property(e => e.IsGmxInitialized)
.IsRequired()
.HasDefaultValue(false); // Default value for new records
// Create unique index on account name
entity.HasIndex(e => e.Name).IsUnique();

View File

@@ -72,7 +72,7 @@ public class PostgreSqlAccountRepository : IAccountRepository
_cacheService.SaveValue(cacheKey, account, TimeSpan.FromHours(1));
return account;
}
catch (Exception ex)
catch (Exception)
{
// If there's an error, try to reset the connection
throw;
@@ -117,4 +117,34 @@ public class PostgreSqlAccountRepository : IAccountRepository
_context.Accounts.Add(accountEntity);
await _context.SaveChangesAsync().ConfigureAwait(false);
}
public async Task UpdateAccountAsync(Account account)
{
try
{
await PostgreSqlConnectionHelper.EnsureConnectionOpenAsync(_context);
var existingEntity = await _context.Accounts
.AsTracking()
.FirstOrDefaultAsync(a => a.Name == account.Name)
.ConfigureAwait(false);
if (existingEntity == null)
{
throw new ArgumentException($"Account '{account.Name}' not found");
}
// Update properties
existingEntity.IsGmxInitialized = account.IsGmxInitialized;
await _context.SaveChangesAsync().ConfigureAwait(false);
// Clear cache for this account
var cacheKey = $"account_{account.Name}";
_cacheService.RemoveValue(cacheKey);
}
finally
{
await PostgreSqlConnectionHelper.SafeCloseConnectionAsync(_context);
}
}
}

View File

@@ -34,7 +34,8 @@ public static class PostgreSqlMappers
Key = entity.Key,
Secret = entity.Secret,
User = entity.User != null ? Map(entity.User) : null,
Balances = new List<Balance>() // Empty list for now, balances handled separately if needed
Balances = new List<Balance>(), // Empty list for now, balances handled separately if needed
IsGmxInitialized = entity.IsGmxInitialized
};
}
@@ -50,6 +51,7 @@ public static class PostgreSqlMappers
Key = account.Key,
Secret = account.Secret,
UserId = account.User.Id,
IsGmxInitialized = account.IsGmxInitialized
};
}