-
Notifications
You must be signed in to change notification settings - Fork 297
feat(hip-3-pusher): Price fallback logic and staleness checks #3061
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
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
self.price_state.hl_oracle_price = ctx["oraclePx"] | ||
self.price_state.hl_mark_price = ctx["markPx"] | ||
logger.debug("on_activeAssetCtx: oraclePx: {} marketPx: {}", self.price_state.hl_oracle_price, self.price_state.hl_mark_price) | ||
self.price_state.latest_hl_timestamp = time.time() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would recommend storing the timestamp together with the price in one type to enforce they are updated together. something like
class PriceUpdate:
asset_id: str
price: float
timestamp: int
self.hermes_quote_exponent = config["hermes"]["quote_feed_exponent"] | ||
self.latest_hermes_timestamp = now | ||
|
||
def get_current_oracle_price(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth thinking through how this evolves as we need to support pushing multiple prices. Also, we might want to have this orchestration in a different module and split up the state to be managed by the individual data sources instead of a single mono-state.
# fall back to Hermes | ||
if self.hermes_base_price and self.hermes_quote_price: | ||
time_diff = now - self.latest_hermes_timestamp | ||
if time_diff < self.stale_price_threshold_seconds: | ||
return self.get_hermes_price() | ||
else: | ||
logger.error("Hermes price stale by {} seconds", time_diff) | ||
else: | ||
logger.error("Hermes base/quote prices not received yet") | ||
|
||
# fall back to Lazer | ||
if self.lazer_base_price and self.lazer_quote_price: | ||
time_diff = now - self.latest_lazer_timestamp | ||
if time_diff < self.stale_price_threshold_seconds: | ||
return self.get_lazer_price() | ||
else: | ||
logger.error("Lazer price stale by {} seconds", time_diff) | ||
else: | ||
logger.error("Lazer base/quote prices not received yet") | ||
|
||
logger.error("All prices missing or stale!") | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason we fall back to Hermes before Lazer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think I just mixed up the order you guys suggested for whatever reason. Dunno if currently we trust one more than the other.
|
||
mark_pxs = [] | ||
#if self.price_state.hl_mark_price: | ||
# mark_pxs.append({self.market_symbol: self.price_state.hl_mark_price}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not publish the mark prices?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They told us not to for now. Note that this will also include the actual HIP-3's market data in the calculation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are just mark prices for the HyperCore perps which are useful data points but separate.
hermes_urls = ["wss://hermes.pyth.network/ws"] | ||
base_feed_id = "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43" # BTC | ||
base_feed_exponent = -8 | ||
quote_feed_id = "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b" # USDT | ||
quote_feed_exponent = -8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll eventually need to split out the price config into its own file and source the metadata (like exponent) from the data sources themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, will need to scale this into a general set of prices and calcs.
Summary
Rationale
How has this been tested?