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

feat: Poller refresh interval #232

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 12 additions & 1 deletion price-pusher/price_pusher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async def main(
private_key: PrivateKey,
publisher_name: str,
publisher_address: str,
poller_refresh_interval: int,
rpc_url: Optional[str] = None,
api_base_url: Optional[str] = None,
api_key: Optional[str] = None,
Expand Down Expand Up @@ -75,6 +76,7 @@ async def main(
pusher = PricePusher(client=pragma_client)
orchestrator = Orchestrator(
poller=poller,
poller_refresh_interval=poller_refresh_interval,
listeners=_create_listeners(price_configs, target, pragma_client),
pusher=pusher,
)
Expand Down Expand Up @@ -243,7 +245,14 @@ def _create_client(
"--enable-strk-fees",
type=click.BOOL,
required=False,
help="enable_strk_fees option for the onchain client",
help="Pay fees using STRK for on chain queries.",
)
@click.option(
"--poller-refresh-interval",
type=click.IntRange(min=5),
required=False,
default=5,
help="Interval in seconds between poller refreshes. Default to 5 seconds.",
)
def cli_entrypoint(
config_file: str,
Expand All @@ -259,6 +268,7 @@ def cli_entrypoint(
max_fee: Optional[int],
pagination: Optional[int],
enable_strk_fees: Optional[bool],
poller_refresh_interval: int,
) -> None:
if target == "offchain":
if not api_key or not api_base_url:
Expand Down Expand Up @@ -312,6 +322,7 @@ def cli_entrypoint(
max_fee=max_fee,
pagination=pagination,
enable_strk_fees=enable_strk_fees,
poller_refresh_interval=poller_refresh_interval,
)
)

Expand Down
13 changes: 10 additions & 3 deletions price-pusher/price_pusher/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class Orchestrator:
"""

poller: PricePoller
# Time between poller refresh. Defaults to 5 seconds.
# Make sure it's high enough - else we might get rate limited by public APIs.
poller_refresh_interval: int

listeners: List[PriceListener]
pusher: PricePusher
# Contains the latest spot/future prices for each sources
Expand All @@ -32,12 +36,15 @@ def __init__(
poller: PricePoller,
listeners: List[PriceListener],
pusher: PricePusher,
poller_refresh_interval: int = 5,
) -> None:
# Init class properties.
self.poller = poller
self.listeners = listeners
self.pusher = pusher

# Time between poller refresh
self.poller_refresh_interval = poller_refresh_interval

# Contains the latest prices for each sources
self.latest_prices: LatestOrchestratorPairPrices = {}

Expand Down Expand Up @@ -73,8 +80,8 @@ async def _poller_service(self) -> None:
"""
while True:
await self.poller.poll_prices()
# Wait 5 seconds before requerying public APIs (rate limits).
await asyncio.sleep(5)
# Wait some time before requerying public APIs (rate limits).
await asyncio.sleep(self.poller_refresh_interval)

async def _listener_services(self) -> None:
"""
Expand Down
Loading