> For the complete documentation index, see [llms.txt](https://docs.lighter.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lighter.xyz/developers/integration-guides/account-data.md).

# Account data & positions

Balances, positions, orders, fills and transaction status for an account.

## REST

```shell
# Public account snapshot: collateral, positions, sub-accounts
curl "https://mainnet.zklighter.elliot.ai/api/v1/account?by=index&value=123"
```

Private endpoints such as [accountActiveOrders](https://docs.lighter.xyz/api/orders), [accountInactiveOrders](https://docs.lighter.xyz/api/orders), [pnl](https://docs.lighter.xyz/api/account) and the history endpoints require an [auth token](/developers/integration-guides/api-keys.md#authentication):

```typescript
const { authToken } = check(lighter.CreateAuthToken(Math.floor(Date.now() / 1000) + 3600, API_KEY_INDEX, ACCOUNT_INDEX));

const orders = await fetch(
  `${BASE_URL}/api/v1/accountActiveOrders?account_index=${ACCOUNT_INDEX}&market_id=0`,
  { headers: { Authorization: authToken } },
).then(r => r.json());
```

Check a submitted transaction with [tx](https://docs.lighter.xyz/api/transactions) (status values are in [Data Structures, Constants and Errors](/developers/reference/data-structures-constants-and-errors.md)):

```shell
curl "https://mainnet.zklighter.elliot.ai/api/v1/tx?by=hash&value=<tx_hash>"
```

## Binary options

[account](https://docs.lighter.xyz/api/account) returns binary options positions in `bo_positions`, separately from perps positions. The `account_all` and `account_all_positions` WebSocket channels also expose `bo_positions`; `account_market` uses `bo_position`. Realized PnL is available through [portfolio\_boPnl](https://docs.lighter.xyz/api/binary-options) and is gross of fees. See [Positions and settlement](/developers/binary-options/positions-and-settlement.md) for position fields and payout records.

## WebSocket (recommended)

Add `auth` to the subscribe message for private channels:

```json
{ "type": "subscribe", "channel": "account_all_orders/123", "auth": "<AUTH_TOKEN>" }
```

Which channel to use:

| You need                                       | Channel                                                                         |
| ---------------------------------------------- | ------------------------------------------------------------------------------- |
| Positions, trades, funding across all markets  | [Account All](https://docs.lighter.xyz/api/websocket#account-all)               |
| Open orders                                    | [Account All Orders](https://docs.lighter.xyz/api/websocket#account-all-orders) |
| Whether a transaction executed or was rejected | [Account Tx](https://docs.lighter.xyz/api/websocket#account-tx)                 |
| Collateral, leverage, margin usage             | [Account Stats](https://docs.lighter.xyz/api/websocket#account-stats)           |
| Liquidations, deleverages, announcements       | [Notification](https://docs.lighter.xyz/api/websocket#notification)             |

Every account channel, with its auth requirement and payload, is in the [WebSocket reference](https://docs.lighter.xyz/api/websocket#channels).

## Recommended pattern for apps

1. On load: REST snapshot (`account`) + subscribe to `account_all/{account}` and `account_all_orders/{account}`.
2. After every `sendTx`: optimistically show the order as pending; reconcile when it appears in `account_all_orders` or a failure arrives on `account_tx`.
3. On reconnect: resubscribe and replace local state with the new snapshot.

## Read-only access for third parties

For portfolio trackers, accountants, or AI agents, ask the user for a **read-only token** (`ro:…`). It works anywhere an auth token is accepted for reading and can never trade. See [Read-only Authentication](/developers/integration-guides/api-keys.md#read-only-authentication).


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lighter.xyz/developers/integration-guides/account-data.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
