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

# Opera WebSocket

> Upgrade to WebSocket. All Opera traffic is JSON text frames.

**Client actions** (set `action`):
- `operaConnect` — `{ token, requestId? }` required for external bots (marks the socket as API; cannot call bot-mode / session record/reset)
- `operaPlace` — single order fields or `{ orders: [...] }` (max 40)
- `operaCancel` — `{ orderId }`
- `operaCancelAll`
- `operaGetState`

Optional `requestId` is echoed on `operaResult`. The browser UI authenticates with `userConnected` (not `operaConnect`); UI-only ops are gated by that connection kind, not by a client `source` field.

**Server messages** (set `type`):
- `operaResult` — reply to a client action (`op`, `status`, body fields)
- `operaState` — snapshot push after mutations
- `orderBook` — live book / participants



## OpenAPI

````yaml /api-reference/openapi.json get /ws
openapi: 3.1.0
info:
  title: Opera WebSocket API
  description: >-
    WebSocket API for the Opera trading simulator. Connect to `/ws`,
    authenticate with `operaConnect` using a Clerk session JWT from the Avenir
    /opera page, then send place/cancel/state messages. The server pushes
    `operaState` and `orderBook` updates.
  version: 2.0.0
servers:
  - url: wss://www.getavenir.co/ws
    description: Production WebSocket
  - url: ws://localhost:3000/ws
    description: Local development WebSocket
security: []
tags:
  - name: Connection
    description: Authenticate and receive live updates
  - name: Orders
    description: Place and cancel orders
  - name: Snapshot
    description: Open orders, position, and activity
paths:
  /ws:
    get:
      tags:
        - Connection
      summary: Opera WebSocket
      description: >-
        Upgrade to WebSocket. All Opera traffic is JSON text frames.


        **Client actions** (set `action`):

        - `operaConnect` — `{ token, requestId? }` required for external bots
        (marks the socket as API; cannot call bot-mode / session record/reset)

        - `operaPlace` — single order fields or `{ orders: [...] }` (max 40)

        - `operaCancel` — `{ orderId }`

        - `operaCancelAll`

        - `operaGetState`


        Optional `requestId` is echoed on `operaResult`. The browser UI
        authenticates with `userConnected` (not `operaConnect`); UI-only ops are
        gated by that connection kind, not by a client `source` field.


        **Server messages** (set `type`):

        - `operaResult` — reply to a client action (`op`, `status`, body fields)

        - `operaState` — snapshot push after mutations

        - `orderBook` — live book / participants
      operationId: operaWebSocket
      responses:
        '101':
          description: Switching Protocols

````