Add netPnl in db for position
This commit is contained in:
1458
src/Managing.Infrastructure.Database/Migrations/20251002195251_AddNetPnLToPositionEntity.Designer.cs
generated
Normal file
1458
src/Managing.Infrastructure.Database/Migrations/20251002195251_AddNetPnLToPositionEntity.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 AddNetPnLToPositionEntity : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<decimal>(
|
||||
name: "NetPnL",
|
||||
table: "Positions",
|
||||
type: "numeric(18,8)",
|
||||
nullable: false,
|
||||
defaultValue: 0m);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "NetPnL",
|
||||
table: "Positions");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -704,6 +704,9 @@ namespace Managing.Infrastructure.Databases.Migrations
|
||||
b.Property<string>("MoneyManagementJson")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<decimal>("NetPnL")
|
||||
.HasColumnType("decimal(18,8)");
|
||||
|
||||
b.Property<int?>("OpenTradeId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
|
||||
@@ -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