> ## 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.

# Tutorial

> WebSocket API for the guided Tutorial simulator

Tutorial binds a UI WebSocket, runs a step machine, and evaluates your ladder actions against the current step.

Product overview: [Tutorial](/tutorial). Shared connect and `placeOrder` fields: [API overview](/api-reference/introduction).

## Protocol

1. Connect to `wss://www.getavenir.co/ws`
2. `{ "action": "userConnected", "token": "<Clerk JWT>", "applicationType": "tutorial" }`
3. Receive `orderBook` and `tutorialInstruction`
4. Trade with `placeOrder` / `cancelOrder` / `cancelAllOrders`, or advance with `tutorialNext` / `tutorialPrevious`
5. Disconnect clears tutorial progress (nothing is logged as a past session)

## Client actions

| Action                                           | Body                                                 | Effect                                    |
| ------------------------------------------------ | ---------------------------------------------------- | ----------------------------------------- |
| `userConnected`                                  | `token`, `applicationType: "tutorial"`, `sessionId?` | Bind UI socket; bootstrap or resume steps |
| `tutorialReady`                                  | —                                                    | Re-send the current instruction           |
| `tutorialNext`                                   | `stepId?`                                            | Advance when the step allows Next         |
| `tutorialPrevious`                               | `stepId?`                                            | Go back when the step has a previous link |
| `tutorialQuantityChange`                         | `size`                                               | Set tutorial order size                   |
| `tutorialTourComplete`                           | `stepId` (expect `S21`)                              | Mark the in-app tour complete             |
| `tutorialUserOrderColumnClick`                   | `stepId: "S4"`, `price`                              | Ack the highlighted price column          |
| `placeOrder` / `cancelOrder` / `cancelAllOrders` | See [overview](/api-reference/introduction)          | Instrument `0`; may advance the step      |
| `setBotsActive`                                  | `active: false`                                      | Bots off (leave)                          |

Bot on/off during the walkthrough is **server-driven per step**. Do not use `toggleBots`.

## Server messages

### `tutorialInstruction`

```json theme={null}
{
  "type": "tutorialInstruction",
  "stepId": "S4",
  "stepNumber": 4,
  "stepTotal": 22,
  "replace": { "en": "…", "fr": "…" },
  "hint": "…",
  "showNext": true,
  "showPrevious": true,
  "nextDisabled": false,
  "autoStartTour": false,
  "isTerminal": false,
  "eventVersion": 1
}
```

| Field                       | Notes                         |
| --------------------------- | ----------------------------- |
| `stepId`                    | Stable step key (e.g. `S4`)   |
| `replace`                   | Localized instruction text    |
| `showNext` / `showPrevious` | Whether UI nav buttons apply  |
| `isTerminal`                | Final step; tutorial complete |

### `orderBook`

Standard book for instrument `0`.

## Related

* Guide: [Tutorial](/tutorial)
* Shared auth and orders: [API overview](/api-reference/introduction)
