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

# Portfolio Performance

> Retrieve performance metrics for a portfolio

This endpoint returns detailed performance metrics for a specific portfolio, including cost basis, realized profit/loss, and unrealized profit/loss information.

## Path Parameters

<ParamField path="portfolioId" type="string" required>
  The unique identifier of the portfolio
</ParamField>

## Query Parameters

<ParamField query="includeTrades" type="boolean" default="true">
  Include per-trade performance data in the response
</ParamField>

<ParamField query="realtime" type="boolean" default="false">
  Use real-time market data for calculating unrealized profit/loss
</ParamField>

## Request Headers

<ParamField header="X-API-KEY" type="string" required>
  Your API key
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  Indicates if the request was successful
</ResponseField>

<ResponseField name="data" type="object">
  <Expandable title="Properties">
    <ResponseField name="pnl" type="object">
      <Expandable title="Properties">
        <ResponseField name="costBasis" type="object">
          Cost basis data for each asset

          <Expandable title="Cost Basis Object">
            <ResponseField name="[assetId]" type="object">
              <Expandable title="Properties">
                <ResponseField name="amount" type="string">
                  Amount of the asset
                </ResponseField>

                <ResponseField name="costBasisUsd" type="string">
                  Total cost basis in USD
                </ResponseField>

                <ResponseField name="averagePrice" type="string">
                  Average acquisition price per unit
                </ResponseField>
              </Expandable>
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="realizedPnl" type="object">
          Realized profit/loss data for each asset

          <Expandable title="Realized PnL Object">
            <ResponseField name="[assetId]" type="object">
              <Expandable title="Properties">
                <ResponseField name="amount" type="string">
                  Amount of the asset realized
                </ResponseField>

                <ResponseField name="realizedPnlUsd" type="string">
                  Realized profit/loss in USD
                </ResponseField>
              </Expandable>
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="unrealizedPnl" type="object">
          Unrealized profit/loss data (only when realtime=true)

          <Expandable title="Unrealized PnL Object">
            <ResponseField name="[assetId]" type="object">
              <Expandable title="Properties">
                <ResponseField name="amount" type="string">
                  Current amount of the asset held
                </ResponseField>

                <ResponseField name="currentValueUsd" type="string">
                  Current market value in USD
                </ResponseField>

                <ResponseField name="costBasisUsd" type="string">
                  Cost basis for current holdings in USD
                </ResponseField>

                <ResponseField name="unrealizedPnlUsd" type="string">
                  Unrealized profit/loss in USD
                </ResponseField>

                <ResponseField name="unrealizedPnlPercentage" type="string">
                  Unrealized profit/loss as a percentage
                </ResponseField>
              </Expandable>
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="trades" type="array">
          Per-trade performance data (only when includeTrades=true)

          <Expandable title="Trade Object">
            <ResponseField name="id" type="string">
              Unique identifier for the trade
            </ResponseField>

            <ResponseField name="timestamp" type="number">
              Unix timestamp when the trade occurred
            </ResponseField>

            <ResponseField name="type" type="string">
              Type of trade (e.g., "buy", "sell", "swap")
            </ResponseField>

            <ResponseField name="assetIn" type="object">
              Asset received
            </ResponseField>

            <ResponseField name="assetOut" type="object">
              Asset sent
            </ResponseField>

            <ResponseField name="amountIn" type="string">
              Amount received
            </ResponseField>

            <ResponseField name="amountOut" type="string">
              Amount sent
            </ResponseField>

            <ResponseField name="valueIn" type="string">
              Value received in USD
            </ResponseField>

            <ResponseField name="valueOut" type="string">
              Value sent in USD
            </ResponseField>

            <ResponseField name="costBasis" type="string">
              Cost basis used for the trade
            </ResponseField>

            <ResponseField name="realizedPnl" type="string">
              Realized profit/loss from the trade in USD
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="summary" type="object">
          Summary performance metrics

          <Expandable title="Summary Object">
            <ResponseField name="totalCostBasisUsd" type="string">
              Total cost basis across all assets in USD
            </ResponseField>

            <ResponseField name="totalRealizedPnlUsd" type="string">
              Total realized profit/loss across all assets in USD
            </ResponseField>

            <ResponseField name="totalUnrealizedPnlUsd" type="string">
              Total unrealized profit/loss across all assets in USD (only when realtime=true)
            </ResponseField>

            <ResponseField name="totalPnlUsd" type="string">
              Total profit/loss (realized + unrealized) in USD
            </ResponseField>

            <ResponseField name="totalPnlPercentage" type="string">
              Total profit/loss as a percentage
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

## Example Request

```bash theme={null}
curl -X GET "https://api.glider.fi/portfolio/port_1a2b3c4d5e6f/pnl?realtime=true" \
  -H "X-API-KEY: YOUR_API_KEY"
```

## Example Response

```json theme={null}
{
  "success": true,
  "data": {
    "pnl": {
      "costBasis": {
        "usdc-usd-coin": {
          "amount": "500000000",
          "costBasisUsd": "500.00",
          "averagePrice": "1.00"
        },
        "weth-wrapped-ethereum": {
          "amount": "250000000000000000",
          "costBasisUsd": "500.00",
          "averagePrice": "2000.00"
        }
      },
      "realizedPnl": {
        "usdc-usd-coin": {
          "amount": "0",
          "realizedPnlUsd": "0.00"
        }
      },
      "unrealizedPnl": {
        "usdc-usd-coin": {
          "amount": "500000000",
          "currentValueUsd": "500.00",
          "costBasisUsd": "500.00",
          "unrealizedPnlUsd": "0.00",
          "unrealizedPnlPercentage": "0.00"
        },
        "weth-wrapped-ethereum": {
          "amount": "250000000000000000",
          "currentValueUsd": "550.00",
          "costBasisUsd": "500.00",
          "unrealizedPnlUsd": "50.00",
          "unrealizedPnlPercentage": "10.00"
        }
      },
      "summary": {
        "totalCostBasisUsd": "1000.00",
        "totalRealizedPnlUsd": "0.00",
        "totalUnrealizedPnlUsd": "50.00",
        "totalPnlUsd": "50.00",
        "totalPnlPercentage": "5.00"
      }
    }
  }
}
```

## Error Codes

<ResponseField name="NOT_FOUND" type="404">
  The specified portfolio could not be found
</ResponseField>

<ResponseField name="UNAUTHORIZED" type="401">
  Invalid or missing API key
</ResponseField>

<ResponseField name="FORBIDDEN" type="403">
  The API key does not have permission to access this portfolio
</ResponseField>

## Notes

* Performance data is calculated based on the complete transaction history of the portfolio
* Real-time pricing data can be enabled with the `realtime` parameter to get current unrealized PnL
* Without real-time pricing, only realized PnL and cost basis data will be provided
* The per-trade PnL calculations use FIFO (First In, First Out) accounting methodology
