@@ -489,6 +489,9 @@ def __init__(self, key: SolanaPublicKey, solana: SolanaClient, *, product: Optio
489
489
self .derivations : Dict [EmaType , int ] = {}
490
490
self .timestamp : int = 0 # unix timestamp in seconds
491
491
self .min_publishers : Optional [int ] = None
492
+ self .prev_slot : int = 0
493
+ self .prev_price : float = field (init = False )
494
+ self .prev_conf : float = field (init = False )
492
495
self .prev_timestamp : int = 0 # unix timestamp in seconds
493
496
494
497
@property
@@ -512,7 +515,7 @@ def aggregate_price_confidence_interval(self) -> Optional[float]:
512
515
return self .aggregate_price_info .confidence_interval
513
516
else :
514
517
return None
515
-
518
+
516
519
@property
517
520
def aggregate_price_status (self ) -> Optional [PythPriceStatus ]:
518
521
"""The aggregate price status."""
@@ -562,9 +565,11 @@ def update_from(self, buffer: bytes, *, version: int, offset: int = 0) -> None:
562
565
timestamp , min_publishers = struct .unpack_from ("<qB" , buffer , offset )
563
566
offset += 16 # struct.calcsize("qBbhi") ("bhi" is drv_2, drv_3, drv_4)
564
567
product_account_key_bytes , next_price_account_key_bytes = struct .unpack_from ("32s32s" , buffer , offset )
565
- offset += 88 # struct.calcsize("32s32sQqQ") ("QqQ" is prev_slot, prev_price, prev_conf)
566
- prev_timestamp = struct .unpack_from ("<q" , buffer , offset )[0 ]
567
- offset += 8 # struct.calcsize("q")
568
+ offset += 64 # struct.calcsize("32s32s")
569
+ prev_slot , prev_price , prev_conf , prev_timestamp = struct .unpack_from ("<QqQq" , buffer , offset )
570
+ offset += 32 # struct.calcsize("QqQq")
571
+ prev_price *= (10 ** exponent )
572
+ prev_conf *= (10 ** exponent )
568
573
elif version == _VERSION_1 :
569
574
price_type , exponent , num_components , _ , last_slot , valid_slot , product_account_key_bytes , next_price_account_key_bytes , aggregator_key_bytes = struct .unpack_from (
570
575
"<IiIIQQ32s32s32s" , buffer , offset )
@@ -601,6 +606,9 @@ def update_from(self, buffer: bytes, *, version: int, offset: int = 0) -> None:
601
606
self .price_components = price_components
602
607
self .timestamp = timestamp
603
608
self .min_publishers = min_publishers
609
+ self .prev_slot = prev_slot
610
+ self .prev_price = prev_price
611
+ self .prev_conf = prev_conf
604
612
self .prev_timestamp = prev_timestamp
605
613
606
614
def __str__ (self ) -> str :
0 commit comments