Skip to content

Commit

Permalink
Fix some bugs + some improvements (#45)
Browse files Browse the repository at this point in the history
* Fix some bugs + some improvements

* Bump the version
  • Loading branch information
ali-bahjati authored Jan 3, 2023
1 parent c1e479d commit 140ce22
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ repos:
hooks:
- id: isort
name: isort
entry: poetry run isort --profile=black --check .
entry: poetry run isort --profile=black .
language: system
- id: black
name: black
entry: poetry run black --check .
entry: poetry run black .
pass_filenames: false
language: system
- id: pyright
Expand Down
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.0"
version = "0.1.1"
description = "Alerts and stuff"
authors = []
readme = "README.md"
Expand Down
13 changes: 8 additions & 5 deletions pyth_observer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import asyncio
import os
from typing import Any, Dict, Tuple
from typing import Any, Dict, List, Tuple

from base58 import b58decode
from loguru import logger
from pythclient.pythaccounts import PythPriceAccount, PythPriceType, PythProductAccount
from pythclient.pythclient import PythClient
from pythclient.solana import (
SOLANA_DEVNET_HTTP_ENDPOINT,
Expand Down Expand Up @@ -137,17 +138,19 @@ async def run(self):
logger.debug("Sleeping...")
await asyncio.sleep(5)

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

async with self.pyth_throttler:
return await self.pyth_client.get_products()
return await self.pyth_client.refresh_products()

async def get_pyth_prices(self, product):
async def get_pyth_prices(
self, product: PythProductAccount
) -> Dict[PythPriceType, PythPriceAccount]:
logger.debug("Fetching Pyth price accounts...")

async with self.pyth_throttler:
return await product.get_prices()
return await product.refresh_prices()

async def get_coingecko_prices(self):
logger.debug("Fetching CoinGecko prices...")
Expand Down
8 changes: 4 additions & 4 deletions pyth_observer/crosschain.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ async def get_crosschain_prices(self) -> Dict[str, CrosschainPrice]:
price_feeds = []

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

async with session.get(price_feeds_url) as response:
async with session.get(
price_feeds_url, params={"ids": ids}
) as response:
price_feeds += await response.json()

# Return a dictionary of id -> {price, conf, expo} for fast lookup
Expand Down
3 changes: 2 additions & 1 deletion pyth_observer/dispatch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from copy import deepcopy
from typing import Any, Awaitable, Dict, List

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

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

if symbol in self.config["checks"]:
if check_name in self.config["checks"][symbol]:
Expand Down

0 comments on commit 140ce22

Please sign in to comment.