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

# Account Positions

> Streams all changes made to an account's positions in any market. A position that has been fully closed will be streamed and return empty.

Refer to [Websocket](/api-documentation/api/websocket) for establishing the websocket connection.

### Params

```json theme={null}
{
    "method": "subscribe",
    "params": {
        "source": "account_positions",
        "account": "42trU9A5..."
    }
}
```

### Positions Snapshots

Upon subscription, the `account_positions` websocket immediately returns a snapshot of all current positions, then begins streaming all changes made to an account's positions in a best effort picture of current state.\
\
We recommend using `account_positions` for initialization, and `account_trades`, to construct up-to-date positions state.

Every `account_positions` message is a **complete replacement** — replace your whole local array on each message rather than merging. A closed position is dropped (there is no zero row or deletion marker), and an empty `data: []` array means the account is flat.

Each message carries a [Last ID](/api-documentation/api/last-id) (`li`) on every row and one on the envelope for the whole position set. On (re)subscription, use the initialization snapshot as your baseline, then apply later snapshots with an equal or newer envelope `li` and discard older ones.

### Stream

```json theme={null}
{
  "channel": "subscribe",
  "data": {
    "source": "account_positions",
    "account": "BrZp5..."
  }
}
// this is the initialization snapshot
{
  "channel": "account_positions", 
  "data": [
    {
      "s": "BTC",
      "d": "bid",
      "a": "0.00022",
      "p": "87185",
      "m": "0",
      "f": "-0.00023989",
      "i": false,
      "l": null,
      "t": 1764133203991,
      "li": 1559395580
    }
  ],
  "li": 1559395580
}
// this shows the position being increased by an order filling
{
  "channel": "account_positions",
  "data": [
    {
      "s": "BTC",
      "d": "bid",
      "a": "0.00044",
      "p": "87285.5",
      "m": "0",
      "f": "-0.00023989",
      "i": false,
      "l": "-95166.79231",
      "t": 1764133656974,
      "li": 1559412952
    }
  ],
  "li": 1559412952
}
// this shows the position being closed
{
  "channel": "account_positions",
  "data": [],
  "li": 1559438203
}
```

<table><thead><tr><th width="196.800048828125">Field</th><th width="187.4000244140625">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>'s'</code></td><td>string</td><td>Symbol</td></tr><tr><td><code>'d'</code></td><td>string</td><td>Position side (bid, ask)</td></tr><tr><td><code>'a'</code></td><td>decimal string</td><td>Position amount</td></tr><tr><td><code>'p'</code></td><td>decimal string</td><td>Average entry price</td></tr><tr><td><code>'m'</code></td><td>decimal string</td><td>Position margin</td></tr><tr><td><code>'f'</code></td><td>decimal string</td><td>Position funding fee</td></tr><tr><td><code>'i'</code></td><td>bool</td><td>Is position isolated?</td></tr><tr><td><code>'l'</code></td><td>decimal string</td><td>Liquidation price in USD (null if not applicable)</td></tr><tr><td><code>'t'</code></td><td>number</td><td>Timestamp in milliseconds</td></tr><tr><td><code>'li'</code> (row)</td><td>number or null</td><td><a href="/api-documentation/api/last-id">Last ID</a> — sequence number for this <code>(account, symbol)</code> position. <code>null</code> if the engine has not touched the row yet.</td></tr><tr><td><code>'li'</code> (envelope)</td><td>number</td><td><a href="/api-documentation/api/last-id">Last ID</a> — sequence number for the account's whole position set. Advances on every change, including closes and empty snapshots.</td></tr></tbody></table>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.