Stream market summary updates for all markets and yield JSON objects.
Dictionary containing list of market summaries, 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 summaries in streamAllMarketSummaries():
... print(len(summaries.get("marketSummaries", [])))
async def streamAllMarketSummaries() -> 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_summaries in client.stream_all_market_summaries():
summaries_list = [MessageToDict(summary, always_print_fields_with_no_presence=True) for summary in market_summaries]
yield {'marketSummaries': summaries_list}
except Exception as e:
print(f'Error streaming all market summaries: {e}')
print('\nTroubleshooting:')
print(' - Is the server running?')
print(' - Are there markets configured in the database?')
print(' - Check network connectivity')
yield None