Skip to content

Commit 9716905

Browse files
authoredJul 25, 2022
add prev slot, price and conf to PythPriceAccount (#28)
1 parent 30303a1 commit 9716905

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed
 

‎pythclient/pythaccounts.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ def __init__(self, key: SolanaPublicKey, solana: SolanaClient, *, product: Optio
489489
self.derivations: Dict[EmaType, int] = {}
490490
self.timestamp: int = 0 # unix timestamp in seconds
491491
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)
492495
self.prev_timestamp: int = 0 # unix timestamp in seconds
493496

494497
@property
@@ -512,7 +515,7 @@ def aggregate_price_confidence_interval(self) -> Optional[float]:
512515
return self.aggregate_price_info.confidence_interval
513516
else:
514517
return None
515-
518+
516519
@property
517520
def aggregate_price_status(self) -> Optional[PythPriceStatus]:
518521
"""The aggregate price status."""
@@ -562,9 +565,11 @@ def update_from(self, buffer: bytes, *, version: int, offset: int = 0) -> None:
562565
timestamp, min_publishers = struct.unpack_from("<qB", buffer, offset)
563566
offset += 16 # struct.calcsize("qBbhi") ("bhi" is drv_2, drv_3, drv_4)
564567
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)
568573
elif version == _VERSION_1:
569574
price_type, exponent, num_components, _, last_slot, valid_slot, product_account_key_bytes, next_price_account_key_bytes, aggregator_key_bytes = struct.unpack_from(
570575
"<IiIIQQ32s32s32s", buffer, offset)
@@ -601,6 +606,9 @@ def update_from(self, buffer: bytes, *, version: int, offset: int = 0) -> None:
601606
self.price_components = price_components
602607
self.timestamp = timestamp
603608
self.min_publishers = min_publishers
609+
self.prev_slot = prev_slot
610+
self.prev_price = prev_price
611+
self.prev_conf = prev_conf
604612
self.prev_timestamp = prev_timestamp
605613

606614
def __str__(self) -> str:

0 commit comments

Comments
 (0)