Files

133 lines
7.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using FinlyticCore.Dtos.TechnicalAnalysis;
namespace FinlyticCore.Dtos.Trading;
public record DerivativeSelectionDto(
[property: JsonPropertyName("derivativeIsin")] string DerivativeIsin,
// Trade Republic liefert für Derivate keine WKN, nur die ISIN (siehe TradeRepublicDerivativeItemDto).
// Daher ist dieses Feld nullable: eine ISIN darf hier NICHT als Ersatz-WKN eingetragen werden (Rules.md §4).
[property: JsonPropertyName("derivativeWkn")] string? DerivativeWkn,
[property: JsonPropertyName("issuer")] string Issuer,
[property: JsonPropertyName("optionType")] string OptionType, // "LONG" oder "SHORT"
[property: JsonPropertyName("strike")] decimal Strike,
[property: JsonPropertyName("barrier")] decimal Barrier,
[property: JsonPropertyName("leverage")] decimal Leverage,
[property: JsonPropertyName("safetyBufferPercent")] decimal SafetyBufferPercent,
[property: JsonPropertyName("spreadPercentage")] decimal SpreadPercentage,
[property: JsonPropertyName("size")] decimal Size
);
/// <summary>
/// Kennzeichnet die Herkunft einer <see cref="AiValidationResultDto"/>-Entscheidung, damit
/// Konsumenten (Frontend, Logs) eine echte KI-Analyse von einer regelbasierten Ersatzentscheidung
/// unterscheiden können. Der Enum-Wert <see cref="Ai"/> ist absichtlich der Default (0), damit ein
/// vom N8N-Webhook geliefertes JSON, das dieses Feld (noch) nicht setzt, korrekt als KI-Ergebnis
/// interpretiert wird.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter<ValidationSource>))]
public enum ValidationSource
{
Ai,
RuleBased
}
/// <summary>
/// Ergebnis des AI-Reasoning-Gates. <see cref="Confidence"/> ist nur gesetzt, wenn <see cref="Source"/>
/// den Wert <see cref="ValidationSource.Ai"/> hat, da eine Konfidenz ohne tatsächliche KI-Bewertung
/// erfunden wäre (Rules.md §4).
/// </summary>
public record AiValidationResultDto(
[property: JsonPropertyName("isApproved")] bool IsApproved,
[property: JsonPropertyName("confidence")] decimal? Confidence,
[property: JsonPropertyName("validationSource")] ValidationSource Source,
[property: JsonPropertyName("thesisSummary")] string ThesisSummary,
[property: JsonPropertyName("invalidationReason")] string InvalidationReason,
[property: JsonPropertyName("keyCatalysts")] List<string> KeyCatalysts,
[property: JsonPropertyName("identifiedRisks")] List<string> IdentifiedRisks
);
public record TradeProposalDto(
[property: JsonPropertyName("proposalId")] Guid ProposalId,
[property: JsonPropertyName("underlyingIsin")] string UnderlyingIsin,
[property: JsonPropertyName("symbol")] string Symbol,
[property: JsonPropertyName("strategyKey")] string StrategyKey,
[property: JsonPropertyName("direction")] SignalDirection Direction,
[property: JsonPropertyName("qualityScore")] decimal QualityScore,
[property: JsonPropertyName("compositeScore")] decimal CompositeScore,
[property: JsonPropertyName("currentPrice")] decimal CurrentPrice,
[property: JsonPropertyName("entryPrice")] decimal EntryPrice,
[property: JsonPropertyName("invalidationPrice")] decimal InvalidationPrice,
[property: JsonPropertyName("exitPlan")] ExitPlan ExitPlan,
[property: JsonPropertyName("selectedDerivative")] DerivativeSelectionDto? SelectedDerivative,
[property: JsonPropertyName("aiValidation")] AiValidationResultDto AiValidation,
[property: JsonPropertyName("createdAtUtc")] DateTime CreatedAtUtc,
[property: JsonPropertyName("expiresAtUtc")] DateTime ExpiresAtUtc
);
/// <summary>
/// Full result of <c>ITradeLifecycleService.EvaluateAssetAsync</c>, carrying both possible outcomes of the
/// evaluation pipeline (technicals, sentiment, fundamentals, simulation-reliability, AI reasoning gate):
/// an accepted opportunity (<see cref="Proposal"/> is set) or a rejection, in which case <see cref="Proposal"/>
/// is <see langword="null"/> but every score/reasoning field below is still populated with the real,
/// already-computed values instead of leaving the caller with silence (Rules.md §4).
/// <para>
/// When the pipeline could not even produce a score (no technical setups available for the ISIN, or the
/// ISIN was blank), the score fields are <c>0</c> and <see cref="AiThesisSummary"/> carries a
/// "<c>[Regelbasiert]</c>"-prefixed explanation — the same prefix <see cref="AiValidationResultDto"/> uses for
/// its <see cref="ValidationSource.RuleBased"/> fallback — so a caller/UI can recognize this is not a real
/// AI verdict, just as it already must for a rule-based <see cref="AiValidationResultDto"/>.
/// </para>
/// </summary>
public record AssetEvaluationResultDto(
[property: JsonPropertyName("proposal")] TradeProposalDto? Proposal,
[property: JsonPropertyName("compositeScore")] decimal CompositeScore,
[property: JsonPropertyName("technicalScore")] decimal TechnicalScore,
[property: JsonPropertyName("sentimentScore")] decimal SentimentScore,
[property: JsonPropertyName("fundamentalScore")] decimal FundamentalScore,
[property: JsonPropertyName("passedEarningsLockout")] bool PassedEarningsLockout,
[property: JsonPropertyName("daysToNextEarnings")] int? DaysToNextEarnings,
[property: JsonPropertyName("passedDividendGate")] bool PassedDividendGate,
[property: JsonPropertyName("daysToNextExDividend")] int? DaysToNextExDividend,
[property: JsonPropertyName("aiApproved")] bool AiApproved,
[property: JsonPropertyName("aiThesisSummary")] string AiThesisSummary,
[property: JsonPropertyName("aiIdentifiedRisks")] List<string> AiIdentifiedRisks
);
public record TradeFillDto(
[property: JsonPropertyName("fillId")] Guid FillId,
[property: JsonPropertyName("executedAtUtc")] DateTime ExecutedAtUtc,
[property: JsonPropertyName("price")] decimal Price,
[property: JsonPropertyName("quantity")] decimal Quantity,
[property: JsonPropertyName("fee")] decimal Fee,
[property: JsonPropertyName("note")] string? Note
);
public record ActiveTradeDto(
[property: JsonPropertyName("tradeId")] Guid TradeId,
[property: JsonPropertyName("proposalId")] Guid ProposalId,
[property: JsonPropertyName("userId")] Guid UserId,
[property: JsonPropertyName("underlyingIsin")] string UnderlyingIsin,
[property: JsonPropertyName("symbol")] string Symbol,
[property: JsonPropertyName("derivativeIsin")] string? DerivativeIsin,
[property: JsonPropertyName("derivativeWkn")] string? DerivativeWkn,
[property: JsonPropertyName("executionMode")] ExecutionMode ExecutionMode,
[property: JsonPropertyName("instrumentType")] InstrumentCategoryType InstrumentType,
[property: JsonPropertyName("direction")] SignalDirection Direction,
[property: JsonPropertyName("status")] TradeStatus Status,
[property: JsonPropertyName("averageBuyIn")] decimal AverageBuyIn,
[property: JsonPropertyName("totalQuantity")] decimal TotalQuantity,
[property: JsonPropertyName("initialStopLoss")] decimal InitialStopLoss,
[property: JsonPropertyName("currentStopLoss")] decimal CurrentStopLoss,
[property: JsonPropertyName("currentPrice")] decimal CurrentPrice,
[property: JsonPropertyName("unrealizedPnlEur")] decimal UnrealizedPnlEur,
[property: JsonPropertyName("unrealizedPnlPercent")] decimal UnrealizedPnlPercent,
[property: JsonPropertyName("realizedPnlEur")] decimal RealizedPnlEur,
[property: JsonPropertyName("exitPlan")] ExitPlan ExitPlan,
[property: JsonPropertyName("fills")] List<TradeFillDto> Fills,
[property: JsonPropertyName("openedAtUtc")] DateTime OpenedAtUtc,
[property: JsonPropertyName("closedAtUtc")] DateTime? ClosedAtUtc
);