Update the position count and initiator
This commit is contained in:
@@ -23,6 +23,11 @@ public class PositionEntity
|
||||
[MaxLength(255)] public string AccountName { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Identifier of the bot or entity that initiated this position
|
||||
/// </summary>
|
||||
[Required] public Guid InitiatorIdentifier { get; set; }
|
||||
|
||||
// Foreign keys to trades
|
||||
public int? OpenTradeId { get; set; }
|
||||
|
||||
@@ -300,6 +300,7 @@ public class ManagingDbContext : DbContext
|
||||
entity.Property(e => e.SignalIdentifier).IsRequired().HasMaxLength(255);
|
||||
entity.Property(e => e.AccountName).IsRequired().HasMaxLength(255);
|
||||
entity.Property(e => e.UserId);
|
||||
entity.Property(e => e.InitiatorIdentifier).IsRequired();
|
||||
entity.Property(e => e.MoneyManagementJson).HasColumnType("text");
|
||||
|
||||
// Configure relationship with User
|
||||
@@ -333,7 +334,7 @@ public class ManagingDbContext : DbContext
|
||||
entity.HasIndex(e => e.Identifier).IsUnique();
|
||||
entity.HasIndex(e => e.UserId);
|
||||
entity.HasIndex(e => e.Status);
|
||||
entity.HasIndex(e => e.Date);
|
||||
entity.HasIndex(e => e.InitiatorIdentifier);
|
||||
|
||||
// Composite indexes
|
||||
entity.HasIndex(e => new { e.UserId, e.Identifier });
|
||||
|
||||
@@ -561,7 +561,8 @@ public static class PostgreSqlMappers
|
||||
entity.User != null ? Map(entity.User) : null)
|
||||
{
|
||||
Status = entity.Status,
|
||||
SignalIdentifier = entity.SignalIdentifier
|
||||
SignalIdentifier = entity.SignalIdentifier,
|
||||
InitiatorIdentifier = entity.InitiatorIdentifier
|
||||
};
|
||||
|
||||
// Set ProfitAndLoss with proper type
|
||||
@@ -596,6 +597,7 @@ public static class PostgreSqlMappers
|
||||
SignalIdentifier = position.SignalIdentifier,
|
||||
AccountName = position.AccountName,
|
||||
UserId = position.User?.Id ?? 0,
|
||||
InitiatorIdentifier = position.InitiatorIdentifier,
|
||||
MoneyManagementJson = position.MoneyManagement != null
|
||||
? JsonConvert.SerializeObject(position.MoneyManagement)
|
||||
: null
|
||||
|
||||
@@ -397,6 +397,22 @@ public class PostgreSqlTradingRepository : ITradingRepository
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Position>> GetPositionsByInitiatorIdentifierAsync(Guid initiatorIdentifier)
|
||||
{
|
||||
var positions = await _context.Positions
|
||||
.AsNoTracking()
|
||||
.Include(p => p.User)
|
||||
.Include(p => p.OpenTrade)
|
||||
.Include(p => p.StopLossTrade)
|
||||
.Include(p => p.TakeProfit1Trade)
|
||||
.Include(p => p.TakeProfit2Trade)
|
||||
.Where(p => p.InitiatorIdentifier == initiatorIdentifier)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return PostgreSqlMappers.Map(positions);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Position>> GetAllPositionsAsync()
|
||||
{
|
||||
var positions = await _context.Positions
|
||||
|
||||
Reference in New Issue
Block a user