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

# getPortfolioHistory

> Fetch the account's portfolio value and cumulative PnL over a lookback window

Returns the account's portfolio value and cumulative PnL over a lookback window. Points appear oldest first. The read goes direct to the provider.

<Info>
  The examples on this page use **Hyperliquid** (`provider: 'hyperliquid'`). Replace the `provider` value with any supported DEX from `getProviders()`.
</Info>

`getPortfolioHistory` is a method on the SDK client, not a standalone imported function.

```typescript theme={null}
const history = await client.getPortfolioHistory({
  provider: 'hyperliquid',
  address: userAddress,
  range: '30d',
});

for (const point of history.points) {
  console.log(point.timestamp, point.accountValue, point.pnl);
}

console.log('Total PnL for the window:', history.totalPnl);
```

## Parameters

| Parameter         | Type                    | Required | Description                                                           |
| ----------------- | ----------------------- | -------- | --------------------------------------------------------------------- |
| `params.provider` | `string`                | Yes      | DEX identifier                                                        |
| `params.address`  | `string`                | Yes      | User's wallet address                                                 |
| `params.range`    | `PortfolioHistoryRange` | Yes      | Lookback window — see [PortfolioHistoryRange](#portfoliohistoryrange) |
| `options`         | `SDKRequestOptions`     | No       | Request options                                                       |

## PortfolioHistoryRange

`PortfolioHistoryRange` is a string union imported from `@lifi/perps-sdk`.

| Value   | Description          |
| ------- | -------------------- |
| `'24h'` | Last 24 hours        |
| `'7d'`  | Last 7 days          |
| `'30d'` | Last 30 days         |
| `'all'` | Full account history |

## Returns

`PortfolioHistoryResponse`:

| Field      | Type                      | Description                                                                             |
| ---------- | ------------------------- | --------------------------------------------------------------------------------------- |
| `range`    | `PortfolioHistoryRange`   | The window the response covers                                                          |
| `points`   | `PortfolioHistoryPoint[]` | Samples over the window, oldest first                                                   |
| `volume`   | `string?`                 | Window trading volume in USD. Absent when the provider does not report it.              |
| `totalPnl` | `string?`                 | Cumulative PnL for the full window in USD. Absent when the provider does not report it. |

## PortfolioHistoryPoint fields

| Field          | Type     | Description                                                  |
| -------------- | -------- | ------------------------------------------------------------ |
| `timestamp`    | `number` | Unix milliseconds                                            |
| `accountValue` | `string` | Portfolio value in USD at this point                         |
| `pnl`          | `string` | Cumulative PnL in USD from the start of the requested window |

## Auth requirements

Each provider reads portfolio history with its own credential. The requirement is per provider.

### Hyperliquid

Hyperliquid needs no auth. The SDK reads portfolio history from a public Hyperliquid `info` endpoint using only the account address.

### Ondo

Ondo needs an active session. The user signs in with `siweLogin` before this call. A call with no active session returns an empty `points` array instead of an error.

### Lighter

Lighter needs the account auth token or the read-only token. The SDK resolves a token from its stored key automatically. A call with no resolvable token returns an empty `points` array instead of an error.
