22from collections import defaultdict , deque
33from dataclasses import asdict , dataclass
44from datetime import datetime
5- from typing import Dict , Protocol , runtime_checkable
5+ from typing import Any , Dict , Protocol , runtime_checkable
66from zoneinfo import ZoneInfo
77
88from loguru import logger
@@ -54,7 +54,7 @@ class PublisherState:
5454
5555@runtime_checkable
5656class PublisherCheck (Protocol ):
57- def __init__ (self , state : PublisherState , config : PublisherCheckConfig ):
57+ def __init__ (self , state : PublisherState , config : PublisherCheckConfig ) -> None :
5858 ...
5959
6060 def state (self ) -> PublisherState :
@@ -63,12 +63,12 @@ def state(self) -> PublisherState:
6363 def run (self ) -> bool :
6464 ...
6565
66- def error_message (self ) -> dict :
66+ def error_message (self ) -> Dict [ str , Any ] :
6767 ...
6868
6969
7070class PublisherWithinAggregateConfidenceCheck (PublisherCheck ):
71- def __init__ (self , state : PublisherState , config : PublisherCheckConfig ):
71+ def __init__ (self , state : PublisherState , config : PublisherCheckConfig ) -> None :
7272 self .__state = state
7373 self .__max_interval_distance : int = int (config ["max_interval_distance" ])
7474
@@ -103,7 +103,7 @@ def run(self) -> bool:
103103 # Fail
104104 return False
105105
106- def error_message (self ) -> dict :
106+ def error_message (self ) -> Dict [ str , Any ] :
107107 diff = self .__state .price - self .__state .price_aggregate
108108 intervals_away = abs (diff / self .__state .confidence_interval_aggregate )
109109 return {
@@ -117,7 +117,7 @@ def error_message(self) -> dict:
117117
118118
119119class PublisherConfidenceIntervalCheck (PublisherCheck ):
120- def __init__ (self , state : PublisherState , config : PublisherCheckConfig ):
120+ def __init__ (self , state : PublisherState , config : PublisherCheckConfig ) -> None :
121121 self .__state = state
122122 self .__min_confidence_interval : int = int (config ["min_confidence_interval" ])
123123
@@ -141,7 +141,7 @@ def run(self) -> bool:
141141 # Fail
142142 return False
143143
144- def error_message (self ) -> dict :
144+ def error_message (self ) -> Dict [ str , Any ] :
145145 return {
146146 "msg" : f"{ self .__state .publisher_name } confidence interval is too tight." ,
147147 "type" : "PublisherConfidenceIntervalCheck" ,
@@ -153,7 +153,7 @@ def error_message(self) -> dict:
153153
154154
155155class PublisherOfflineCheck (PublisherCheck ):
156- def __init__ (self , state : PublisherState , config : PublisherCheckConfig ):
156+ def __init__ (self , state : PublisherState , config : PublisherCheckConfig ) -> None :
157157 self .__state = state
158158 self .__max_slot_distance : int = int (config ["max_slot_distance" ])
159159 self .__abandoned_slot_distance : int = int (config ["abandoned_slot_distance" ])
@@ -182,7 +182,7 @@ def run(self) -> bool:
182182 # Fail
183183 return False
184184
185- def error_message (self ) -> dict :
185+ def error_message (self ) -> Dict [ str , Any ] :
186186 distance = self .__state .latest_block_slot - self .__state .slot
187187 return {
188188 "msg" : f"{ self .__state .publisher_name } hasn't published recently for { distance } slots." ,
@@ -195,7 +195,7 @@ def error_message(self) -> dict:
195195
196196
197197class PublisherPriceCheck (PublisherCheck ):
198- def __init__ (self , state : PublisherState , config : PublisherCheckConfig ):
198+ def __init__ (self , state : PublisherState , config : PublisherCheckConfig ) -> None :
199199 self .__state = state
200200 self .__max_aggregate_distance : int = int (config ["max_aggregate_distance" ]) # %
201201 self .__max_slot_distance : int = int (config ["max_slot_distance" ]) # Slots
@@ -230,7 +230,7 @@ def run(self) -> bool:
230230 # Fail
231231 return False
232232
233- def error_message (self ) -> dict :
233+ def error_message (self ) -> Dict [ str , Any ] :
234234 deviation = (self .ci_adjusted_price_diff () / self .__state .price_aggregate ) * 100
235235 return {
236236 "msg" : f"{ self .__state .publisher_name } price is too far from aggregate price." ,
@@ -250,7 +250,7 @@ def ci_adjusted_price_diff(self) -> float:
250250
251251
252252class PublisherStalledCheck (PublisherCheck ):
253- def __init__ (self , state : PublisherState , config : PublisherCheckConfig ):
253+ def __init__ (self , state : PublisherState , config : PublisherCheckConfig ) -> None :
254254 self .__state = state
255255 self .__stall_time_limit : int = int (
256256 config ["stall_time_limit" ]
@@ -313,7 +313,7 @@ def run(self) -> bool:
313313
314314 return not result .is_stalled
315315
316- def error_message (self ) -> dict :
316+ def error_message (self ) -> Dict [ str , Any ] :
317317 stall_duration = f"{ self .__last_analysis .duration :.1f} seconds"
318318 return {
319319 "msg" : f"{ self .__state .publisher_name } has been publishing the same price of { self .__state .symbol } for { stall_duration } " ,
0 commit comments