@@ -25,7 +25,7 @@ class PriceFeedState:
2525 confidence_interval_aggregate : float
2626 coingecko_price : Optional [float ]
2727 coingecko_update : Optional [int ]
28- crosschain_price : CrosschainPrice
28+ crosschain_price : Optional [ CrosschainPrice ]
2929
3030
3131PriceFeedCheckConfig = Dict [str , str | float | int | bool ]
@@ -181,10 +181,6 @@ def run(self) -> bool:
181181 if self .__state .status != PythPriceStatus .TRADING :
182182 return True
183183
184- # Skip if publish time is zero
185- if not self .__state .crosschain_price ["publish_time" ]:
186- return True
187-
188184 is_market_open = HolidayCalendar ().is_market_open (
189185 self .__state .asset_type ,
190186 datetime .datetime .now (tz = pytz .timezone ("America/New_York" )),
@@ -194,6 +190,14 @@ def run(self) -> bool:
194190 if not is_market_open :
195191 return True
196192
193+ # Price should exist, it fails otherwise
194+ if not self .__state .crosschain_price :
195+ return False
196+
197+ # Skip if publish time is zero
198+ if not self .__state .crosschain_price ["publish_time" ]:
199+ return True
200+
197201 staleness = int (time .time ()) - self .__state .crosschain_price ["publish_time" ]
198202
199203 # Pass if current staleness is less than `max_staleness`
@@ -204,7 +208,10 @@ def run(self) -> bool:
204208 return False
205209
206210 def error_message (self ) -> str :
207- publish_time = arrow .get (self .__state .crosschain_price ["publish_time" ])
211+ if self .__state .crosschain_price :
212+ publish_time = arrow .get (self .__state .crosschain_price ["publish_time" ])
213+ else :
214+ publish_time = arrow .get (0 )
208215
209216 return dedent (
210217 f"""
@@ -225,6 +232,10 @@ def state(self) -> PriceFeedState:
225232 return self .__state
226233
227234 def run (self ) -> bool :
235+ # Skip if does not exist
236+ if not self .__state .crosschain_price :
237+ return True
238+
228239 # Skip if not trading
229240 if self .__state .status != PythPriceStatus .TRADING :
230241 return True
@@ -257,12 +268,18 @@ def run(self) -> bool:
257268 return False
258269
259270 def error_message (self ) -> str :
271+ # It can never happen because of the check logic but linter could not understand it.
272+ price = (
273+ self .__state .crosschain_price ["price" ]
274+ if self .__state .crosschain_price
275+ else None
276+ )
260277 return dedent (
261278 f"""
262279 { self .__state .symbol } is too far at the price service.
263280
264281 Price: { self .__state .price_aggregate }
265- Price at price service: { self . __state . crosschain_price [ ' price' ] }
282+ Price at price service: { price }
266283 """
267284 ).strip ()
268285
0 commit comments