> For the complete documentation index, see [llms.txt](https://ocx.gitbook.io/ocx-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ocx.gitbook.io/ocx-doc/ocx/api/portfolio.md).

# portfolio

Consolidated views across all your positions, balances, and PnL.

## GET /portfolio/me

Full portfolio snapshot — positions, balances, equity, margin usage, unrealized and realized PnL.

**Auth**: required.

**Response**

```json
{
  "equity":             "12450.75",
  "tradableBalance":    "4820.50",
  "balances": {
    "walletBalance":    "500.00",
    "perpsBalance":     "4320.50",
    "optionsBalance":   "0.00"
  },
  "pnl": {
    "unrealized":       "250.00",
    "realized24h":      "-45.00"
  },
  "margin": {
    "initialMargin":     "2010.00",
    "maintenanceMargin": "1340.00",
    "marginUsage":       "0.42"
  },
  "positions": [
    {
      "marketId":       "BTC-PERP",
      "side":           "long",
      "quantity":       "0.5",
      "avgPrice":       "66500.00",
      "markPrice":      "67000.00",
      "unrealizedPnl":  "250.00",
      "realizedPnl":    "0",
      "fundingPayment": "-1.25",
      "marginMode":     "cross"
    }
  ],
  "optionPositions": []
}
```

`margin.marginUsage` is a fractional value between 0 and 1 representing `initialMargin / equity`.

## GET /portfolio/balances

Same bucket breakdown as `/wallet/balance`, enriched with spot asset entries.

**Auth**: required.

**Response**

```json
{
  "walletBalance":   "500.00",
  "perpsBalance":    "300.00",
  "optionsBalance":  "180.00",
  "assets": [
    {
      "asset":     "USDC",
      "available": "100.00",
      "locked":    "5.00",
      "total":     "105.00"
    }
  ]
}
```

## SSE /portfolio/balances/stream

Server-Sent Events stream of your balance snapshot. Emits on every event that changes your balance — fills, funding, deposits, withdrawals, and mark updates that change your equity.

**Auth**: required.

Each message is the same shape as `GET /portfolio/balances`.

**Example**

```bash
curl -N https://api.ocx.global/portfolio/balances/stream \
  -H "Authorization: Bearer ocx_sk_..."
```

```
event: snapshot
data: {"walletBalance":"500.00","perpsBalance":"300.00",...}

event: snapshot
data: {"walletBalance":"500.00","perpsBalance":"299.85",...}
```

Reconnect on disconnect; the next message is always a full snapshot.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ocx.gitbook.io/ocx-doc/ocx/api/portfolio.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
