Skip to content

Commit 9824763

Browse files
authoredMar 17, 2022
Merge pull request #1 from tnedev/update_to_json
Update to json
2 parents 805c08f + 9ee2e32 commit 9824763

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed
 

‎pythclient/pythaccounts.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,17 @@ class PythPriceStatus(Enum):
3737
class PythPriceType(Enum):
3838
UNKNOWN = 0
3939
PRICE = 1
40-
# TWAP/VOL removed after V2
41-
TWAP = 2
42-
VOLATILITY = 3
4340

4441

45-
# Join time-weighted exponential moving average for TWAP and TWAC
46-
class TwEmaType(Enum):
42+
# Join exponential moving average for EMA price and EMA confidence
43+
class EmaType(Enum):
4744
UNKNOWN = 0
48-
TWAPVALUE = 1
49-
TWAPNUMERATOR = 2
50-
TWAPDENOMINATOR = 3
51-
TWACVALUE = 4
52-
TWACNUMERATOR = 5
53-
TWACDENOMINATOR = 6
45+
EMA_PRICE_VALUE = 1
46+
EMA_PRICE_NUMERATOR = 2
47+
EMA_PRICE_DENOMINATOR = 3
48+
EMA_CONFIDENCE_VALUE = 4
49+
EMA_CONFIDENCE_NUMERATOR = 5
50+
EMA_CONFIDENCE_DENOMINATOR = 6
5451

5552

5653
def _check_base64(format: str):
@@ -524,7 +521,7 @@ def __init__(self, key: SolanaPublicKey, solana: SolanaClient, *, product: Optio
524521
self.next_price_account_key: Optional[SolanaPublicKey] = None
525522
self.aggregate_price_info: Optional[PythPriceInfo] = None
526523
self.price_components: List[PythPriceComponent] = []
527-
self.derivations: Dict[TwEmaType, int] = {}
524+
self.derivations: Dict[EmaType, int] = {}
528525
self.min_publishers: Optional[int] = None
529526

530527
@property
@@ -592,7 +589,7 @@ def update_from(self, buffer: bytes, *, version: int, offset: int = 0) -> None:
592589
last_slot, valid_slot = struct.unpack_from("<QQ", buffer, offset)
593590
offset += 16 # QQ
594591
derivations = list(struct.unpack_from("<6q", buffer, offset))
595-
self.derivations = dict((type_, derivations[type_.value - 1]) for type_ in [TwEmaType.TWACVALUE, TwEmaType.TWAPVALUE])
592+
self.derivations = dict((type_, derivations[type_.value - 1]) for type_ in [EmaType.EMA_CONFIDENCE_VALUE, EmaType.EMA_PRICE_VALUE])
596593
offset += 48 # 6q
597594
# All drv*_ fields sans min_publishers are currently unused
598595
_, min_publishers = struct.unpack_from("<qQ", buffer, offset)
@@ -654,7 +651,7 @@ def to_json(self):
654651
"next_price_account_key": str(self.next_price_account_key),
655652
"aggregate_price_info": self.aggregate_price_info.to_json(),
656653
"price_components": [x.to_json() for x in self.price_components],
657-
"derivations": {TwEmaType(x).name: self.derivations.get(x) for x in list(self.derivations.keys())},
654+
"derivations": {EmaType(x).name: self.derivations.get(x) for x in list(self.derivations.keys())},
658655
"min_publishers": self.min_publishers,
659656
"aggregate_price": self.aggregate_price,
660657
"aggregate_price_confidence_interval": self.aggregate_price_confidence_interval

0 commit comments

Comments
 (0)
Please sign in to comment.