@@ -193,6 +193,13 @@ def update_from(self, buffer: bytes, *, version: int, offset: int = 0) -> None:
193193 def __str__ (self ) -> str :
194194 return f"PythMappingAccount ({ self .key } )"
195195
196+ def to_json (self ):
197+
198+ return {
199+ 'entries' : [str (x ) for x in self .entries ],
200+ 'next_account_key' : str (self .next_account_key )
201+ }
202+
196203
197204class PythProductAccount (PythAccount ):
198205 """
@@ -350,6 +357,12 @@ def __iter__(self):
350357 if not key .startswith ('_' ):
351358 yield key , val
352359
360+ def to_json (self ):
361+
362+ return {
363+ 'symbol' : self .symbol ,
364+ }
365+
353366
354367@dataclass
355368class PythPriceInfo :
@@ -405,6 +418,19 @@ def __str__(self) -> str:
405418 def __repr__ (self ) -> str :
406419 return str (self )
407420
421+ def to_json (self ):
422+
423+ return {
424+ "price" : self .price ,
425+ "confidence_interval" : self .confidence_interval ,
426+ "price_status" : self .price_status .name ,
427+ "pub_slot" : self .pub_slot ,
428+ "exponent" : self .exponent ,
429+ "raw_confidence_interval" : self .raw_confidence_interval ,
430+ "raw_price" : self .raw_price
431+ }
432+
433+
408434
409435@dataclass
410436class PythPriceComponent :
@@ -449,6 +475,15 @@ def deserialise(buffer: bytes, offset: int = 0, *, exponent: int) -> Optional[Py
449475 latest_price = PythPriceInfo .deserialise (buffer , offset , exponent = exponent )
450476 return PythPriceComponent (key , last_aggregate_price , latest_price , exponent )
451477
478+ def to_json (self ):
479+
480+ return {
481+ "publisher_key" : str (self .publisher_key ),
482+ "last_aggregate_price_info" : self .last_aggregate_price_info .to_json (),
483+ "latest_price_info" : self .latest_price_info .to_json (),
484+ "exponent" : self .exponent
485+ }
486+
452487
453488class PythPriceAccount (PythAccount ):
454489 """
@@ -603,6 +638,25 @@ def __str__(self) -> str:
603638 else :
604639 return f"PythPriceAccount { self .price_type } ({ self .key } )"
605640
641+ def to_json (self ):
642+
643+ return {
644+ "product" : self .product .to_json () if self .product else None ,
645+ "price_type" : self .price_type .name ,
646+ "exponent" : self .exponent ,
647+ "num_components" : self .num_components ,
648+ "last_slot" : self .last_slot ,
649+ "valid_slot" : self .valid_slot ,
650+ "product_account_key" : str (self .product_account_key ),
651+ "next_price_account_key" : str (self .next_price_account_key ),
652+ "aggregate_price_info" : self .aggregate_price_info .to_json () if self .aggregate_price_info else None ,
653+ "price_components" : [x .to_json () for x in self .price_components ],
654+ "derivations" : {EmaType (x ).name : self .derivations .get (x ) for x in list (self .derivations .keys ())},
655+ "min_publishers" : self .min_publishers ,
656+ "aggregate_price" : self .aggregate_price ,
657+ "aggregate_price_confidence_interval" : self .aggregate_price_confidence_interval
658+ }
659+
606660
607661_ACCOUNT_TYPE_TO_CLASS = {
608662 PythAccountType .MAPPING : PythMappingAccount ,
0 commit comments