-
Notifications
You must be signed in to change notification settings - Fork 7
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1991051
fix zero division error in PriceDeviation when aggregate price is 0
cctdaniel df891d7
set deviation number to 0 when aggregate price is 0
cctdaniel 974e4d4
remove deviation = 0 when aggregate price is 0 and add new clause to …
cctdaniel a748e8e
check for aggregate price = 0 instead of deviation att for event details
cctdaniel 05cb619
remove $ on event details for PriceDeviation
cctdaniel a90dc31
add return value for get_event_details of StoppedPublishing class
cctdaniel 5b7d543
add todo
cctdaniel 966b4e1
Update pyth_observer/events.py
cctdaniel 188c333
return true for pricedeviation if aggregate price is 0
cctdaniel b0e7e68
remove else indent in PriceDeviation
cctdaniel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import datetime | ||
|
||
EQUITY_START = datetime.time(9, 30, 0) | ||
EQUITY_CLOSE = datetime.time(16, 0, 0) | ||
EQUITY_EARLY_CLOSE = datetime.time(13, 0, 0) | ||
EQUITY_HOLIDAYS = ["2022-01-17", "2022-02-21", "2022-04-15", "2022-05-30", | ||
"2022-06-20", "2022-07-04", "2022-09-05", "2022-11-24", "2022-11-25", "2022-12-26"] | ||
EQUITY_HOLIDAYS_EARLY = ["2022-11-25"] | ||
EQUITY_TRADING_DAYS = [1, 2, 3, 4, 5] | ||
|
||
FX_START = datetime.time(17, 0, 0) | ||
FX_CLOSE = datetime.time(16, 0, 0) | ||
FX_TRADING_DAYS = [7, 1, 2, 3, 4, 5] | ||
|
||
METAL_START = datetime.time(18, 3, 0) | ||
METAL_CLOSE = datetime.time(16, 58, 0) | ||
METAL_TRADING_DAYS = [7, 1, 2, 3, 4, 5] | ||
|
||
|
||
class Calendar: | ||
def is_market_open(self, product, dt): | ||
day, date, time = dt.weekday(), dt.date(), dt.time() | ||
if product.attrs["asset_type"] == "Equity": | ||
# market holiday | ||
if date.strftime("%Y-%m-%d") in EQUITY_HOLIDAYS: | ||
# market within early closing hours | ||
if date.strftime("%Y-%m-%d") in EQUITY_HOLIDAYS_EARLY and time >= EQUITY_START and time <= EQUITY_EARLY_CLOSE: | ||
breakpoint() | ||
return True | ||
# market after holiday closing hours | ||
return False | ||
# market within regular opening hours | ||
if day in EQUITY_TRADING_DAYS and time >= EQUITY_START and time <= EQUITY_CLOSE: | ||
return True | ||
# market closed | ||
return False | ||
elif product.attrs["asset_type"] == "FX": | ||
if day in FX_TRADING_DAYS: | ||
if (day == 7 and time < FX_START) or (day == 5 and time > FX_CLOSE): | ||
return False | ||
return True | ||
return False | ||
elif product.attrs["asset_type"] == "Metal": | ||
pass | ||
else: # Crypto | ||
return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,6 +185,10 @@ class PriceDeviation(PriceValidationEvent): | |
|
||
def is_valid(self) -> bool: | ||
delta = self.publisher_aggregate.price - self.price.aggregate.price | ||
if self.price.aggregate.price == 0: | ||
# TODO: add another alert that validates whether the aggregate price is close to the truth | ||
return True | ||
|
||
self.deviation = abs(delta / self.price.aggregate.price) * 100 | ||
|
||
if (self.price.is_publishing(self.publisher_key) and | ||
|
@@ -196,7 +200,6 @@ def is_valid(self) -> bool: | |
def get_event_details(self) -> Tuple[str, List[str]]: | ||
agg = self.price.aggregate | ||
published = self.publisher_aggregate | ||
|
||
title = f"{self.publisher_name.upper()} price is {self.deviation:.0f}% off on {self.symbol}" | ||
details = [ | ||
f"Aggregate: {agg.price:.2f} ± {agg.confidence_interval:.2f} (slot {agg.slot})", | ||
|
@@ -232,6 +235,8 @@ def get_event_details(self) -> Tuple[str, List[str]]: | |
f"Published last slot: {self.publisher_latest.slot}" | ||
) | ||
|
||
return title, details | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good eye! |
||
|
||
|
||
# Price Account events | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.