Skip to content

fix zero division error in PriceDeviation when aggregate price is 0 #10

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

Merged
merged 10 commits into from
Feb 7, 2022

Conversation

cctdaniel
Copy link
Contributor

  • program crashes when aggregate price is 0 as it tries to divide delta (publisher aggregate price - aggregate price) by aggregate price
  • not sure what's the best way to handle this case but what I did here was to return False if aggregate price is 0 (happy to get suggestions if there are better alternatives)

@cctdaniel cctdaniel self-assigned this Feb 3, 2022
@cctdaniel
Copy link
Contributor Author

to reproduce error, run with devnet as network arg

@SEJeff SEJeff self-requested a review February 3, 2022 08:06
Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm approving this, but please delete the dead code before merging.

details = [
f"Aggregate: {agg.price:.2f} ± {agg.confidence_interval:.2f} (slot {agg.slot})",
f"Published: {published.price:.2f} ± {published.confidence_interval:.2f} (slot {published.slot})",
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case won't ever trigger. The event details are only printed if is_valid == True. I think it makes sense to separate out the validation of the aggregate price into a separate PriceValidationEvent though, so no need for this case here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it triggers when I run the program locally -- I don't see the is_valid == True check in the code, are you able to point me to the right direction?

Copy link

@SEJeff SEJeff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't normally run this against devnet since that's just a throwaway playground for publishers to test things out. We use testnet as a UAT environment and then obviously mainnet is production.

However, this is a good addition. Nice job. I originally didn't want the events to change the title based on the data, but for PriceDeviation it makes sense to do things the way you did I think.

@@ -232,6 +242,8 @@ def get_event_details(self) -> Tuple[str, List[str]]:
f"Published last slot: {self.publisher_latest.slot}"
)

return title, details
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye!

@cctdaniel cctdaniel merged commit 674dad3 into main Feb 7, 2022
@cctdaniel cctdaniel deleted the fix/zero_division_error branch February 7, 2022 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants