From 75c08293c585e8e9088c13bd3af51fe0b8b5efd4 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Fri, 11 Apr 2025 10:28:39 +0900 Subject: [PATCH] chore: update pythclient to version 0.2.1 and integrate MarketSchedule for price feed checks --- poetry.lock | 9 ++++----- pyproject.toml | 2 +- pyth_observer/__init__.py | 3 +++ pyth_observer/check/price_feed.py | 12 +++++------- pyth_observer/check/publisher.py | 9 ++++----- tests/test_checks_price_feed.py | 2 ++ tests/test_checks_publisher.py | 2 ++ 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/poetry.lock b/poetry.lock index 14ed276..9f219b6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1588,13 +1588,13 @@ dev = ["pre-commit", "pytest-asyncio", "tox"] [[package]] name = "pythclient" -version = "0.1.24" +version = "0.2.1" description = "A library to retrieve Pyth account structures off the Solana blockchain." optional = false python-versions = ">=3.9.0" files = [ - {file = "pythclient-0.1.24-py3-none-any.whl", hash = "sha256:e31641579de99ffc29cc7b5399856875bd51fc7d65dedc941223b42c645238c6"}, - {file = "pythclient-0.1.24.tar.gz", hash = "sha256:c037665e82a68be84148165e1f0d5916b933e751cc87bd07749fa825cd5dbc19"}, + {file = "pythclient-0.2.1-py3-none-any.whl", hash = "sha256:d31344abdfa3c02e7dd887c259223807902d8dbd03dafddaaa324010230456bd"}, + {file = "pythclient-0.2.1.tar.gz", hash = "sha256:43265b808465fd7503cd10a18549c14d84d34a5df60d567df63906fe83ef2601"}, ] [package.dependencies] @@ -1677,7 +1677,6 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -2103,4 +2102,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "f7bfd1509c9fc61ae0cc624b8b0c4b8f127ed6c71bb5d3db6195af9d1b45f592" +content-hash = "66bfd35d3ba30747800e7c206fca29289530fac1e7d77fb6b288c218b70f6045" diff --git a/pyproject.toml b/pyproject.toml index 690003d..7d23e79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ loguru = "^0.6.0" more-itertools = "^9.0.0" prometheus-client = "0.15.0" pycoingecko = "2.2.0" -pythclient = "^0.1.24" +pythclient = "^0.2.1" pyyaml = "^6.0" throttler = "1.2.1" types-pyyaml = "^6.0.12" diff --git a/pyth_observer/__init__.py b/pyth_observer/__init__.py index 79d8fc0..4655575 100644 --- a/pyth_observer/__init__.py +++ b/pyth_observer/__init__.py @@ -4,6 +4,7 @@ from base58 import b58decode from loguru import logger +from pythclient.market_schedule import MarketSchedule from pythclient.pythaccounts import PythPriceAccount, PythPriceType, PythProductAccount from pythclient.pythclient import PythClient from pythclient.solana import ( @@ -120,6 +121,7 @@ async def run(self): PriceFeedState( symbol=product.attrs["symbol"], asset_type=product.attrs["asset_type"], + schedule=MarketSchedule(product.attrs["schedule"]), public_key=price_account.key, status=price_account.aggregate_price_status, # this is the solana block slot when price account was fetched @@ -146,6 +148,7 @@ async def run(self): publisher_name=publisher_name, symbol=product.attrs["symbol"], asset_type=product.attrs["asset_type"], + schedule=MarketSchedule(product.attrs["schedule"]), public_key=component.publisher_key, confidence_interval=component.latest_price_info.confidence_interval, confidence_interval_aggregate=price_account.aggregate_price_info.confidence_interval, diff --git a/pyth_observer/check/price_feed.py b/pyth_observer/check/price_feed.py index cd8bbb0..75f8063 100644 --- a/pyth_observer/check/price_feed.py +++ b/pyth_observer/check/price_feed.py @@ -5,7 +5,7 @@ from zoneinfo import ZoneInfo import arrow -from pythclient.calendar import is_market_open +from pythclient.market_schedule import MarketSchedule from pythclient.pythaccounts import PythPriceStatus from pythclient.solana import SolanaPublicKey @@ -16,6 +16,7 @@ class PriceFeedState: symbol: str asset_type: str + schedule: MarketSchedule public_key: SolanaPublicKey status: PythPriceStatus latest_block_slot: int @@ -55,8 +56,7 @@ def state(self) -> PriceFeedState: return self.__state def run(self) -> bool: - market_open = is_market_open( - self.__state.asset_type.lower(), + market_open = self.__state.schedule.is_market_open( datetime.now(ZoneInfo("America/New_York")), ) @@ -176,8 +176,7 @@ def run(self) -> bool: if self.__state.status != PythPriceStatus.TRADING: return True - market_open = is_market_open( - self.__state.asset_type.lower(), + market_open = self.__state.schedule.is_market_open( datetime.now(ZoneInfo("America/New_York")), ) @@ -237,8 +236,7 @@ def run(self) -> bool: if self.__state.status != PythPriceStatus.TRADING: return True - market_open = is_market_open( - self.__state.asset_type.lower(), + market_open = self.__state.schedule.is_market_open( datetime.now(ZoneInfo("America/New_York")), ) diff --git a/pyth_observer/check/publisher.py b/pyth_observer/check/publisher.py index 6a20ad4..8536d53 100644 --- a/pyth_observer/check/publisher.py +++ b/pyth_observer/check/publisher.py @@ -6,7 +6,7 @@ from zoneinfo import ZoneInfo from loguru import logger -from pythclient.calendar import is_market_open +from pythclient.market_schedule import MarketSchedule from pythclient.pythaccounts import PythPriceStatus from pythclient.solana import SolanaPublicKey @@ -36,6 +36,7 @@ class PublisherState: publisher_name: str symbol: str asset_type: str + schedule: MarketSchedule public_key: SolanaPublicKey status: PythPriceStatus aggregate_status: PythPriceStatus @@ -161,8 +162,7 @@ def state(self) -> PublisherState: return self.__state def run(self) -> bool: - market_open = is_market_open( - self.__state.asset_type.lower(), + market_open = self.__state.schedule.is_market_open( datetime.now(ZoneInfo("America/New_York")), ) @@ -272,8 +272,7 @@ def state(self) -> PublisherState: return self.__state def run(self) -> bool: - market_open = is_market_open( - self.__state.asset_type.lower(), + market_open = self.__state.schedule.is_market_open( datetime.now(ZoneInfo("America/New_York")), ) diff --git a/tests/test_checks_price_feed.py b/tests/test_checks_price_feed.py index 03b4135..b774c7a 100644 --- a/tests/test_checks_price_feed.py +++ b/tests/test_checks_price_feed.py @@ -1,3 +1,4 @@ +from pythclient.market_schedule import MarketSchedule from pythclient.pythaccounts import PythPriceStatus from pythclient.solana import SolanaPublicKey @@ -8,6 +9,7 @@ def test_price_feed_offline_check(): state = PriceFeedState( symbol="Crypto.BTC/USD", asset_type="Crypto", + schedule=MarketSchedule("America/New_York;O,O,O,O,O,O,O;"), public_key=SolanaPublicKey("2hgu6Umyokvo8FfSDdMa9nDKhcdv9Q4VvGNhRCeSWeD3"), status=PythPriceStatus.TRADING, latest_block_slot=100, diff --git a/tests/test_checks_publisher.py b/tests/test_checks_publisher.py index 4676b1f..156b986 100644 --- a/tests/test_checks_publisher.py +++ b/tests/test_checks_publisher.py @@ -3,6 +3,7 @@ from unittest.mock import patch import pytest +from pythclient.market_schedule import MarketSchedule from pythclient.pythaccounts import PythPriceStatus from pythclient.solana import SolanaPublicKey @@ -29,6 +30,7 @@ def make_publisher_state( publisher_name="publisher", symbol=symbol, asset_type=asset_type, + schedule=MarketSchedule("America/New_York;O,O,O,O,O,O,O;"), public_key=SolanaPublicKey("2hgu6Umyokvo8FfSDdMa9nDKhcdv9Q4VvGNhRCeSWeD3"), status=PythPriceStatus.TRADING, aggregate_status=PythPriceStatus.TRADING,