Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change twap/twac to emap/emac #23

Merged
merged 2 commits into from
Mar 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions pythclient/pythaccounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,17 @@ class PythPriceStatus(Enum):
class PythPriceType(Enum):
UNKNOWN = 0
PRICE = 1
# TWAP/VOL removed after V2
TWAP = 2
VOLATILITY = 3


# Join time-weighted exponential moving average for TWAP and TWAC
class TwEmaType(Enum):
# Join exponential moving average for EMA price and EMA confidence
class EmaType(Enum):
UNKNOWN = 0
TWAPVALUE = 1
TWAPNUMERATOR = 2
TWAPDENOMINATOR = 3
TWACVALUE = 4
TWACNUMERATOR = 5
TWACDENOMINATOR = 6
EMA_PRICE_VALUE = 1
EMA_PRICE_NUMERATOR = 2
EMA_PRICE_DENOMINATOR = 3
EMA_CONFIDENCE_VALUE = 4
EMA_CONFIDENCE_NUMERATOR = 5
EMA_CONFIDENCE_DENOMINATOR = 6


def _check_base64(format: str):
Expand Down Expand Up @@ -489,7 +486,7 @@ def __init__(self, key: SolanaPublicKey, solana: SolanaClient, *, product: Optio
self.next_price_account_key: Optional[SolanaPublicKey] = None
self.aggregate_price_info: Optional[PythPriceInfo] = None
self.price_components: List[PythPriceComponent] = []
self.derivations: Dict[TwEmaType, int] = {}
self.derivations: Dict[EmaType, int] = {}
self.min_publishers: Optional[int] = None

@property
Expand Down Expand Up @@ -557,7 +554,7 @@ def update_from(self, buffer: bytes, *, version: int, offset: int = 0) -> None:
last_slot, valid_slot = struct.unpack_from("<QQ", buffer, offset)
offset += 16 # QQ
derivations = list(struct.unpack_from("<6q", buffer, offset))
self.derivations = dict((type_, derivations[type_.value - 1]) for type_ in [TwEmaType.TWACVALUE, TwEmaType.TWAPVALUE])
self.derivations = dict((type_, derivations[type_.value - 1]) for type_ in [EmaType.EMA_CONFIDENCE_VALUE, EmaType.EMA_PRICE_VALUE])
offset += 48 # 6q
# All drv*_ fields sans min_publishers are currently unused
_, min_publishers = struct.unpack_from("<qQ", buffer, offset)
Expand Down