> 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/api/websocket.md).

# WebSocket

This page will help you get started with the Lighter WebSocket server.

## Connection

| Environment             | URL                                        |
| ----------------------- | ------------------------------------------ |
| Lighter mainnet         | `wss://mainnet.zklighter.elliot.ai/stream` |
| Lighter testnet         | `wss://testnet.zklighter.elliot.ai/stream` |
| Robinhood Chain mainnet | `wss://api.rh.lighter.xyz/stream`          |
| Robinhood Chain testnet | `wss://api.rh-testnet.lighter.xyz/stream`  |

You can directly connect to the WebSocket server using wscat:

```shell
wscat -c 'wss://mainnet.zklighter.elliot.ai/stream'
```

If you're connecting from a restricted region, you can still access read-only data:

```shell
wscat -c 'wss://mainnet.zklighter.elliot.ai/stream?readonly=true'
```

## Message envelope

| Message                        | Meaning                                                                                                          |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
| `type: "connected"`            | The socket is connected; subscribe to the channels you need.                                                     |
| `type: "subscribed/<channel>"` | Subscription acknowledgement with the initial snapshot.                                                          |
| `type: "update/<channel>"`     | A subsequent update. Apply it according to that channel's rules.                                                 |
| `error: {code, message}`       | Request or subscription failed. Errors need not contain a `type` field; an optional `id` identifies the request. |

Subscribe requests use slash-separated channel names; response `channel` values use colons. Private channels take an `auth` token inside the subscribe message, as shown below. This WebSocket field is separate from REST authentication, which uses the `Authorization` header. Public-pool data does not require authentication; see `pool_data` and `pool_info`.

Structure blocks below use placeholders such as `INTEGER`, `STRING` and `FLOAT`; they describe payloads and are not literal JSON. Example response blocks are JSON. `transaction_time` is in microseconds and may be omitted when no transaction execution time is available. See [Timestamps](https://docs.lighter.xyz/developers/reference/timestamps) for field-specific units.

## Keepalive Requirements

Clients are responsible for keeping the connection alive by sending at least one frame every **2 minutes**. This can be either:

* **A** **WebSocket ping frame**
* **Any application-level message**

Clients sending `{"type":"ping"}` will receive back `{"type":"pong"}`.

If the server receives no frames from a client within the 2-minute window, it will close the connection.

Support for `permessage-deflate` compression is enabled.

Writes to slow clients time out after 250 ms by default. Keep reading messages continuously; if the connection closes, reconnect and resubscribe to obtain fresh snapshots.

## Send Tx

You can send transactions using the websocket as follows:

```
{
    "type": "jsonapi/sendtx",
    "data": {
        "id": STRING, // returned in the ws response
        "tx_type": INTEGER,
        "tx_info": ...
    }
}
```

The *tx\_type* options can be found in the [SignerClient](https://github.com/elliottech/lighter-python/blob/main/lighter/signer_client.py) file, while *tx\_info* can be generated using the sign methods in the SignerClient.

Example: [create\_modify\_cancel\_order\_ws.py](https://github.com/elliottech/lighter-python/blob/main/examples/orders/create_modify_cancel_order_ws.py)

## Send Batch Tx

You can send batch transactions to execute up to 50 transactions in a single message. Larger batches are rejected with error `21514`.

```
{
    "type": "jsonapi/sendtxbatch",
    "data": {
        "id": STRING, // returned in the ws response
        "tx_types": "[INTEGER]",
        "tx_infos": "[tx_info]"
    }
}
```

The *tx\_type* options can be found in the [SignerClient](https://github.com/elliottech/lighter-python/blob/main/lighter/signer_client.py) file, while *tx\_info* can be generated using the sign methods in the SignerClient.

Example: [ws\_send\_batch\_tx.py](https://github.com/elliottech/lighter-python/blob/main/examples/batch-orders/send_batch_tx_ws.py)

## Types

These types are shared across channels. Fields marked optional are omitted when zero or empty. Field names and numeric/string representations match the API.

### Transaction JSON

To decode `event_info`, you can refer to [Data Structures](https://docs.lighter.xyz/developers/reference/data-structures-constants-and-errors).

```
Transaction = {
    "hash": STRING,
    "type": INTEGER,
    "info": STRING,                // json object as string, attributes depending on the tx type
    "event_info": STRING,          // json object as string, attributes depending on the tx type
    "status": INTEGER,
    "transaction_index": INTEGER,
    "l1_address": STRING,
    "account_index": INTEGER,
    "nonce": INTEGER,
    "expire_at": INTEGER,
    "block_height": INTEGER,
    "queued_at": INTEGER,
    "executed_at": INTEGER,
    "sequence_index": INTEGER,
    "parent_hash": STRING,
    "api_key_index": INTEGER,
    "transaction_time": INTEGER
}
```

Example:

```json
{
    "hash": "0xabc123456789def",
    "type": 15,
    "info": "{\"AccountIndex\":1,\"ApiKeyIndex\":2,\"MarketIndex\":3,\"Index\":404,\"ExpiredAt\":1700000000000,\"Nonce\":1234,\"Sig\":\"0xsigexample\"}",
    "event_info": "{\"a\":1,\"i\":404,\"u\":123,\"ae\":\"\"}",
    "status": 2,
    "transaction_index": 10,
    "l1_address": "0x123abc456def789",
    "account_index": 101,
    "nonce": 12345,
    "expire_at": 1700000000000,
    "block_height": 1500000,
    "queued_at": 1699999990000,
    "executed_at": 1700000000005,
    "sequence_index": 5678,
    "parent_hash": "0xparenthash123456",
    "api_key_index": 2,
    "transaction_time": 1700000000005000
}
```

Used in: [Account Tx](#account-tx).

### Order JSON

```
Order = {
    "order_index": INTEGER,
    "client_order_index": INTEGER,
    "order_id": STRING,
    "client_order_id": STRING,
    "market_index": INTEGER,
    "market_symbol": STRING,
    "market_kind": "spot" | "bo" | "perps",
    "owner_account_index": INTEGER,
    "initial_base_amount": STRING,
    "price": STRING,
    "nonce": INTEGER,
    "remaining_base_amount": STRING,
    "is_ask": BOOLEAN,
    "base_size": INTEGER,
    "base_price": INTEGER,
    "filled_base_amount": STRING,
    "filled_quote_amount": STRING,
    "side": STRING,
    "type": "limit" | "market" | "stop-loss" | "stop-loss-limit" | "take-profit" | "take-profit-limit" | "twap" | "twap-sub" | "liquidation",
    "time_in_force": "good-till-time" | "immediate-or-cancel" | "post-only" | "Unknown",
    "reduce_only": BOOLEAN,
    "trigger_price": STRING,
    "order_expiry": INTEGER,
    "status": "in-progress" | "pending" | "open" | "filled" | "canceled" | "canceled-post-only" | "canceled-reduce-only" | "canceled-position-not-allowed" | "canceled-margin-not-allowed" | "canceled-too-much-slippage" | "canceled-not-enough-liquidity" | "canceled-self-trade" | "canceled-expired" | "canceled-oco" | "canceled-child" | "canceled-liquidation" | "canceled-invalid-balance",
    "trigger_status": "na" | "ready" | "mark-price" | "twap" | "parent-order",
    "trigger_time": INTEGER,
    "parent_order_index": INTEGER,
    "parent_order_id": STRING,
    "to_trigger_order_id_0": STRING,
    "to_trigger_order_id_1": STRING,
    "to_cancel_order_id_0": STRING,
    "integrator_fee_collector_index": STRING,
    "integrator_taker_fee": STRING,
    "integrator_maker_fee": STRING,
    "order_flags": INTEGER,
    "block_height": INTEGER,
    "timestamp": INTEGER, // Unix seconds
    "created_at": INTEGER,
    "updated_at": INTEGER,
    "transaction_time": INTEGER, // Unix microseconds
    "order_version": INTEGER
}
```

Used in: [Account Market](#account-market), [Account All Orders](#account-all-orders), [Account Orders](#account-orders).

### Trade JSON

```
Trade = {
    "trade_id": INTEGER,
    "trade_id_str": STRING,
    "tx_hash": STRING,
    "type": "trade" | "liquidation" | "deleverage" | "market-settlement",
    "market_id": INTEGER,
    "market_symbol": STRING,
    "market_kind": "spot" | "bo" | "perps",
    "size": STRING,
    "price": STRING,
    "usd_amount": STRING,
    "ask_id": INTEGER,
    "ask_id_str": STRING,
    "bid_id": INTEGER,
    "bid_id_str": STRING,
    "ask_client_id": INTEGER,
    "ask_client_id_str": STRING,
    "bid_client_id": INTEGER,
    "bid_client_id_str": STRING,
    "ask_account_id": INTEGER,
    "bid_account_id": INTEGER,
    "is_maker_ask": BOOLEAN,
    "block_height": INTEGER,
    "timestamp": INTEGER, // Unix milliseconds
    "taker_fee": INTEGER, // optional: omitted when zero or empty
    "taker_position_size_before": STRING, // optional: omitted when zero or empty
    "taker_entry_quote_before": STRING, // optional: omitted when zero or empty
    "taker_initial_margin_fraction_before": INTEGER, // optional: omitted when zero or empty
    "taker_position_sign_changed": BOOLEAN, // optional: omitted when zero or empty
    "maker_fee": INTEGER, // optional: omitted when zero or empty
    "maker_position_size_before": STRING, // optional: omitted when zero or empty
    "maker_entry_quote_before": STRING, // optional: omitted when zero or empty
    "maker_initial_margin_fraction_before": INTEGER, // optional: omitted when zero or empty
    "maker_position_sign_changed": BOOLEAN, // optional: omitted when zero or empty
    "transaction_time": INTEGER, // Unix microseconds
    "ask_account_pnl": STRING, // optional: omitted when zero or empty
    "bid_account_pnl": STRING, // optional: omitted when zero or empty
    "integrator_taker_fee": INTEGER, // optional: omitted when zero or empty
    "integrator_taker_fee_collector_index": INTEGER, // optional: omitted when zero or empty
    "integrator_maker_fee": INTEGER, // optional: omitted when zero or empty
    "integrator_maker_fee_collector_index": INTEGER, // optional: omitted when zero or empty
    "taker_allocated_margin_usdc_before": INTEGER, // optional: omitted when zero or empty
    "taker_allocated_margin_usdc_after": INTEGER, // optional: omitted when zero or empty
    "maker_allocated_margin_usdc_before": INTEGER, // optional: omitted when zero or empty
    "maker_allocated_margin_usdc_after": INTEGER, // optional: omitted when zero or empty
    "ask_order_version": INTEGER,
    "bid_order_version": INTEGER
}
```

Example:

```json
{
    "trade_id":16164557907,
    "trade_id_str":"16164557907",
    "tx_hash":"019f2b9c9cc609196316a569541e135a739728e0837fcfb05c913534e305e503c01d5dcfeabeaf81",
    "type":"trade",
    "market_id":0,
    "market_symbol":"ETH",
    "market_kind":"perps",
    "size":"0.1336",
    "price":"2181.83",
    "usd_amount":"291.492488",
    "ask_id":281476612587355,
    "ask_id_str":"281476612587355",
    "bid_id":562948334068259,
    "bid_id_str":"562948334068259",
    "ask_client_id":363283,
    "ask_client_id_str":"363283",
    "bid_client_id":23004521241,
    "bid_client_id_str":"23004521241",
    "ask_account_id":57890,
    "bid_account_id":317068,
    "is_maker_ask":false,
    "block_height":198321831,
    "timestamp":1773854156654,
    "taker_position_size_before":"80.5467",
    "taker_entry_quote_before":"178806.039128",
    "taker_initial_margin_fraction_before":500,
    "taker_fee": 196,
    "maker_fee":28,
    "maker_position_size_before":"-4.3180",
    "maker_entry_quote_before":"9419.085856",
    "maker_initial_margin_fraction_before":200,
    "transaction_time":1773854156686065
}
```

Used in: [Trade](#trade), [Account All](#account-all), [Account Market](#account-market), [Account All Trades](#account-all-trades).

### Position JSON

```
Position = {
    "market_id": INTEGER,
    "symbol": STRING,
    "initial_margin_fraction": STRING,
    "open_order_count": INTEGER,
    "pending_order_count": INTEGER,
    "position_tied_order_count": INTEGER,
    "sign": -1 | 1,
    "position": STRING,
    "avg_entry_price": STRING,
    "position_value": STRING,
    "unrealized_pnl": STRING,
    "realized_pnl": STRING,
    "liquidation_price": STRING,
    "total_funding_paid_out": STRING, // optional: omitted when zero or empty
    "margin_mode": 0 | 1,
    "margin_set_flag": INTEGER,
    "allocated_margin": STRING,
    "total_discount": STRING // optional: omitted when zero or empty
}
```

Example:

```json
{
    "market_id": 1,
    "symbol": "BTC",
    "initial_margin_fraction": "0.1",
    "open_order_count": 2,
    "pending_order_count": 1,
    "position_tied_order_count": 3,
    "sign": 1,
    "position": "0.5",
    "avg_entry_price": "20000.00",
    "position_value": "10000.00",
    "unrealized_pnl": "500.00",
    "realized_pnl": "100.00",
    "liquidation_price": "3024.66",
    "total_funding_paid_out": "34.2",
    "margin_mode": 1,
    "allocated_margin": "46342"
}
```

Used in: [Account All](#account-all), [Account Market](#account-market), [Account All Positions](#account-all-positions).

### PoolShares JSON

```
PoolShares = {
    "public_pool_index": INTEGER,
    "shares_amount": INTEGER,
    "entry_usdc": STRING,
    "principal_amount": STRING,
    "entry_timestamp": INTEGER
}
```

Example:

```json
{
    "public_pool_index": 1,
    "shares_amount": 100,
    "entry_usdc": "1000.00",
    "principal_amount": "3000",
    "entry_timestamp": 3600000
}
```

Used in: [Account All](#account-all), [Account All Positions](#account-all-positions).

### Asset JSON

Structure (pseudocode):

```
Asset {
    "symbol": STRING,
    "asset_id": INTEGER,
    "balance": STRING,
    "locked_balance": STRING,
    "margin_mode": "enabled" | "disabled",
    "margin_balance": STRING,
    "multiplier": STRING
}
```

Example:

```json
{
    "symbol": "ETH",
    "asset_id": 1,
    "balance": "6691.4917",
    "locked_balance": "564.6135"
}
```

Used in: [Account All Assets](#account-all-assets), [Account Market](#account-market), [Account All](#account-all).

### PositionFunding JSON

```
PositionFunding = {
    "timestamp": INTEGER, // Unix seconds
    "market_id": INTEGER,
    "funding_id": INTEGER,
    "change": STRING,
    "rate": STRING,
    "position_size": STRING,
    "position_side": "long" | "short",
    "discount": STRING
}
```

```json
{
    "timestamp": 1773850000,
    "market_id": 0,
    "funding_id": 2001,
    "change": "0.001",
    "rate": "0.0001",
    "position_size": "0.5",
    "position_side": "long",
    "discount": "0"
}
```

## Channels

To unsubscribe from a channel, use the following syntax:

```
{
    "type": "unsubscribe",
    "channel": STRING
}
```

### Order Book

The order book channel sends the new ask and bid orders for the given market in batches, every 50ms. While the nonce is tied to Lighter's matching engine, the offset is tied to the API servers; hence, you can expect the offset to change drastically on reconnection if you're routed to a different server. Regardless, on each update the offset will increase, but it's not guaranteed to be continuous. Additionally, this channel sends a complete snapshot on subscription, but only state changes after that. To verify the continuity of the data, you can check that `begin_nonce` on the current update matches the `nonce` (i.e. `last_nonce`) of the previous update.

```json
{
    "type": "subscribe",
    "channel": "order_book/{MARKET_INDEX}"
}
```

{% @lighter-ws-console/console channel="order\_book/0" %}

**Example Subscription**

```json
{
    "type": "subscribe",
    "channel": "order_book/0"
}
```

**Response Structure**

```
{
    "channel": "order_book:{MARKET_INDEX}",
    "last_updated_at": INTEGER,
    "offset": INTEGER,
    "order_book": {
        "code": INTEGER,
        "asks": [
            {
                "price": STRING,
                "size": STRING
            }
        ],
        "bids": [
            {
                "price": STRING,
                "size": STRING
            }
        ],
        "offset": INTEGER,
        "nonce": INTEGER,
        "last_updated_at": INTEGER,
        "begin_nonce": INTEGER,

    },
    "timestamp": INTEGER,
    "type": "update/order_book"
}
```

**Example Response**

```json
{
   "channel":"order_book:0",
   "last_updated_at":1774884082309144,
   "offset":1558300,
   "order_book":{
      "code":0,
      "asks":[
         {
            "price":"2064.54",
            "size":"0.3285"
         }
      ],
      "bids":[

      ],
      "offset":1558300,
      "nonce":9182390020,
      "last_updated_at":1774884082309144,
      "begin_nonce":9182389998
   },
   "timestamp":1774884082326,
   "type":"update/order_book"
}
```

### Best Bid and Offer (BBO)

Updates are triggered on every nonce update for a given market's order book.

```json
{
   "type":"subscribe",
   "channel":"ticker/{MARKET_INDEX}"
}
```

{% @lighter-ws-console/console channel="ticker/0" %}

**Example subscription:**

```json
{
   "type":"subscribe",
   "channel":"ticker/0"
}
```

**Response Structure:**

```
{
   "channel": "ticker:{MARKET_INDEX}",
   "last_updated_at": INTEGER,
   "nonce": INTEGER,
   "ticker":{
      "s": STRING,
      "a":{
         "price": STRING,
         "size": STRING
      },
      "b":{
         "price": STRING,
         "size": STRING
      },
      "last_updated_at":INTEGER
   },
   "timestamp": INTEGER,
   "type":"update/ticker"
}
```

**Example Response:**

```json
{
   "channel":"ticker:0",
   "last_updated_at":1774883844921166,
   "nonce":9182249734,
   "ticker":{
      "s":"ETH",
      "a":{
         "price":"2064.48",
         "size":"0.4950"
      },
      "b":{
         "price":"2064.30",
         "size":"1.0392"
      },
      "last_updated_at":1774883844921166
   },
   "timestamp":1774883844933,
   "type":"update/ticker"
}
```

### Market Stats

`market_stats` and `spot_market_stats` exclude binary options. Use [Binary options market stats](#binary-options-market-stats) for those markets.

The market stats channel sends the market stat data for a given market. `current_funding_rate` is an estimation of the upcoming funding payment, while `funding_rate` represents the last funding payment that occurred (at `funding_timestamp`). To fetch stats for spot markets, use [spot\_market\_stats](#spot-market-stats).

```json
{
    "type": "subscribe",
    "channel": "market_stats/{MARKET_INDEX}"
}
```

{% @lighter-ws-console/console channel="market\_stats/0" %}

or

```json
{
    "type": "subscribe",
    "channel": "market_stats/all"
}
```

**Example Subscription**

```json
{
    "type": "subscribe",
    "channel": "market_stats/0"
}
```

**Response Structure**

```
{
    "channel": "market_stats:{MARKET_INDEX}",
    "market_stats": {
      "symbol": STRING,
      "market_id": INTEGER,
      "index_price": STRING,
      "mark_price": STRING,
      "mid_price": STRING,
      "best_ask_price": STRING,
      "best_bid_price": STRING,
      "open_interest": STRING,
      "open_interest_limit": STRING,
      "funding_clamp_small": STRING,
      "funding_clamp_big": STRING,
      "last_trade_price": STRING,
      "current_funding_rate": STRING,
      "funding_rate": STRING,
      "funding_timestamp": INTEGER,
      "daily_base_token_volume": FLOAT,
      "daily_quote_token_volume": FLOAT,
      "daily_price_low": FLOAT,
      "daily_price_high": FLOAT,
      "daily_price_change": FLOAT,
      "base_interest_rate": STRING,
      "premium": STRING // percentage
    },
    "timestamp": INTEGER,
    "type": "update/market_stats"
}
```

**Example Response**

```json
{
  "channel": "market_stats:0",
  "market_stats": {
    "symbol": "ETH",
    "market_id": 0,
    "index_price": "1900.86",
    "mark_price": "1899.99",
    "mid_price": "1899.95",
    "best_ask_price": "1899.95",
    "best_bid_price": "1899.94",
    "open_interest": "81885817.089747",
    "open_interest_limit": "72057594037927936.000000",
    "funding_clamp_small": "0.0500",
    "funding_clamp_big": "4.0000",
    "last_trade_price": "1899.98",
    "current_funding_rate": "0.0008",
    "funding_rate": "0.0008",
    "funding_timestamp": 1786370400000,
    "daily_base_token_volume": 79940.2167,
    "daily_quote_token_volume": 153191468.329297,
    "daily_price_low": 1893.51,
    "daily_price_high": 1937.78,
    "daily_price_change": -1.332599347722221,
    "base_interest_rate": "0.0100",
    "premium": "-0.0429"
  },
  "timestamp": 1786372092759,
  "type": "update/market_stats"
}
```

#### Multiple markets

To follow a chosen set of markets on one subscription, subscribe to the bare `market_stats` channel with `market_ids`, a list of up to 500 public market IDs. Duplicate IDs are ignored. Responses use `channel: "market_stats"` and a `market_stats` object keyed by market ID, as with `market_stats/all`.

```json
{
    "type": "subscribe",
    "channel": "market_stats",
    "market_ids": [0, 1, 2]
}
```

* Send another `subscribe` to `market_stats` with `market_ids` to add markets to the live subscription. The added markets' current stats arrive in an `update/market_stats` message. A request that would take the subscription above 500 markets is rejected and changes nothing.
* Send `unsubscribe` to `market_stats` with `market_ids` to remove those markets. An `unsubscribe` without `market_ids` ends the whole subscription.

#### Partial updates

Add `"partial": true` to a `market_stats/all` or `market_stats` (with `market_ids`) subscription to receive only changed fields. The `subscribed/market_stats` snapshot, and the stats sent for markets added later, stay complete. Each later `update/market_stats` entry contains `market_id` plus the fields that changed since the previous message sent on this subscription; merge it into the stats you hold. `partial` is rejected on `market_stats/{MARKET_INDEX}`.

```json
{
    "type": "subscribe",
    "channel": "market_stats/all",
    "partial": true
}
```

### Binary Options Market Stats

Subscribe to `bo_market_stats/{MARKET_INDEX}` for one market or `bo_market_stats/all` for all binary options markets. The all-market response contains a `bo_market_stats` object keyed by market ID; a single-market response contains one stats object. The all-market stream also includes old, settled and not-yet-open markets: filter by `status: "active"`, then check the trading window and `is_frozen` in [events](https://docs.lighter.xyz/api/binary-options) before placing orders. See [Binary options WebSocket](https://docs.lighter.xyz/developers/binary-options/websocket#binary-options-market-stats) for fields and lifecycle statuses.

{% @lighter-ws-console/console channel="bo\_market\_stats/all" %}

### Trade

The trade channel sends the new trade data for the given market.

```json
{
    "type": "subscribe",
    "channel": "trade/{MARKET_INDEX}"
}
```

{% @lighter-ws-console/console channel="trade/0" %}

**Example Subscription**

```json
{
    "type": "subscribe",
    "channel": "trade/0"
}
```

**Response Structure**

```
{
    "channel": "trade:{MARKET_INDEX}",
    "liquidation_trades": [Trade],
    "nonce":INTEGER,
    "trades": [Trade],
    "type": "update/trade"
}
```

**Example Response**

```json
{
   "channel":"trade:0",
   "liquidation_trades":[],
   "nonce":8630448841,
   "trades":[
      {
         "trade_id":16164557907,
         "trade_id_str":"16164557907",
         "tx_hash":"019f2b9c9cc609196316a569541e135a739728e0837fcfb05c913534e305e503c01d5dcfeabeaf81",
         "type":"trade",
         "market_id":0,
         "size":"0.1336",
         "price":"2181.83",
         "usd_amount":"291.492488",
         "ask_id":281476612587355,
         "ask_id_str":"281476612587355",
         "bid_id":562948334068259,
         "bid_id_str":"562948334068259",
         "ask_client_id":363283,
         "ask_client_id_str":"363283",
         "bid_client_id":23004521241,
         "bid_client_id_str":"23004521241",
         "ask_account_id":57890,
         "bid_account_id":317068,
         "is_maker_ask":false,
         "block_height":198321831,
         "timestamp":1773854156654,
         "taker_position_size_before":"80.5467",
         "taker_entry_quote_before":"178806.039128",
         "taker_initial_margin_fraction_before":500,
         "taker_fee": 196,
         "maker_fee":28,
         "maker_position_size_before":"-4.3180",
         "maker_entry_quote_before":"9419.085856",
         "maker_initial_margin_fraction_before":200,
         "transaction_time":1773854156686065
      }
   ],
   "type":"update/trade"
}
```

### Candlesticks

Real-time candlestick (OHLCV) updates via WebSocket. Subscribe to any market and resolution to receive live candle data as trades occur. Supported resolutions: `1m`, `5m`, `15m`, `30m`, `1h`, `4h`, `12h`, `1d`. The candles\[] array allows up to 2 candles to be sent in a single update when a candle period closes (rolls over). If so, candles\[0] will be the oldest, just closed candle.

```json
{
	"type": "subscribe",
	"channel": "candle/{MARKET_INDEX}/{resolution}"
}
```

{% @lighter-ws-console/console channel="candle/0/1m" %}

**Example Subscription**

```json
{
	"type": "subscribe",
	"channel": "candle/0/1m"
}
```

**Response Structure (Subscribe)**

```
{
  "type": "subscribed/candle",
  "channel": "candle:{MARKET_INDEX}:{resolution}",
  "timestamp": INTEGER,
  "candles": [
    {
      "t": INTEGER, // candle open timestamp
      "o": FLOAT, // open price
      "h": FLOAT, // high price
      "l": FLOAT, // low price
      "c": FLOAT, // close price
      "v": FLOAT, // base token volume
      "V": FLOAT, // quote token volume
      "i": INTEGER // last trade id
    }
  ]
}
```

**Response Structure (Updates)**

```
{
  "type": "update/candle",
  "channel": "candle:{MARKET_INDEX}:{resolution}",
  "timestamp": INTEGER,
  "candles": [
    {
      "t": INTEGER,
      "o": FLOAT,
      "h": FLOAT,
      "l": FLOAT,
      "c": FLOAT,
      "v": FLOAT,
      "V": FLOAT,
      "i": INTEGER
    }
  ]
}
```

**Example Response (Subscribe)**

Returns the current live candle.

```json
{
  "type": "subscribed/candle",
  "channel": "candle:0:1m",
  "timestamp": 1778500801812,
  "candles": [
    {
      "t": 1778500800000,
      "o": 2334.89,
      "h": 2335.14,
      "l": 2334.73,
      "c": 2334.73,
      "v": 19.8259,
      "V": 46293.345028,
      "i": 19694821240
    }
  ]
}
```

**Example Response (Updates)**

Returns the latest candle state, whenever a trade occurs, with a 500ms batching.

```json
{
  "type": "update/candle",
  "channel": "candle:0:1m",
  "timestamp": 1778500803456,
  "candles": [
    {
      "t": 1778500800000,
      "o": 2334.89,
      "h": 2335.33,
      "l": 2334.73,
      "c": 2335.15,
      "v": 24.3878,
      "V": 56946.630946,
      "i": 19694823713
    }
  ]
}
```

### Up/Down Candlesticks

Subscribe to `up_down_candle/{SYMBOL}/{DURATION}/{RESOLUTION}` for the underlying price of an Up/Down series, for example `up_down_candle/eth/15m/1s`. Resolutions are `1s` and `30s`. The initial snapshot contains up to 300 candles. See [Binary options WebSocket](https://docs.lighter.xyz/developers/binary-options/websocket#up-down-candlesticks) for the payload and [upDownCandles](https://docs.lighter.xyz/api/binary-options) for REST history.

{% @lighter-ws-console/console channel="up\_down\_candle/eth/15m/1s" %}

### Mark Price Candlesticks

Real-time mark price candlestick (OHLC) updates via WebSocket. Subscribe to any market and resolution to receive live candle data as mark price samples arrive. Supported resolutions: `1m`, `5m`, `15m`, `30m`, `1h`, `4h`, `12h`, `1d`. The candles\[] array allows up to 2 candles to be sent in a single update when a candle period closes (rolls over). If so, candles\[0] will be the oldest, just closed candle.

```json
{
	"type": "subscribe",
	"channel": "mark_price_candle/{MARKET_INDEX}/{resolution}"
}
```

{% @lighter-ws-console/console channel="mark\_price\_candle/0/1m" %}

**Example Subscription**

```json
{
	"type": "subscribe",
	"channel": "mark_price_candle/0/1m"
}
```

**Response Structure (Subscribe)**

```
{
  "type": "subscribed/mark_price_candle",
  "channel": "mark_price_candle:{MARKET_INDEX}:{resolution}",
  "timestamp": INTEGER,
  "candles": [
    {
      "t": INTEGER, // candle open timestamp
      "o": FLOAT, // open price
      "h": FLOAT, // high price
      "l": FLOAT, // low price
      "c": FLOAT, // close price
      "sc": INTEGER // mark price samples within candle
    }
  ]
}
```

**Response Structure (Updates)**

```
{
  "type": "update/mark_price_candle",
  "channel": "mark_price_candle:{MARKET_INDEX}:{resolution}",
  "timestamp": INTEGER,
  "candles": [
    {
      "t": INTEGER,
      "o": FLOAT,
      "h": FLOAT,
      "l": FLOAT,
      "c": FLOAT,
      "sc": INTEGER
    }
  ]
}
```

**Example Response (Subscribe)**

Returns the current live candle.

```json
{
  "type": "subscribed/mark_price_candle",
  "channel": "mark_price_candle:0:1m",
  "timestamp": 1778500801812,
  "candles": [
    {
      "t": 1778500800000,
      "o": 2334.89,
      "h": 2335.14,
      "l": 2334.73,
      "c": 2334.73,
      "sc": 1
    }
  ]
}
```

**Example Response (Updates)**

Returns the latest candle state, as mark price samples arrive, batched every 500 ms.

```json
{
  "type": "update/mark_price_candle",
  "channel": "mark_price_candle:0:1m",
  "timestamp": 1778500803456,
  "candles": [
    {
      "t": 1778500800000,
      "o": 2334.89,
      "h": 2335.33,
      "l": 2334.73,
      "c": 2335.15,
      "sc": 1
    }
  ]
}
```

### Account All

Binary options positions appear separately in `bo_positions` (also in `account_all_positions`); `account_market` uses the singular `bo_position`. See [Binary options positions](https://docs.lighter.xyz/developers/binary-options/positions-and-settlement).

The account all channel sends specific account market data for all markets. Each new subscribe message returns a fresh snapshot; it does not reconnect the socket. Updates contain changed data: `assets` may be `null` when nothing changed, and daily/weekly/monthly/total trade statistics are snapshot-only fields.

```json
{
    "type": "subscribe",
    "channel": "account_all/{ACCOUNT_ID}"
}
```

{% @lighter-ws-console/console channel="account\_all/1" %}

**Example Subscription**

```json
{
    "type": "subscribe",
    "channel": "account_all/1"
}
```

**Response Structure**

```
{
    "account": INTEGER,
    "assets": {
      "{ASSET_INDEX}": Asset
    },
    "bo_positions": {},
    "channel": "account_all:{ACCOUNT_ID}",
    "daily_trades_count": INTEGER,
    "daily_volume": FLOAT,
    "weekly_trades_count": INTEGER,
    "weekly_volume": FLOAT,
    "monthly_trades_count": INTEGER,
    "monthly_volume": FLOAT,
    "total_trades_count": INTEGER,
    "total_volume": FLOAT,
    "funding_histories": {"{MARKET_INDEX}": [PositionFunding]},
    "positions": {
        "{MARKET_INDEX}": Position
    },
    "shares": [PoolShares],
    "trades": {
        "{MARKET_INDEX}": [Trade]
    },
    "transaction_time": INTEGER,
    "type": "update/account_all"
}
```

**Example Response**

Mainnet snapshot captured on 2026-10-22, with the positions map shortened to one entry. Empty funding and trade maps are valid.

```json
{
  "account": 10,
  "assets": {
    "2": {
      "symbol": "LIT",
      "asset_id": 2,
      "balance": "524.21838586",
      "locked_balance": "0.00000000",
      "margin_mode": "disabled",
      "margin_balance": "0.00000000",
      "multiplier": "1.000000000000000000"
    },
    "3": {
      "symbol": "USDC",
      "asset_id": 3,
      "balance": "1.997570461",
      "locked_balance": "0.000000",
      "margin_mode": "disabled",
      "margin_balance": "1945.003244157056",
      "multiplier": "1.000000000000000000"
    }
  },
  "bo_positions": {},
  "channel": "account_all:10",
  "daily_trades_count": 0,
  "daily_volume": 0,
  "funding_histories": {},
  "monthly_trades_count": 0,
  "monthly_volume": 0,
  "positions": {
    "0": {
      "market_id": 0,
      "symbol": "ETH",
      "initial_margin_fraction": "2.63",
      "open_order_count": 0,
      "pending_order_count": 0,
      "position_tied_order_count": 0,
      "sign": 1,
      "position": "0.0000",
      "avg_entry_price": "0.00",
      "position_value": "-0.000000",
      "unrealized_pnl": "0.000000",
      "realized_pnl": "0.000000",
      "liquidation_price": "0",
      "margin_mode": 0,
      "margin_set_flag": 1,
      "allocated_margin": "0.000000"
    }
  },
  "shares": [
    {
      "public_pool_index": 281474976624800,
      "shares_amount": 965,
      "entry_usdc": "0",
      "principal_amount": "0.00965000",
      "entry_timestamp": 0
    },
    {
      "public_pool_index": 281474976710654,
      "shares_amount": 1,
      "entry_usdc": "0.003276",
      "principal_amount": "0.003276",
      "entry_timestamp": 0
    }
  ],
  "total_trades_count": 2476,
  "total_volume": 2935377.596694,
  "trades": {},
  "transaction_time": 1789404078899134,
  "type": "subscribed/account_all",
  "weekly_trades_count": 0,
  "weekly_volume": 0
}
```

### Account Market

The account market channel sends specific account market data for a market. If `{MARKET_ID}` is a perpetual market, `assets` will return `null`, if `{MARKET_ID}` is a spot market, `funding_history` will return `null`.

```json
{
    "type": "subscribe",
    "channel": "account_market/{MARKET_ID}/{ACCOUNT_ID}",
    "auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="account\_market/0/1" %}

**Example Subscription**

```json
{
    "type": "subscribe",
    "channel": "account_market/0/40",
    "auth": "{AUTH_TOKEN}"
}
```

**Response Structure**

```
{
    "account": INTEGER,
    "assets": {"{ASSET_INDEX}": Asset} | null,
    "channel": "account_market:{MARKET_ID}:{ACCOUNT_ID}",
    "funding_history": [PositionFunding] | null,
    "orders": [Order],
    "position": Position | null,
    "bo_position": {"market_id": INTEGER, "entry_quote": STRING, "avg_entry_price": STRING, "sign": -1 | 1, "size": STRING} | null,
    "trades": [Trade],
    "transaction_time": INTEGER, // optional, Unix microseconds
    "type": "update/account_market"
}
```

`assets` and `funding_history` may be `null` in the initial snapshot when not applicable, and empty collections on updates. `position` and `bo_position` are single objects or `null`, not arrays.

### Account Stats

The account stats channel sends account stats data for the specific account.

```json
{
    "type": "subscribe",
    "channel": "user_stats/{ACCOUNT_ID}"
}
```

{% @lighter-ws-console/console channel="user\_stats/1" %}

**Example Subscription**

```json
{
    "type": "subscribe",
    "channel": "user_stats/1234"
}
```

**Response Structure**

```
{
    "channel": "user_stats:{ACCOUNT_ID}",
    "stats": {
        "collateral": STRING,
        "portfolio_value": STRING,
        "leverage": STRING,
        "available_balance": STRING,
        "margin_usage": STRING,
        "buying_power": STRING,
        "account_trading_mode": INTEGER,
        "cross_stats":{
            "collateral": STRING,
            "portfolio_value": STRING,
            "leverage": STRING,
            "available_balance": STRING,
            "margin_usage": STRING,
            "buying_power": STRING
        },
        "total_stats":{
            "collateral": STRING,
            "portfolio_value": STRING,
            "leverage": STRING,
            "available_balance": STRING,
            "margin_usage": STRING,
            "buying_power": STRING
        }
    },
    "timestamp": INTEGER,
    "type": "update/user_stats"
}
```

**Example Response**

```json
{
    "channel": "user_stats:10",
    "stats": {
        "collateral": "5000.00",
        "portfolio_value": "15000.00",
        "leverage": "3.0",
        "available_balance": "2000.00",
        "margin_usage": "0.80",
        "buying_power": "4000.00",
        "account_trading_mode": 1,
        "cross_stats":{
           "collateral":"0.000000",
           "portfolio_value":"0.000000",
           "leverage":"0.00",
           "available_balance":"0.000000",
           "margin_usage":"0.00",
           "buying_power":"0"
        },
        "total_stats":{
           "collateral":"0.000000",
           "portfolio_value":"0.000000",
           "leverage":"0.00",
           "available_balance":"0.000000",
           "margin_usage":"0.00",
           "buying_power":"0"
        }
    },
    "timestamp": 1773158679717,
    "type": "update/user_stats"
}
```

### Account Tx

This channel sends transactions related to a specific account.

```json
{
    "type": "subscribe",
    "channel": "account_tx/{ACCOUNT_ID}",
    "auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="account\_tx/1" %}

**Response Structure**

```
{
    "channel": "account_tx:{ACCOUNT_ID}",
    "txs": [Transaction],
    "type": "update/account_tx"
}
```

### Account All Orders

The account all orders channel sends data about all the orders of an account.

```json
{
    "type": "subscribe",
    "channel": "account_all_orders/{ACCOUNT_ID}",
    "auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="account\_all\_orders/1" %}

**Response Structure**

```
{
    "channel": "account_all_orders:{ACCOUNT_ID}",
    "orders": {
        "{MARKET_INDEX}": [Order]
    },
    "type": "update/account_all_orders"
}
```

### Height

Blockchain height updates

```json
{
    "type": "subscribe",
    "channel": "height"
}
```

{% @lighter-ws-console/console channel="height" %}

**Response Structure**

```
{
    "channel": "height",
    "height": INTEGER,
    "timestamp": INTEGER,
    "type": "update/height"
}
```

### Pool data

Provides data about pool activities: trades, orders, positions, shares and funding histories.

```json
{
    "type": "subscribe",
    "channel": "pool_data/{ACCOUNT_ID}",
    "auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="pool\_data/1" %}

**Response Structure**

```
{
    "channel": "pool_data:{ACCOUNT_ID}",
    "account": INTEGER,
    "trades": {
        "{MARKET_INDEX}": [Trade]
    },
    "orders": {
        "{MARKET_INDEX}": [Order]
    },
    "positions": {
        "{MARKET_INDEX}": [Position]
    },
    "shares": [PoolShares],
    "funding_histories": {
        "{MARKET_INDEX}": [PositionFunding]
    },
    "type": "subscribed/pool_data"
}
```

### Pool info

Provides information about pools.

```json
{
    "type": "subscribe",
    "channel": "pool_info/{ACCOUNT_ID}",
    "auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="pool\_info/1" %}

**Response Structure**

```
{
    "channel": "pool_info:{ACCOUNT_ID}",
    "pool_info": {
        "status": INTEGER,
        "operator_fee": STRING,
        "min_operator_share_rate": STRING,
        "total_shares": INTEGER,
        "operator_shares": INTEGER,
        "annual_percentage_yield": FLOAT,
        "sharpe_ratio": FLOAT,
        "daily_returns": [
            {
                "timestamp": INTEGER,
                "daily_return": FLOAT
            }
        ],
        "share_prices": [
            {
                "timestamp": INTEGER,
                "share_price": FLOAT
            }
        ],
        "strategies": [
            {
                "collateral": STRING
            }
        ]
    },
    "type": "subscribed/pool_info"
}
```

### Notification

Provides notifications received by an account. Notifications can be of three kinds: liquidation, deleverage, or announcement. Each kind has a different content structure.

```json
{
    "type": "subscribe",
    "channel": "notification/{ACCOUNT_ID}",
    "auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="notification/1" %}

**Response Structure**

```
{
    "channel": "notification:{ACCOUNT_ID}",
    "notifs": [
        {
            "id": STRING,
            "created_at": STRING,
            "updated_at": STRING,
            "kind": STRING,
            "account_index": INTEGER,
            "content": NotificationContent,
            "ack": BOOLEAN,
            "acked_at": STRING
        }
    ],
    "type": "subscribed/notification"
}
```

**Liquidation Notification Content**

```
{
    "id": STRING,
    "is_ask": BOOLEAN,
    "usdc_amount": STRING,
    "size": STRING,
    "market_index": INTEGER,
    "price": STRING,
    "timestamp": INTEGER,
    "avg_price": STRING
}
```

**Deleverage Notification Content**

```
{
    "id": STRING,
    "usdc_amount": STRING,
    "size": STRING,
    "market_index": INTEGER,
    "settlement_price": STRING,
    "timestamp": INTEGER
}
```

**Announcement Notification Content**

```
{
    "title": STRING,
    "content": STRING,
    "created_at": INTEGER
}
```

**Example response**

```json
{
    "channel": "notification:12345",
    "notifs": [
        {
            "id": "notif_123",
            "created_at": "2024-01-15T10:30:00Z",
            "updated_at": "2024-01-15T10:30:00Z",
            "kind": "liquidation",
            "account_index": 12345,
            "content": {
                "id": "notif_123",
                "is_ask": false,
                "usdc_amount": "1500.50",
                "size": "0.500000",
                "market_index": 1,
                "price": "3000.00",
                "timestamp": 1705312200,
                "avg_price": "3000.00"
            },
            "ack": false,
            "acked_at": null
        },
        {
            "id": "notif_124",
            "created_at": "2024-01-15T11:00:00Z",
            "updated_at": "2024-01-15T11:00:00Z",
            "kind": "deleverage",
            "account_index": 12345,
            "content": {
                "id": "notif_124",
                "usdc_amount": "500.25",
                "size": "0.200000",
                "market_index": 1,
                "settlement_price": "2501.25",
                "timestamp": 1705314000
            },
            "ack": false,
            "acked_at": null
        }
    ],
    "type": "update/notification"
}
```

### Account Orders

The account orders channel sends data about the orders of an account on a certain market.

```json
{
    "type": "subscribe",
    "channel": "account_orders/{MARKET_INDEX}/{ACCOUNT_ID}",
    "auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="account\_orders/0/1" %}

**Response Structure**

```
{
    "account": INTEGER,
    "channel": "account_orders:{MARKET_INDEX}",
    "nonce": INTEGER,
    "orders": {
        "{MARKET_INDEX}": [Order] // the only present market index will be the one provided
    },
    "type": "update/account_orders"
}
```

### Account All Trades

The account all trades channel sends data about all the trades of an account.

```json
{
    "type": "subscribe",
    "channel": "account_all_trades/{ACCOUNT_ID}"
}
```

{% @lighter-ws-console/console channel="account\_all\_trades/1" %}

**Response Structure**

```
{
    "channel": "account_all_trades:{ACCOUNT_ID}",
    "trades": [],
    "total_volume": FLOAT,
    "monthly_volume": FLOAT,
    "weekly_volume": FLOAT,
    "daily_volume": FLOAT,
    "type": "subscribed/account_all_trades"
}
```

```
{
    "channel": "account_all_trades:{ACCOUNT_ID}",
    "trades": {
        "{MARKET_INDEX}": [Trade]
    },
    "type": "update/account_all_trades"
}
```

### Account All Positions

The account all positions channel sends data about all the positions of an account.

```json
{
    "type": "subscribe",
    "channel": "account_all_positions/{ACCOUNT_ID}"
}
```

{% @lighter-ws-console/console channel="account\_all\_positions/1" %}

**Response Structure**

```
{
    "bo_positions": {},
    "channel": "account_all_positions:{ACCOUNT_ID}",
    "positions": {
        "{MARKET_INDEX}": Position
    },
    "shares": [PoolShares],
    "transaction_time": INTEGER,
    "type": "subscribed/account_all_positions",
}
```

```
{
    "bo_positions": {},
    "channel": "account_all_positions:{ACCOUNT_ID}",
    "positions": {
        "{MARKET_INDEX}": Position
    },
    "shares": [PoolShares],
    "last_funding_round": {            // optional, only present when funding occurs
        "{MARKET_INDEX}": STRING
    },
    "last_funding_discount": {         // optional, only present when funding occurs
        "{MARKET_INDEX}": STRING
    },
    "transaction_time": INTEGER,
    "type": "update/account_all_positions",
}
```

### Spot Market Stats

The spot market stats channel sends the market stat data for the given spot market.

```json
{
    "type": "subscribe",
    "channel": "spot_market_stats/{MARKET_INDEX}"
}
```

{% @lighter-ws-console/console channel="spot\_market\_stats/2048" %}

or

```json
{
    "type": "subscribe",
    "channel": "spot_market_stats/all"
}
```

**Example Subscription**

```json
{
    "type": "subscribe",
    "channel": "spot_market_stats/2048"
}
```

`spot_market_stats` supports the same `market_ids` list subscription and `partial` updates as [market\_stats](#multiple-markets), using the bare `spot_market_stats` channel and the `spot_market_stats` payload key.

**Response Structure** **using** `all`

```
{
    "channel": "spot_market_stats:all",
    "spot_market_stats": {
      "{MARKET_INDEX}": {
          "symbol": STRING,
          "market_id": INTEGER,
          "index_price": STRING,
          "mid_price": STRING,
          "last_trade_price": STRING,
          "daily_base_token_volume": FLOAT,
          "daily_quote_token_volume": FLOAT,
          "daily_price_low": FLOAT,
          "daily_price_high": FLOAT,
          "daily_price_change": FLOAT
      }
    },
    "timestamp": INTEGER,
    "type": "update/spot_market_stats"
}
```

**Example Response** **using** `all`

```json
{
   "channel":"spot_market_stats:all",
   "spot_market_stats":{
      "2048":{
         "symbol":"ETH/USDC",
         "market_id":2048,
         "index_price":"2188.994707",
         "mid_price":"2188.90",
         "last_trade_price":"2190.25",
         "daily_base_token_volume":681.5806,
         "daily_quote_token_volume":1535781.121577,
         "daily_price_low":2166.63,
         "daily_price_high":2347.78,
         "daily_price_change":-5.917096219931271
      }
   },
   "timestamp":1773860622360,
   "type":"update/spot_market_stats"
}
```

**Response Structure** **using** `MARKET_INDEX`

```
{
    "channel": "spot_market_stats:{MARKET_INDEX}",
    "spot_market_stats": {
      "symbol": STRING,
        "market_id": INTEGER,
        "index_price": STRING,
        "mid_price": STRING,
        "last_trade_price": STRING,
        "daily_base_token_volume": FLOAT,
        "daily_quote_token_volume": FLOAT,
        "daily_price_low": FLOAT,
        "daily_price_high": FLOAT,
        "daily_price_change": FLOAT
    },
    "timestamp": INTEGER,
    "type": "update/spot_market_stats"
}
```

**Example Response** **using** `MARKET_INDEX`

```json
{
   "channel":"spot_market_stats:2048",
   "spot_market_stats":{
      "symbol":"ETH/USDC",
      "market_id":2048,
      "index_price":"2183.030179",
      "mid_price":"2182.60",
      "last_trade_price":"2179.81",
      "daily_base_token_volume":670.444,
      "daily_quote_token_volume":1511428.664237,
      "daily_price_low":2166.63,
      "daily_price_high":2347.78,
      "daily_price_change":-6.365549828178694
   },
   "timestamp":1773860440362,
   "type":"update/spot_market_stats"
}
```

### Account All Assets

The account all assets channel sends specific account market data for all spot markets for a specific account. `balance` is in coin terms, not USDC (unless asset\_index=3, in which case they coincide).

```json
{
    "type": "subscribe",
    "channel": "account_all_assets/{ACCOUNT_ID}",
    "auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="account\_all\_assets/1" %}

**Example Subscription**

```json
{
    "type": "subscribe",
    "channel": "account_all_assets/1234",
    "auth": "{AUTH_TOKEN}"
}
```

**Response Structure**

```
{
    "assets": {
         "{ASSET_INDEX}": Asset,
         "{ASSET_INDEX}": Asset
    },
    "channel": "account_all_assets:{ACCOUNT_ID}",
    "timestamp": INTEGER,
    "transaction_time": INTEGER,
    "type": "update/account_all_assets"
}
```

**Example Response**

```json
{
    "assets": {
        "1": {
            "symbol": "ETH",
            "asset_id": 1,
            "balance": "7.1072",
            "locked_balance": "0.0000"
        },
        "3": {
            "symbol": "USDC",
            "asset_id": 3,
            "balance": "6343.581906",
            "locked_balance": "297.000000"
        }
    },
    "channel": "account_all_assets:1234",
    "timestamp": 1791407336316,
    "transaction_time": 1791406944316056,
    "type": "update/account_all_assets"
}
```

### Average Entry Prices

Updates on the `account_spot_avg_entry_prices` channel are triggered whenever an event occurs for a given spot asset. Each event is accounted for as a buy or sell executed at the index price. Events include trades, deposits, withdrawals, transfers, and staking. The `last_trade_id` field confirms the validity of the data returned up to that `trade_id`.

```json
{
    "type": "subscribe",
    "channel": "account_spot_avg_entry_prices/{ACCOUNT_ID}",
    "auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="account\_spot\_avg\_entry\_prices/1" %}

**Example subscription:**

```json
{
    "type": "subscribe",
    "channel": "account_spot_avg_entry_prices/1234",
    "auth": "{AUTH_TOKEN}"
}
```

**Response Structure:**

```
{
   "avg_entry_prices":{
      "{ASSET_INDEX}":{
         "asset_id":INTEGER,
         "avg_entry_price":STRING,
         "asset_size":STRING,
         "last_trade_id":INTEGER
      }
   },
   "channel":"account_spot_avg_entry_prices:{ACCOUNT_ID}",
   "timestamp": INTEGER,
   "type":"subscribed/account_spot_avg_entry_prices"
}
```

**Example Response:**

```json
{
   "avg_entry_prices":{
      "1":{
         "asset_id":1,
         "avg_entry_price":"1850.45",
         "asset_size":"0.01234567",
         "last_trade_id":13472591098
      }
   },
   "channel":"account_spot_avg_entry_prices:1234",
   "timestamp": 1773158679717,
   "type":"subscribed/account_spot_avg_entry_prices"
}
```

### Request for Quote (RFQ)

This channel allows you to receive all currently open RFQs, followed by live updates as new ones arrive. RFQ responses are hidden if you're not the requester, so you will only see the market and its size. API endpoints to create, respond, update, get, and list RFQs are available [here](https://docs.lighter.xyz/api/rfq). Currently, this program is whitelist-only.

```json
{
	"type": "subscribe",
	"channel": "rfq",
	"auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="rfq" %}

**Response Structure**

```
{
   "channel":"rfq",
   "rfqs":[
      {
         "id":INTEGER, // needed to respond
         "account_index":INTEGER,
         "market_index":INTEGER,
         "direction":INTEGER, // redacted to -1
         "base_amount":STRING,
         "quote_amount":STRING,
         "status":STRING,
         "metadata":{},
         "responses":[],
         "created_at":INTEGER,
         "updated_at":INTEGER
      }
   ],
   "type":"update/rfq"
}
```

**Example Response**

```json
{
   "channel":"rfq",
   "rfqs":[
      {
         "id":1234,
         "account_index":704885,
         "market_index":1,
         "direction":-1,
         "base_amount":"100",
         "quote_amount":"",
         "status":"opened",
         "metadata":{

         },
         "responses":[

         ],
         "created_at":1780077339117,
         "updated_at":1780077339117
      }
   ],
   "type":"update/rfq"
}
```

### Live points (Lighter on Robinhood Chain only)

This channel returns the total live points accrued to an account index. Updates are triggered as the total changes. You can confirm you have the latest value by fetching [livePoints/total](https://docs.lighter.xyz/api/points) via REST.

```json
{
	"type": "subscribe",
	"channel": "live_points/{ACCOUNT_ID}",
	"auth": "{AUTH_TOKEN}"
}
```

{% @lighter-ws-console/console channel="live\_points/1" %}

**Example Subscription:**

```json
{
	"type": "subscribe",
	"channel": "live_points/1234",
	"auth": "{AUTH_TOKEN}"
}
```

**Response Structure**

```
{
	"type": "subscribed/live_points",
	"channel": "live_points:{ACCOUNT_ID}",
	"total_live_points": INTEGER
}
```

**Example Response**

```json
{
	"type": "subscribed/live_points",
	"channel": "live_points:{ACCOUNT_ID}",
	"total_live_points": 1234.56
}
```

```json
{
	"type": "update/live_points",
	"channel": "live_points:{ACCOUNT_ID}",
	"total_live_points": 1234.56
}
```


---

# 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/api/websocket.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.
