> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fairground.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# getMarketSummary

> Python SDK reference for getMarketSummary.

Retrieve market summary statistics by market ID and return it as a JSON object.

<ParamField path="market_id" type="object" required>
  The market identifier
</ParamField>

<ResponseField name="returns" type="object" required>
  Dictionary containing market summary data if found, None otherwise
</ResponseField>

**Raises**

* **ValueError** — If API\_SERVER\_URL environment variable is not set

**Example**

```python theme={null}
>>> import os
>>> os.environ["API_SERVER_URL"] = "http://localhost:8080"
>>> summary = await getMarketSummary(market_id=1)
>>> print(summary["openInterest"])
1000.5
```

```python theme={null}
async def getMarketSummary(market_id: Union[str, int]) -> 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:
            market_summary = await client.get_market_summary(market_id)
            if market_summary:
                market_summary_dict = MessageToDict(market_summary, always_print_fields_with_no_presence=True)
                market_summary_dict = _filter_executable_depth(market_summary_dict)
                return market_summary_dict
            return None
        except Exception as e:
            print(f'Error getting market summary: {e}')
            print('\nTroubleshooting:')
            print('  - Is the server running?')
            print('  - Is this a valid market ID in the database?')
            return None
```
