#!/usr/bin/env python3 from __future__ import annotations import asyncio import os import signal import sys from typing import List, Any from loguru import logger from pythclient.pythclient import PythClient # noqa from pythclient.ratelimit import RateLimit # noqa from pythclient.pythaccounts import PythPriceAccount # noqa from pythclient.utils import get_key # noqa logger.enable("pythclient") RateLimit.configure_default_ratelimit(overall_cps=9, method_cps=3, connection_cps=3) to_exit = False def set_to_exit(sig: Any, frame: Any): global to_exit to_exit = True signal.signal(signal.SIGINT, set_to_exit) async def main(): global to_exit use_program = len(sys.argv) >= 2 and sys.argv[1] == "program" v2_first_mapping_account_key = get_key("devnet", "mapping") v2_program_key = get_key("devnet", "program") async with PythClient( first_mapping_account_key=v2_first_mapping_account_key, program_key=v2_program_key if use_program else None, ) as c: await c.refresh_all_prices() products = await c.get_products() all_prices: List[PythPriceAccount] = [] for p in products: print(p.key, p.attrs) prices = await p.get_prices() for _, pr in prices.items(): all_prices.append(pr) print( pr.key, pr.product_account_key, pr.price_type, pr.aggregate_price, "p/m", pr.aggregate_price_confidence_interval, ) if __name__ == '__main__': asyncio.run(main())