Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add type check and fix the type issues #26

Merged
merged 7 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
13 changes: 11 additions & 2 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Run image
uses: abatilo/actions-poetry@v2
with:
poetry-version: '1.3.2'
- name: Install dependencies
run: poetry install
- name: Run pre-commit
run: poetry run pre-commit run --all-files
keyvankhademi marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ repos:
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/fsouza/mirrors-pyright
rev: v1.1.354
hooks:
- id: pyright
14 changes: 11 additions & 3 deletions example_publisher/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ def __init__(self, config: Config) -> None:
if not getattr(self.config, self.config.provider_engine):
raise ValueError(f"Missing {self.config.provider_engine} config")

if self.config.provider_engine == "coin_gecko":
if (
self.config.provider_engine == "coin_gecko"
and config.coin_gecko is not None
):
self.provider = CoinGecko(config.coin_gecko)
elif self.config.provider_engine == "pyth_replicator":
elif (
self.config.provider_engine == "pyth_replicator"
and config.pyth_replicator is not None
):
self.provider: Provider = PythReplicator(config.pyth_replicator)
else:
raise ValueError(f"Unknown provider {self.config.provider_engine}")
raise ValueError(
f"Unknown provider {self.config.provider_engine}, possibly the env variables is not set."
keyvankhademi marked this conversation as resolved.
Show resolved Hide resolved
)

self.pythd: Pythd = Pythd(
address=config.pythd.endpoint,
Expand Down
21 changes: 10 additions & 11 deletions example_publisher/pythd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from dataclasses import dataclass, field
import sys
import traceback
from dataclasses_json import config, dataclass_json
from typing import Awaitable, Callable, List
from dataclasses_json import config, DataClassJsonMixin
from typing import Any, Callable, Coroutine, List
from structlog import get_logger
from jsonrpc_websocket import Server

Expand All @@ -15,37 +15,36 @@
TRADING = "trading"


@dataclass_json
@dataclass
class Price:
class Price(DataClassJsonMixin):
account: str
exponent: int = field(metadata=config(field_name="price_exponent"))


@dataclass_json
@dataclass
class Metadata:
class Metadata(DataClassJsonMixin):
symbol: str


@dataclass_json
@dataclass
class Product:
class Product(DataClassJsonMixin):
account: str
metadata: Metadata = field(metadata=config(field_name="attr_dict"))
prices: List[Price] = field(metadata=config(field_name="price"))


class Pythd:
def __init__(
self, address: str, on_notify_price_sched: Callable[[SubscriptionId], Awaitable]
self,
address: str,
on_notify_price_sched: Callable[[SubscriptionId], Coroutine[Any, Any, None]],
keyvankhademi marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
self.address = address
self.server: Server = None
self.server: Server
self.on_notify_price_sched = on_notify_price_sched
self._tasks = set()

async def connect(self) -> Server:
async def connect(self):
self.server = Server(self.address)
self.server.notify_price_sched = self._notify_price_sched
task = await self.server.ws_connect()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import random
from typing import List
from example_publisher.providers.pyth_replicator import manual_aggregate


def test_manual_aggregate_works():
prices = [1, 2, 3, 4, 5, 6, 8, 10, 12, 14]
prices: List[float] = [1, 2, 3, 4, 5, 6, 8, 10, 12, 14]
random.shuffle(prices)

agg_price, agg_confidence_interval = manual_aggregate(prices)
Expand Down
Loading
Loading