feat(Trades): refactor trades MQTT client and DTOs

This commit is contained in:
2026-08-09 21:01:42 +02:00
parent c74a4456af
commit e7427b7464
21 changed files with 3363 additions and 0 deletions
+146
View File
@@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using FinlyticCore.Models.Analyzer;
using FinlyticCore.Models.Trades;
namespace FinlyticTrades.Entities;
[Table("trades")]
public class TradeEntity
{
[Key]
public Guid Id { get; set; } = Guid.NewGuid();
[Required]
[MaxLength(100)]
public string TradeId { get; set; } = string.Empty;
[Required]
[MaxLength(100)]
public string AnalysisId { get; set; } = string.Empty;
[Required]
[MaxLength(100)]
public string EventId { get; set; } = string.Empty;
[Required]
[MaxLength(50)]
public string Sector { get; set; } = string.Empty;
[Required]
[MaxLength(30)]
public string Symbol { get; set; } = string.Empty;
[Required]
[MaxLength(30)]
public string Isin { get; set; } = string.Empty;
[MaxLength(150)]
public string CompanyName { get; set; } = string.Empty;
public TradeStatus Status { get; set; } = TradeStatus.Proposed;
[MaxLength(100)]
public string? UserId { get; set; }
public bool IsGlobalProposal { get; set; } = true;
[Column(TypeName = "decimal(18,4)")]
public decimal EntryPrice { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal StopLoss { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal TakeProfit { get; set; }
[MaxLength(10)]
public string SignalType { get; set; } = "BUY";
[MaxLength(30)]
public string RiskTolerance { get; set; } = "Moderate";
[MaxLength(20)]
public string Timeframe { get; set; } = "1D";
[MaxLength(30)]
public string InstrumentType { get; set; } = "Stock";
public double WinRate { get; set; }
public VixMarketRegime VixRegime { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal VixValue { get; set; }
public int TtlMinutes { get; set; } = 60;
public string Reasoning { get; set; } = string.Empty;
// --- New Fields for Detailed Execution & Rationale ---
[Column(TypeName = "decimal(18,4)")]
public decimal? EntryZoneMin { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? EntryZoneMax { get; set; }
public string? TakeProfitTargets { get; set; } // Stored as comma separated values
[Column(TypeName = "decimal(18,4)")]
public decimal? RiskRewardRatio { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? MaxLeverage { get; set; }
public string TechnicalRationale { get; set; } = string.Empty;
public string FundamentalRationale { get; set; } = string.Empty;
public string RiskWarning { get; set; } = string.Empty;
// --- User Exit Data ---
[Column(TypeName = "decimal(18,4)")]
public decimal? UserExitPrice { get; set; }
public DateTime? UserExitTimestamp { get; set; }
// --- Real Trade Execution Data ---
[Column(TypeName = "decimal(18,4)")]
public decimal? ActualEntryPrice { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? PositionSize { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? LeverageUsed { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? EntryFee { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? ExitFee { get; set; }
public DateTime? ExecutionTimestamp { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? Quantity { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? KnockoutThreshold { get; set; }
public bool IsRecurring { get; set; } = false;
[MaxLength(50)]
public string? CloseReason { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? PnlAbsolute { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? PnlPercent { get; set; }
public bool? IsWin { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime? ClosedAt { get; set; }
public List<TradeHourlyUpdateEntity> HourlyUpdates { get; set; } = new();
}
@@ -0,0 +1,43 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace FinlyticTrades.Entities;
[Table("trade_hourly_updates")]
[Index(nameof(TradeId), nameof(Timestamp))]
public class TradeHourlyUpdateEntity
{
[Key]
public Guid Id { get; set; } = Guid.NewGuid();
[Required]
public Guid TradeId { get; set; }
[ForeignKey(nameof(TradeId))]
public TradeEntity? Trade { get; set; }
[Required]
[MaxLength(30)]
public string Recommendation { get; set; } = "Hold"; // "Hold", "AdjustSL", "AdjustTP", "Close"
[Column(TypeName = "decimal(18,4)")]
public decimal CurrentPrice { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? SuggestedStopLoss { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? SuggestedTakeProfit { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal VixValue { get; set; }
[Column(TypeName = "decimal(18,4)")]
public decimal? FloatingPnlPercent { get; set; }
public string Reasoning { get; set; } = string.Empty;
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}
@@ -0,0 +1,15 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace FinlyticTrades.Entities;
public class TradesSettingsEntity
{
[Key]
public Guid Id { get; set; }
public double AtrStopLossMultiplier { get; set; } = 1.5;
public double RiskPerTradePercentage { get; set; } = 1.0;
public int MaxOpenPositions { get; set; } = 5;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
}