-
Notifications
You must be signed in to change notification settings - Fork 38
Fix realized last price missing #247
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
Changes from all commits
a014cff
4f1681e
0b69e6b
3d9dd15
193c9fc
6782d73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,29 +72,41 @@ def fetch_data(self, validator_request: ValidatorRequest) -> list: | |
| """ | ||
| asset = str(validator_request.asset) | ||
|
|
||
| if asset in self.HYPERLIQUID_SYMBOL_MAP: | ||
| return self.fetch_data_hyperliquid(validator_request) | ||
| prices = [] | ||
|
|
||
| start_time_int = from_iso_to_unix_time( | ||
| validator_request.start_time.isoformat() | ||
| ) | ||
| params = { | ||
| "symbol": self.PYTH_SYMBOL_MAP[asset], | ||
| "resolution": 1, | ||
| "from": start_time_int, | ||
| "to": start_time_int + validator_request.time_length, | ||
| } | ||
| if asset in self.HYPERLIQUID_SYMBOL_MAP: | ||
| prices = self.fetch_data_hyperliquid(validator_request) | ||
| else: | ||
| start_time_int = from_iso_to_unix_time( | ||
| validator_request.start_time.isoformat() | ||
| ) | ||
| params = { | ||
| "symbol": self.PYTH_SYMBOL_MAP[asset], | ||
| "resolution": 1, | ||
| "from": start_time_int, | ||
| "to": start_time_int + validator_request.time_length, | ||
| } | ||
|
|
||
| response = requests.get(self.PYTH_BASE_URL, params=params) | ||
| response.raise_for_status() | ||
| data = response.json() | ||
|
|
||
| prices = self._transform_data( | ||
| data, | ||
| start_time_int, | ||
| int(validator_request.time_increment), | ||
| int(validator_request.time_length), | ||
| ) | ||
|
|
||
| response = requests.get(self.PYTH_BASE_URL, params=params) | ||
| response.raise_for_status() | ||
| data = response.json() | ||
| if not prices or np.isnan(prices[-1]): | ||
| bt.logging.warning( | ||
| f"missing price data for the last timestamp for asset {asset} in request {validator_request.id}" | ||
| ) | ||
| raise ValueError( | ||
| f"missing price data for the last timestamp for asset {asset} in request {validator_request.id}" | ||
| ) | ||
|
Comment on lines
+105
to
+107
|
||
|
|
||
| return self._transform_data( | ||
| data, | ||
| start_time_int, | ||
| int(validator_request.time_increment), | ||
| int(validator_request.time_length), | ||
| ) | ||
| return prices | ||
|
|
||
| def fetch_data_hyperliquid( | ||
| self, validator_request: ValidatorRequest | ||
|
|
@@ -194,6 +206,9 @@ def _transform_data( | |
| if len(timestamps) != int(time_length / time_increment) + 1: | ||
| # Note: this part of code should never be activated; just included for precaution | ||
| if len(timestamps) == int(time_length / time_increment) + 2: | ||
| bt.logging.warning( | ||
| f"Unexpected number of timestamps generated. Expected {int(time_length / time_increment) + 1} but got {len(timestamps)}. Adjusting the timestamps list by removing the extra timestamp." | ||
| ) | ||
| if data["t"][-1] < timestamps[1]: | ||
| timestamps = timestamps[:-1] | ||
| elif data["t"][0] > timestamps[0]: | ||
|
|
||
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.
self.first_runis now set toFalseeven whenrun_cycle()raises. Previously it was only flipped after a successful cycle; with this change, a failed initial cycle will be treated as a subsequent run, which changes the delay calculation and can slow down recovery/retry scheduling. Consider only settingfirst_run = Falseafterrun_cycle()completes successfully (or track success explicitly).