Coverage for src/copytrading_engine/trading/application/ports.py: 100%

13 statements  

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

1"""Ports the trading use cases need from retained operational evidence.""" 

2 

3import datetime as dt 

4from pathlib import Path 

5from typing import Protocol 

6 

7from copytrading_engine.execution.domain.events import JournalEvent 

8from copytrading_engine.execution.domain.ledger_state import LedgerSnapshot 

9from copytrading_engine.execution.domain.manual_commands import ManualSourceEvidence 

10from copytrading_engine.execution.presentation.account_feed import AccountFeedPage 

11from copytrading_engine.execution.presentation.operator_views import ( 

12 AccountEventPage, 

13 AccountOverview, 

14 DestinationView, 

15) 

16from copytrading_engine.shared.raw_message import RawMessage 

17from copytrading_engine.shared.signals import Instruction 

18from copytrading_engine.trading.presentation.operator_models import GuruPost, SourceActivityPage 

19 

20 

21class ChannelHistory(Protocol): 

22 """Recent text posts of one source channel, for learning a guru's style.""" 

23 

24 async def recent_posts( 

25 self, token: str, channel_id: str, author_id: str | None, limit: int 

26 ) -> tuple[str, ...]: ... 

27 

28 

29class OperatorEvidence(Protocol): 

30 """Read committed source, parser, and account evidence without writing or binding.""" 

31 

32 def source_page( 

33 self, 

34 database: Path, 

35 *, 

36 before_seq: int | None, 

37 limit: int, 

38 destinations: dict[str, tuple[DestinationView, ...]], 

39 source_ids: tuple[str, ...] | None = None, 

40 channel: tuple[str, str] | None = None, 

41 channels: tuple[tuple[str, str], ...] | None = None, 

42 ) -> SourceActivityPage: ... 

43 

44 def guru_posts(self, database: Path, *, since: dt.datetime) -> tuple[GuruPost, ...]: ... 

45 

46 def retained_account( 

47 self, path: Path, *, before_seq: int | None = None, limit: int = 50 

48 ) -> tuple[AccountOverview, LedgerSnapshot, AccountEventPage]: ... 

49 

50 def retained_feed( 

51 self, path: Path, *, before_seq: int | None, limit: int 

52 ) -> AccountFeedPage: ... 

53 

54 def retained_fills(self, path: Path) -> tuple[LedgerSnapshot, tuple[JournalEvent, ...]]: ... 

55 

56 def retained_message_events( 

57 self, path: Path, message_ids: set[str] 

58 ) -> tuple[JournalEvent, ...]: ... 

59 

60 def manual_source_evidence(self, database: Path, source_id: str) -> ManualSourceEvidence: ... 

61 

62 def record_owner_correction( 

63 self, 

64 database: Path, 

65 source_id: str, 

66 instructions: tuple[Instruction, ...], 

67 at: dt.datetime, 

68 ) -> None: ... 

69 

70 def historical_source_message(self, database: Path, source_id: str) -> RawMessage: ... 

71 

72 def delete_record(self, root: Path, account_id: str) -> str | None: ...