Add netPnl in db for position
This commit is contained in:
@@ -55,4 +55,6 @@ public class PositionEntity
|
||||
[ForeignKey("TakeProfit1TradeId")] public virtual TradeEntity? TakeProfit1Trade { get; set; }
|
||||
|
||||
[ForeignKey("TakeProfit2TradeId")] public virtual TradeEntity? TakeProfit2Trade { get; set; }
|
||||
|
||||
[Column(TypeName = "decimal(18,8)")] public decimal NetPnL { get; set; }
|
||||
}
|
||||
@@ -296,6 +296,7 @@ public class ManagingDbContext : DbContext
|
||||
{
|
||||
entity.HasKey(e => e.Identifier);
|
||||
entity.Property(e => e.ProfitAndLoss).HasColumnType("decimal(18,8)");
|
||||
entity.Property(e => e.NetPnL).HasColumnType("decimal(18,8)");
|
||||
entity.Property(e => e.OriginDirection).IsRequired().HasConversion<string>();
|
||||
entity.Property(e => e.Status).IsRequired().HasConversion<string>();
|
||||
entity.Property(e => e.Ticker).IsRequired().HasConversion<string>();
|
||||
|
||||
@@ -570,7 +570,7 @@ public static class PostgreSqlMappers
|
||||
};
|
||||
|
||||
// Set ProfitAndLoss with proper type
|
||||
position.ProfitAndLoss = new ProfitAndLoss { Realized = entity.ProfitAndLoss, Net = entity.ProfitAndLoss - entity.UiFees - entity.GasFees };
|
||||
position.ProfitAndLoss = new ProfitAndLoss { Realized = entity.ProfitAndLoss, Net = entity.NetPnL };
|
||||
|
||||
// Set fee properties
|
||||
position.UiFees = entity.UiFees;
|
||||
@@ -610,7 +610,8 @@ public static class PostgreSqlMappers
|
||||
InitiatorIdentifier = position.InitiatorIdentifier,
|
||||
MoneyManagementJson = position.MoneyManagement != null
|
||||
? JsonConvert.SerializeObject(position.MoneyManagement)
|
||||
: null
|
||||
: null,
|
||||
NetPnL = position.ProfitAndLoss?.Net ?? (position.ProfitAndLoss?.Realized - position.UiFees - position.GasFees ?? 0)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user