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

# WebSocket

Subscribe to binary options market statistics and underlying price candles.

Binary options markets use the shared order-book, trade and account channels listed below, alongside two binary-options-specific channels: `bo_market_stats` and `up_down_candle`. The `market_stats` and `spot_market_stats` channels exclude binary options.

Connect to `wss://mainnet.zklighter.elliot.ai/stream`. Follow the existing [WebSocket reference](https://docs.lighter.xyz/api-reference/websocket) for connection handling and reconnects.

## Shared WebSocket channels

The [WebSocket reference](https://docs.lighter.xyz/api-reference/websocket) covers these general-purpose channels, including their subscription formats, authentication and response payloads. For subscriptions that take a market ID, use the binary options `market_id` returned by [events](https://docs.lighter.xyz/api-reference/binary-options).

| Channel                                                                                                                                                                                                                        | Binary options data                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
| [order\_book/{MARKET\_INDEX}](https://docs.lighter.xyz/api-reference/websocket#order-book)                                                                                                                                     | Order-book snapshots and updates for a market                                  |
| [trade/{MARKET\_INDEX}](https://docs.lighter.xyz/api-reference/websocket#trade)                                                                                                                                                | Public trades for a market                                                     |
| [account\_all/{ACCOUNT\_ID}](https://docs.lighter.xyz/api-reference/websocket#account-all)                                                                                                                                     | Account data, with binary options positions in `bo_positions`                  |
| [account\_all\_positions/{ACCOUNT\_ID}](https://docs.lighter.xyz/api-reference/websocket#account-all-positions)                                                                                                                | Account positions, including `bo_positions`                                    |
| [account\_market/{MARKET\_ID}/{ACCOUNT\_ID}](https://docs.lighter.xyz/api-reference/websocket#account-market)                                                                                                                  | Account data for one market, with its binary options position in `bo_position` |
| [account\_orders/{MARKET\_INDEX}/{ACCOUNT\_ID}](https://docs.lighter.xyz/api-reference/websocket#account-orders) and [account\_all\_orders/{ACCOUNT\_ID}](https://docs.lighter.xyz/api-reference/websocket#account-all-orders) | Account orders for one market or across markets                                |
| [account\_all\_trades/{ACCOUNT\_ID}](https://docs.lighter.xyz/api-reference/websocket#account-all-trades)                                                                                                                      | Account trades, including binary options trades                                |

## Binary options market stats

Sends the `stats` object of a binary options market, for one market or all of them.

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

Subscribe to all binary options markets:

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

For `bo_market_stats/all`, the `bo_market_stats` payload is an **object keyed by market ID**, not an array. Each value is a market stats object. For a single-market subscription, `bo_market_stats` is that market's stats object directly.

The all-market stream can include old, settled and not-yet-open markets. Filter for `status: "active"`, then check `start_timestamp`, `end_timestamp` and `is_frozen` in the market definition returned by [events](https://docs.lighter.xyz/api-reference/binary-options) before placing orders. Do not assume every market in this stream is currently tradeable.

### Response fields

For a single-market update, `channel` is `bo_market_stats:{MARKET_INDEX}`, `type` is `update/bo_market_stats`, and `timestamp` is an integer. The `bo_market_stats` object contains:

| Field                                                               | Type    | Meaning                                                                      |
| ------------------------------------------------------------------- | ------- | ---------------------------------------------------------------------------- |
| `symbol`                                                            | string  | Market symbol                                                                |
| `market_id`                                                         | integer | Market ID                                                                    |
| `mid_price`, `best_ask_price`, `best_bid_price`, `last_trade_price` | string  | Order book and last-trade prices                                             |
| `daily_base_token_volume`, `daily_quote_token_volume`               | number  | Daily base and quote volume                                                  |
| `daily_price_low`, `daily_price_high`, `daily_price_change`         | number  | Daily price statistics                                                       |
| `lifetime_quote_token_volume`, `lifetime_base_token_volume`         | number  | Lifetime quote and base volume                                               |
| `open_interest`                                                     | string  | Open interest                                                                |
| `status`                                                            | string  | `inactive`, `active`, `waiting-for-settlement`, `in-settlement` or `settled` |
| `outcome`                                                           | integer | `0`: none; `1`: No/Down; `2`: Yes/Up                                         |

See [Market lifecycle](/developers/binary-options/discover-markets.md#market-lifecycle) for each status.

## Up/Down candlesticks

Live candles of the underlying price of a series. Resolutions: `1s` (every price observation) and `30s`. The first message (`subscribed/up_down_candle`) is a snapshot of the last 300 candles (or fewer if less history is available); updates carry the changed candle(s).

```json
{
  "type": "subscribe",
  "channel": "up_down_candle/{SYMBOL}/{DURATION}/{RESOLUTION}"
}
```

### Example subscription

Use `symbol` and `duration` from the selected event’s metadata returned by [events](https://docs.lighter.xyz/api-reference/binary-options). The values below illustrate the channel format.

```json
{
  "type": "subscribe",
  "channel": "up_down_candle/btc/15m/1s"
}
```

### Response fields

For the example above, `channel` is `up_down_candle:btc:15m:1s`. Updates have `type: "update/up_down_candle"`, an integer `timestamp`, and a `candles` array. Each candle contains:

| Field                          | Type    | Meaning                                        |
| ------------------------------ | ------- | ---------------------------------------------- |
| `symbol`                       | string  | Underlying asset, for example `btc`            |
| `duration`                     | string  | Observation-window duration, for example `15m` |
| `resolution`                   | string  | `1s` or `30s`                                  |
| `timestamp`                    | integer | Candle bucket start, in Unix seconds           |
| `open`, `high`, `low`, `close` | string  | Underlying prices as decimal strings           |
| `provider`                     | string  | Price provider                                 |
| `feed_id`                      | string  | Underlying price feed identifier               |

These candles describe the underlying price feed, not the binary options order book. Use [upDownCandles](https://docs.lighter.xyz/api-reference/binary-options) for REST history; see [Discover markets](/developers/binary-options/discover-markets.md#underlying-price) for an example.


---

# 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/binary-options/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.
