@@ -25,7 +25,7 @@ class PriceFeedState:
25
25
confidence_interval_aggregate : float
26
26
coingecko_price : Optional [float ]
27
27
coingecko_update : Optional [int ]
28
- crosschain_price : CrosschainPrice
28
+ crosschain_price : Optional [ CrosschainPrice ]
29
29
30
30
31
31
PriceFeedCheckConfig = Dict [str , str | float | int | bool ]
@@ -181,10 +181,6 @@ def run(self) -> bool:
181
181
if self .__state .status != PythPriceStatus .TRADING :
182
182
return True
183
183
184
- # Skip if publish time is zero
185
- if not self .__state .crosschain_price ["publish_time" ]:
186
- return True
187
-
188
184
is_market_open = HolidayCalendar ().is_market_open (
189
185
self .__state .asset_type ,
190
186
datetime .datetime .now (tz = pytz .timezone ("America/New_York" )),
@@ -194,6 +190,14 @@ def run(self) -> bool:
194
190
if not is_market_open :
195
191
return True
196
192
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
+
197
201
staleness = int (time .time ()) - self .__state .crosschain_price ["publish_time" ]
198
202
199
203
# Pass if current staleness is less than `max_staleness`
@@ -204,7 +208,10 @@ def run(self) -> bool:
204
208
return False
205
209
206
210
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 )
208
215
209
216
return dedent (
210
217
f"""
@@ -225,6 +232,10 @@ def state(self) -> PriceFeedState:
225
232
return self .__state
226
233
227
234
def run (self ) -> bool :
235
+ # Skip if does not exist
236
+ if not self .__state .crosschain_price :
237
+ return True
238
+
228
239
# Skip if not trading
229
240
if self .__state .status != PythPriceStatus .TRADING :
230
241
return True
@@ -257,12 +268,18 @@ def run(self) -> bool:
257
268
return False
258
269
259
270
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
+ )
260
277
return dedent (
261
278
f"""
262
279
{ self .__state .symbol } is too far at the price service.
263
280
264
281
Price: { self .__state .price_aggregate }
265
- Price at price service: { self . __state . crosschain_price [ ' price' ] }
282
+ Price at price service: { price }
266
283
"""
267
284
).strip ()
268
285
0 commit comments