Skip to content

Commit 140ce22

Browse files
authored
Fix some bugs + some improvements (#45)
* Fix some bugs + some improvements * Bump the version
1 parent c1e479d commit 140ce22

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ repos:
33
hooks:
44
- id: isort
55
name: isort
6-
entry: poetry run isort --profile=black --check .
6+
entry: poetry run isort --profile=black .
77
language: system
88
- id: black
99
name: black
10-
entry: poetry run black --check .
10+
entry: poetry run black .
1111
pass_filenames: false
1212
language: system
1313
- id: pyright

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ignore_missing_imports = true
44

55
[tool.poetry]
66
name = "pyth-observer"
7-
version = "0.1.0"
7+
version = "0.1.1"
88
description = "Alerts and stuff"
99
authors = []
1010
readme = "README.md"

pyth_observer/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import asyncio
22
import os
3-
from typing import Any, Dict, Tuple
3+
from typing import Any, Dict, List, Tuple
44

55
from base58 import b58decode
66
from loguru import logger
7+
from pythclient.pythaccounts import PythPriceAccount, PythPriceType, PythProductAccount
78
from pythclient.pythclient import PythClient
89
from pythclient.solana import (
910
SOLANA_DEVNET_HTTP_ENDPOINT,
@@ -137,17 +138,19 @@ async def run(self):
137138
logger.debug("Sleeping...")
138139
await asyncio.sleep(5)
139140

140-
async def get_pyth_products(self):
141+
async def get_pyth_products(self) -> List[PythProductAccount]:
141142
logger.debug("Fetching Pyth product accounts...")
142143

143144
async with self.pyth_throttler:
144-
return await self.pyth_client.get_products()
145+
return await self.pyth_client.refresh_products()
145146

146-
async def get_pyth_prices(self, product):
147+
async def get_pyth_prices(
148+
self, product: PythProductAccount
149+
) -> Dict[PythPriceType, PythPriceAccount]:
147150
logger.debug("Fetching Pyth price accounts...")
148151

149152
async with self.pyth_throttler:
150-
return await product.get_prices()
153+
return await product.refresh_prices()
151154

152155
async def get_coingecko_prices(self):
153156
logger.debug("Fetching CoinGecko prices...")

pyth_observer/crosschain.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ async def get_crosschain_prices(self) -> Dict[str, CrosschainPrice]:
3838
price_feeds = []
3939

4040
for ids in chunked(price_feed_ids, 25):
41-
# FIXME: Properly build this URL
42-
query_params = "ids[]=" + "&ids[]=".join(ids)
43-
price_feeds_url = f"{self.url}/api/latest_price_feeds?{query_params}"
41+
price_feeds_url = f"{self.url}/api/latest_price_feeds"
4442

45-
async with session.get(price_feeds_url) as response:
43+
async with session.get(
44+
price_feeds_url, params={"ids": ids}
45+
) as response:
4646
price_feeds += await response.json()
4747

4848
# Return a dictionary of id -> {price, conf, expo} for fast lookup

pyth_observer/dispatch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
from copy import deepcopy
23
from typing import Any, Awaitable, Dict, List
34

45
from prometheus_client import Gauge
@@ -103,7 +104,7 @@ def check_publisher(self, state: PublisherState) -> List[Check]:
103104
return failed_checks
104105

105106
def load_config(self, check_name: str, symbol: str) -> Dict[str, Any]:
106-
config = self.config["checks"]["global"][check_name]
107+
config = deepcopy(self.config["checks"]["global"][check_name])
107108

108109
if symbol in self.config["checks"]:
109110
if check_name in self.config["checks"][symbol]:

0 commit comments

Comments
 (0)