PaperFill.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.ComponentModel.DataAnnotations;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. namespace Domain.Entities.Paper;
  4. /// <summary>
  5. /// 모의투자 체결 결과 — 주문당 1건(OrderID UNIQUE)으로 재실행 멱등을 보장한다 (d4 §③).
  6. /// 배치(M2)가 TargetDate 시세로 기표한다. 매도 시 RealizedPnL(실현손익)을 기록.
  7. /// </summary>
  8. public class PaperFill
  9. {
  10. [ForeignKey(nameof(OrderID))]
  11. public virtual PaperOrder Order { get; private set; } = null!;
  12. [Key]
  13. public int ID { get; private set; }
  14. public int OrderID { get; private set; }
  15. /// <summary>체결가 (18,0)</summary>
  16. public decimal Price { get; private set; }
  17. public int Quantity { get; private set; }
  18. /// <summary>수수료 (토큰 sink)</summary>
  19. public decimal Fee { get; private set; }
  20. /// <summary>거래세 (매도 시, 토큰 sink)</summary>
  21. public decimal Tax { get; private set; }
  22. /// <summary>체결 총액 (Price × Quantity ± 수수료/세금 반영은 핸들러/배치 정책)</summary>
  23. public decimal Amount { get; private set; }
  24. /// <summary>매도 확정 손익 (매수는 null)</summary>
  25. public decimal? RealizedPnL { get; private set; }
  26. /// <summary>체결가 기준일</summary>
  27. public DateOnly PriceDate { get; private set; }
  28. public DateTime FilledAt { get; private set; } = DateTime.UtcNow;
  29. private PaperFill() { }
  30. public static PaperFill Create(
  31. int orderID,
  32. decimal price,
  33. int quantity,
  34. decimal fee,
  35. decimal tax,
  36. decimal amount,
  37. DateOnly priceDate,
  38. decimal? realizedPnL = null
  39. ) {
  40. if (orderID <= 0)
  41. {
  42. throw new ArgumentOutOfRangeException(nameof(orderID));
  43. }
  44. if (quantity <= 0)
  45. {
  46. throw new ArgumentOutOfRangeException(nameof(quantity));
  47. }
  48. return new PaperFill
  49. {
  50. OrderID = orderID,
  51. Price = price,
  52. Quantity = quantity,
  53. Fee = fee,
  54. Tax = tax,
  55. Amount = amount,
  56. PriceDate = priceDate,
  57. RealizedPnL = realizedPnL
  58. };
  59. }
  60. }