> ## 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.

# getPortfolio

> Python SDK reference for getPortfolio.

Retrieve complete portfolio for the authenticated caller.

<ResponseField name="returns" type="object" required>
  Dictionary containing portfolio data if found, None otherwise
  Portfolio includes:

  * Aggregate metrics (margin, PnL, equity, volume, fees, etc.)
  * All positions (open and closed)
  * All orders (filled, open, cancelled)
</ResponseField>

**Raises**

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

**Example**

```python theme={null}
>>> import os
>>> os.environ["API_SERVER_URL"] = "http://localhost:8080"
>>> os.environ["ACCOUNT"] = "0x1234..."
>>> portfolio = await getPortfolio()
>>> print(portfolio["totalEquity"])
15000.50
>>> print(len(portfolio["positions"]))
3
```

```python theme={null}
async def getPortfolio() -> Optional[Dict[str, Any]]:
    base_url = os.getenv('API_SERVER_URL')
    if not base_url:
        raise ValueError('API_SERVER_URL environment variable not set')
    address = os.getenv('ACCOUNT')
    if not address:
        raise ValueError('ACCOUNT environment variable not set')
    async with httpx.AsyncClient() as session:
        client = PerpetualsClient(base_url=base_url, session=session)
        try:
            portfolio = await client.get_portfolio(address)
            if portfolio:
                portfolio_dict = MessageToDict(portfolio, always_print_fields_with_no_presence=True)
                return portfolio_dict
            return None
        except Exception as e:
            print(f'Error getting portfolio: {e}')
            print('\nTroubleshooting:')
            print('  - Is the server running?')
            print('  - Is ACCOUNT environment variable set correctly?')
            print('  - Check network connectivity')
            return None
```
