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

# 4casters Orders API

The 4casters Orders API supports real-time order placement, cancellation, and session management over a raw WebSocket connection.

## Endpoints

* **Orders API**: `wss://orders-api.4casters.io/orders/ws`

## Auth

The connection authenticates with a 4Casters token. Send the token in the
`Authorization` header on the WebSocket handshake. The server derives the user
from the token — **no username in the URL**.

### Get a token

Log in with your 4Casters username and password by calling the `/user/login`
endpoint of the 4Casters REST API. The response includes a token you can use
here.

See [`POST /user/login` in the 4Casters REST API docs](/pages/rest/authentication).

### Connect

<CodeGroup>
  ```javascript JavaScript theme={null}
  const WebSocket = require('ws');
  const token = process.env.FOURCASTERS_TOKEN;
  const ws = new WebSocket('wss://orders-api.4casters.io/orders/ws', {
    headers: { Authorization: token },
  });
  ```
</CodeGroup>

## Message format

Every client request is a 2-tuple `[messageType, payload]`. Every payload should include a `requestID` that you generate; the server echoes it back so you can correlate responses.

<CodeGroup>
  ```json Request theme={null}
  [
    "messageType",
    {
      "requestID": "YOUR_REQUEST_ID",
      "...": "..."
    }
  ]
  ```
</CodeGroup>

Server responses are JSON objects with `requestID` plus either `data` (success) or `error` (failure):

<CodeGroup>
  ```json Success theme={null}
  {
    "requestID": "YOUR_REQUEST_ID",
    "data": { "...": "..." }
  }
  ```

  ```json Error theme={null}
  {
    "requestID": "YOUR_REQUEST_ID",
    "error": "human-readable error"
  }
  ```
</CodeGroup>
