Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ignore_missing_imports = true

[tool.poetry]
name = "pyth-observer"
version = "0.1.2"
version = "0.1.3"
description = "Alerts and stuff"
authors = []
readme = "README.md"
Expand Down
25 changes: 21 additions & 4 deletions pyth_observer/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@


class HolidayCalendar:
def is_market_open(self, asset_type, dt):
# equity market
def is_market_open(self, asset_type: str, dt: datetime.datetime):
Copy link
Contributor

Choose a reason for hiding this comment

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

For the record, the quantlib library (which has Python bindings) has a robust implementation of "is the market open?" for markets across many countries (e.g. see this).

day, date, time = dt.weekday(), dt.date(), dt.time()

if asset_type == "Equity":
day, date, time = dt.weekday(), dt.date(), dt.time()
if date in EQUITY_HOLIDAYS or date in EQUITY_EARLY_HOLIDAYS:
if (
date in EQUITY_EARLY_HOLIDAYS
Expand All @@ -45,5 +45,22 @@ def is_market_open(self, asset_type, dt):
if day < 5 and time >= EQUITY_OPEN and time <= EQUITY_CLOSE:
return True
return False
# all other markets (crypto, fx, metal)

if asset_type in ["FX", "Metal"]:
# The market for FX and Metal is closed from Friday 5pm to Sunday 5pm
close_or_open_time = datetime.time(17, 0, 0, tzinfo=TZ)

# Friday the market is close after 5pm
if day == 4 and time > close_or_open_time:
return False
# Saturday the market is closed all the time
if day == 5:
return False
# Sunday the market is closed before 5pm
if day == 6 and time < close_or_open_time:
return False

return True

# all other markets (crypto)
return True
4 changes: 2 additions & 2 deletions pyth_observer/check/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def error_message(self) -> str:
{self.__state.publisher_name} price is too far from aggregate price.

Symbol: {self.__state.symbol}
Publisher price: {self.__state.price}
Aggregate price: {self.__state.price_aggregate}
Publisher price: {self.__state.price} ± {self.__state.confidence_interval}
Aggregate price: {self.__state.price_aggregate} ± {self.__state.confidence_interval_aggregate}
Deviation: {deviation}%
"""
).strip()
Expand Down