Skip to content

Commit c88073b

Browse files
authored
chore: update pythclient to version 0.2.1 and integrate MarketSchedule for price feed checks (#88)
1 parent 48637db commit c88073b

File tree

7 files changed

+21
-18
lines changed

7 files changed

+21
-18
lines changed

poetry.lock

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ loguru = "^0.6.0"
2121
more-itertools = "^9.0.0"
2222
prometheus-client = "0.15.0"
2323
pycoingecko = "2.2.0"
24-
pythclient = "^0.1.24"
24+
pythclient = "^0.2.1"
2525
pyyaml = "^6.0"
2626
throttler = "1.2.1"
2727
types-pyyaml = "^6.0.12"

pyth_observer/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from base58 import b58decode
66
from loguru import logger
7+
from pythclient.market_schedule import MarketSchedule
78
from pythclient.pythaccounts import PythPriceAccount, PythPriceType, PythProductAccount
89
from pythclient.pythclient import PythClient
910
from pythclient.solana import (
@@ -120,6 +121,7 @@ async def run(self):
120121
PriceFeedState(
121122
symbol=product.attrs["symbol"],
122123
asset_type=product.attrs["asset_type"],
124+
schedule=MarketSchedule(product.attrs["schedule"]),
123125
public_key=price_account.key,
124126
status=price_account.aggregate_price_status,
125127
# this is the solana block slot when price account was fetched
@@ -146,6 +148,7 @@ async def run(self):
146148
publisher_name=publisher_name,
147149
symbol=product.attrs["symbol"],
148150
asset_type=product.attrs["asset_type"],
151+
schedule=MarketSchedule(product.attrs["schedule"]),
149152
public_key=component.publisher_key,
150153
confidence_interval=component.latest_price_info.confidence_interval,
151154
confidence_interval_aggregate=price_account.aggregate_price_info.confidence_interval,

pyth_observer/check/price_feed.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from zoneinfo import ZoneInfo
66

77
import arrow
8-
from pythclient.calendar import is_market_open
8+
from pythclient.market_schedule import MarketSchedule
99
from pythclient.pythaccounts import PythPriceStatus
1010
from pythclient.solana import SolanaPublicKey
1111

@@ -16,6 +16,7 @@
1616
class PriceFeedState:
1717
symbol: str
1818
asset_type: str
19+
schedule: MarketSchedule
1920
public_key: SolanaPublicKey
2021
status: PythPriceStatus
2122
latest_block_slot: int
@@ -55,8 +56,7 @@ def state(self) -> PriceFeedState:
5556
return self.__state
5657

5758
def run(self) -> bool:
58-
market_open = is_market_open(
59-
self.__state.asset_type.lower(),
59+
market_open = self.__state.schedule.is_market_open(
6060
datetime.now(ZoneInfo("America/New_York")),
6161
)
6262

@@ -176,8 +176,7 @@ def run(self) -> bool:
176176
if self.__state.status != PythPriceStatus.TRADING:
177177
return True
178178

179-
market_open = is_market_open(
180-
self.__state.asset_type.lower(),
179+
market_open = self.__state.schedule.is_market_open(
181180
datetime.now(ZoneInfo("America/New_York")),
182181
)
183182

@@ -237,8 +236,7 @@ def run(self) -> bool:
237236
if self.__state.status != PythPriceStatus.TRADING:
238237
return True
239238

240-
market_open = is_market_open(
241-
self.__state.asset_type.lower(),
239+
market_open = self.__state.schedule.is_market_open(
242240
datetime.now(ZoneInfo("America/New_York")),
243241
)
244242

pyth_observer/check/publisher.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from zoneinfo import ZoneInfo
77

88
from loguru import logger
9-
from pythclient.calendar import is_market_open
9+
from pythclient.market_schedule import MarketSchedule
1010
from pythclient.pythaccounts import PythPriceStatus
1111
from pythclient.solana import SolanaPublicKey
1212

@@ -36,6 +36,7 @@ class PublisherState:
3636
publisher_name: str
3737
symbol: str
3838
asset_type: str
39+
schedule: MarketSchedule
3940
public_key: SolanaPublicKey
4041
status: PythPriceStatus
4142
aggregate_status: PythPriceStatus
@@ -161,8 +162,7 @@ def state(self) -> PublisherState:
161162
return self.__state
162163

163164
def run(self) -> bool:
164-
market_open = is_market_open(
165-
self.__state.asset_type.lower(),
165+
market_open = self.__state.schedule.is_market_open(
166166
datetime.now(ZoneInfo("America/New_York")),
167167
)
168168

@@ -272,8 +272,7 @@ def state(self) -> PublisherState:
272272
return self.__state
273273

274274
def run(self) -> bool:
275-
market_open = is_market_open(
276-
self.__state.asset_type.lower(),
275+
market_open = self.__state.schedule.is_market_open(
277276
datetime.now(ZoneInfo("America/New_York")),
278277
)
279278

tests/test_checks_price_feed.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pythclient.market_schedule import MarketSchedule
12
from pythclient.pythaccounts import PythPriceStatus
23
from pythclient.solana import SolanaPublicKey
34

@@ -8,6 +9,7 @@ def test_price_feed_offline_check():
89
state = PriceFeedState(
910
symbol="Crypto.BTC/USD",
1011
asset_type="Crypto",
12+
schedule=MarketSchedule("America/New_York;O,O,O,O,O,O,O;"),
1113
public_key=SolanaPublicKey("2hgu6Umyokvo8FfSDdMa9nDKhcdv9Q4VvGNhRCeSWeD3"),
1214
status=PythPriceStatus.TRADING,
1315
latest_block_slot=100,

tests/test_checks_publisher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest.mock import patch
44

55
import pytest
6+
from pythclient.market_schedule import MarketSchedule
67
from pythclient.pythaccounts import PythPriceStatus
78
from pythclient.solana import SolanaPublicKey
89

@@ -29,6 +30,7 @@ def make_publisher_state(
2930
publisher_name="publisher",
3031
symbol=symbol,
3132
asset_type=asset_type,
33+
schedule=MarketSchedule("America/New_York;O,O,O,O,O,O,O;"),
3234
public_key=SolanaPublicKey("2hgu6Umyokvo8FfSDdMa9nDKhcdv9Q4VvGNhRCeSWeD3"),
3335
status=PythPriceStatus.TRADING,
3436
aggregate_status=PythPriceStatus.TRADING,

0 commit comments

Comments
 (0)