# Portfolio Performance

Daily EUR and USD totals of the user's portfolio over a period, with the change between the first and last day.

## Overview

A nightly job stores one snapshot per user per day. This endpoint returns the snapshots for the requested `period`, oldest first, and computes the change in EUR between the first and the last one.

- `dataAvailable` is `true` when there are at least two snapshots; otherwise `changeEur` and `changePercent` are `null`.
- `changePercent` is relative to the first snapshot, and is also `null` when that first total is 0.
- New users have no history until the nightly job has run.
- Limited to 20 requests per minute.

## Endpoint

### `GET /v1/portfolio/performance`

Authentication: bearer token required.

Returns daily portfolio snapshots and the EUR change over the requested period.

**Query parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `period` | string | no | 24h \| 1W \| 1M \| 1Y (default 1M) |
| `isTestnet` | string | no | "true" for testnet balances, "false" for mainnet |

**Responses**

`200` OK

```json
{
  "period": "1M",
  "dataAvailable": true,
  "changeEur": 320.5,
  "changePercent": 2.64,
  "snapshots": [
    { "date": "2026-08-12", "totalEur": 12130, "totalUsd": 13248.6 },
    { "date": "2026-09-11", "totalEur": 12450.5, "totalUsd": 13598.7 }
  ]
}
```

`429` Rate limited

```json
{ "error": "…", "message": "…" }
```

## Implementation

```javascript
async function getPerformance(accessToken, period = '1M') {
  const res = await fetch(`https://api.aureahub.com/v1/portfolio/performance?period=${period}`, {
    headers: { Authorization: `Bearer ${accessToken}` }
  });
  if (!res.ok) throw new Error(`Portfolio request failed: ${res.status}`);

  const { dataAvailable, changeEur, changePercent, snapshots } = await res.json();
  return {
    chart: snapshots.map(s => ({ x: s.date, y: s.totalEur })),
    summary: dataAvailable
      ? `${changeEur >= 0 ? '+' : ''}${changeEur.toFixed(2)} EUR${changePercent === null ? '' : ` (${changePercent.toFixed(2)}%)`}`
      : 'Not enough history yet'
  };
}
```

---

Web version: https://docs.aureahub.com/#portfolio-perf
