Coverage for src/finbot/execution/errors.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-04 12:05 +0000

1class BrokerError(RuntimeError): 

2 """Base error for broker operations""" 

3 

4 

5class BrokerConnectionError(BrokerError): 

6 """Raised when a broker cannot be reached""" 

7 

8 

9class BrokerResponseError(BrokerError): 

10 """Raised when a broker response cannot be mapped to the domain model.""" 

11 

12 

13class BrokerAPIError(BrokerError): 

14 """Raised when a broker rejects an API request""" 

15 

16 def __init__(self, message: str, *, status_code: int): 

17 super().__init__(message) 

18 self.status_code = status_code 

19 

20 

21class TradingDisabledError(BrokerError): 

22 """Raised when order submission is attempted while trading is disabled.""" 

23 

24 

25class OrderConflictError(BrokerError): 

26 """Raised when a client order ID refers to a different order.""" 

27 

28 

29class ReconciliationError(BrokerError): 

30 """Raised when local and broker order state cannot be reconciled""" 

31 

32 def __init__(self, unresolved_client_order_ids: list[str]): 

33 self.unresolved_client_order_ids = tuple(unresolved_client_order_ids) 

34 joined = ", ".join(self.unresolved_client_order_ids) 

35 

36 super().__init__(f"Could not reconcile persisted orders: {joined}") 

37 

38 

39class RuntimeNotReadyError(RuntimeError): 

40 """Raised when trading is attempted before the execution runtime is ready.""" 

41 

42 

43class KillSwitchActiveError(RuntimeError): 

44 """Raised when trading is attempted while the kill switch is active.""" 

45 

46 

47class RuntimeStoppedError(RuntimeError): 

48 """Raised when an operation is attempted on a stopped execution runtime."""