Dictionary containing market summary data, or None on error
Raises
ValueError — If API_SERVER_URL environment variable is not set
Example
>>> import os>>> os.environ["API_SERVER_URL"] = "http://localhost:8080">>> async for summary in streamMarketSummary(market_id=1):... print(summary["openInterest"])
async def streamMarketSummary(market_id: Union[str, int]) -> AsyncIterator[Optional[Dict[str, Any]]]: base_url = os.getenv('API_SERVER_URL') if not base_url: raise ValueError('API_SERVER_URL environment variable not set') async with httpx.AsyncClient() as session: client = PerpetualsClient(base_url=base_url, session=session) try: async for market_summary in client.stream_market_summary(market_id): market_summary_dict = MessageToDict(market_summary, always_print_fields_with_no_presence=True) market_summary_dict = _filter_executable_depth(market_summary_dict) yield market_summary_dict except Exception as e: print(f'Error streaming market summary: {e}') print('\nTroubleshooting:') print(' - Is the server running?') print(' - Is this a valid market ID in the database?') print(' - Check network connectivity') yield None