Coverage for src/copytrading_engine/execution/domain/progress.py: 100%

15 statements  

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

1"""Explicit progress states for each validated signal instruction.""" 

2 

3from typing import Annotated, Literal 

4 

5from pydantic import AwareDatetime, Field 

6 

7from copytrading_engine.execution.domain.values import Identifier, Quantity, Value 

8 

9 

10class Exposure(Value): 

11 """A named comparison of current, proposed, and permitted exposure.""" 

12 

13 scope: Literal["symbol", "total"] 

14 current: Quantity 

15 proposed: Quantity 

16 limit: Quantity 

17 

18 

19# Why a sell is still waiting to go out: Alpaca has no fresh bid to price it from (ADR-0010). 

20type SellWait = Literal["quote_stale", "quote_unavailable"] 

21 

22 

23class Pending(Value): 

24 kind: Literal["pending"] = "pending" 

25 waiting: SellWait | None = None 

26 

27 

28class OrderLinked(Value): 

29 kind: Literal["order_linked"] = "order_linked" 

30 client_id: Identifier 

31 

32 

33class Skipped(Value): 

34 kind: Literal["skipped"] = "skipped" 

35 reason: Annotated[str, Field(min_length=1)] 

36 # The limit a skipped buy would have passed, with its numbers, so Activity can say which. 

37 exposure: tuple[Exposure, ...] = () 

38 # For a sell skipped as `bought_after_sell`: when the buy it would have sold was posted. 

39 bought_at: AwareDatetime | None = None 

40 

41 

42InstructionProgress = Annotated[ 

43 Pending | OrderLinked | Skipped, 

44 Field(discriminator="kind"), 

45]