Coverage for src/copytrading_engine/trading/presentation/operator_models.py: 100%

41 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-16 16:55 +0000

1"""Bounded native read contracts backed by operational evidence.""" 

2 

3from typing import Literal 

4 

5from pydantic import AwareDatetime 

6 

7from copytrading_engine.execution.domain.values import Value 

8from copytrading_engine.execution.presentation.operator_views import ( 

9 AccountUnavailable, 

10 DestinationView, 

11) 

12from copytrading_engine.shared.reading import PostReading 

13from copytrading_engine.shared.signals import Instruction, StopCall 

14 

15 

16class SourceEmbedField(Value): 

17 name: str 

18 value: str 

19 inline: bool 

20 

21 

22class SourceEmbedEvidence(Value): 

23 title: str | None = None 

24 description: str | None = None 

25 fields: tuple[SourceEmbedField, ...] 

26 

27 

28class SourceAttachmentEvidence(Value): 

29 evidence_id: str 

30 attachment_id: str 

31 filename: str 

32 content_type: str | None 

33 declared_size: int 

34 status: Literal[ 

35 "pending", 

36 "available", 

37 "missing", 

38 "oversize", 

39 "download_failed", 

40 "origin_rejected", 

41 "timed_out", 

42 "count_exceeded", 

43 "skipped_rejected", 

44 ] 

45 byte_size: int | None = None 

46 sha256: str | None = None 

47 omitted_count: int = 0 

48 

49 

50class SourceEventEvidence(Value): 

51 event_type: str 

52 message_id: str | None = None 

53 channel_id: str | None = None 

54 author_id: str | None = None 

55 timestamp: str | None = None 

56 content: str 

57 embeds: tuple[SourceEmbedEvidence, ...] 

58 attachments: tuple[SourceAttachmentEvidence, ...] 

59 attachments_omitted: int 

60 capture_status: Literal["complete", "oversize", "missing"] 

61 payload_bytes: int 

62 

63 

64class RejectedSourceActivity(Value): 

65 source_id: str 

66 rejected_at: AwareDatetime 

67 reason: str 

68 source_event: SourceEventEvidence 

69 

70 

71class SourceActivity(Value): 

72 sequence: int 

73 source_id: str 

74 author_id: str | None = None 

75 source_revision: int 

76 source_at: AwareDatetime 

77 captured_at: AwareDatetime 

78 text: str 

79 capture_status: str 

80 parse_status: str 

81 delivery_status: str 

82 decision: str | None 

83 parser_reason: str | None 

84 parser_profile: str | None 

85 interpreted_by: str | None 

86 # The calls the post trades, as the engine places them, before any account sizing. 

87 instructions: tuple[Instruction, ...] 

88 # The stops the post sets, placed only for an account that follows the guru's stops (ADR-0015). 

89 stops: tuple[StopCall, ...] = () 

90 # For a post that waits for the owner: what Copy places (ADR-0007). 

91 suggested: tuple[Instruction, ...] = () 

92 # How the reader read the post, for Activity's "Read as". 

93 reading: PostReading | None = None 

94 guru_id: str | None = None 

95 profile_revision: str | None = None 

96 source_event: SourceEventEvidence 

97 destinations: tuple[DestinationView, ...] 

98 # When the reader took the post, when it finished, and when the reading reached the 

99 # accounts: with source_at and captured_at, how long each step took. 

100 read_started_at: AwareDatetime | None = None 

101 read_at: AwareDatetime | None = None 

102 delivered_at: AwareDatetime | None = None 

103 

104 

105class SourceActivityPage(Value): 

106 items: tuple[SourceActivity, ...] 

107 rejected_items: tuple[RejectedSourceActivity, ...] 

108 next_before_seq: int | None = None 

109 unavailable_accounts: tuple[AccountUnavailable, ...] = () 

110 

111 

112class GuruPost(Value): 

113 """One read post of a guru's: when it was posted and how long the reader took.""" 

114 

115 source_id: str 

116 guru_id: str 

117 source_at: AwareDatetime 

118 read_started_at: AwareDatetime | None = None 

119 read_at: AwareDatetime | None = None 

120 

121 

122class GuruDayStats(Value): 

123 """One guru's numbers for a day, counted from every post the engine holds, not one page.""" 

124 

125 guru_id: str 

126 posts: int 

127 #: The day's posts at least one account bought or sold on. 

128 traded: int 

129 #: How long the reader took per post that day, on average; None before any was read. 

130 read_seconds: float | None = None 

131 #: Posts of the current trading day a call of which still waits for the owner, any calendar 

132 #: day, newest first and whole, so the app lists them without having loaded them; it leaves 

133 #: out the ones the owner skipped, which only it knows. 

134 waiting: tuple[SourceActivity, ...] = () 

135 

136 

137class GuruDayStatsPage(Value): 

138 day_start: AwareDatetime 

139 day_end: AwareDatetime 

140 gurus: tuple[GuruDayStats, ...] 

141 unavailable_accounts: tuple[AccountUnavailable, ...] = ()