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

# Order Status WebSocket

> Upgrade to a WebSocket connection to receive real-time order status events.

Authentication is performed over the WebSocket protocol using a `connect` message, so no HTTP headers are required during the upgrade handshake.

### Protocol

**Step 1 - Authenticate** (must be the first message sent):
```json
{"type":"connect","data":{"api_key":"<your_api_key>"}}
```
For organization-wide subscriptions, include an authorization signature generated for `GET /ws`:
```json
{"type":"connect","data":{"api_key":"<your_api_key>","authorization_signature":"APIKey=<your_api_key>,signature=<signature>,timestamp=<timestamp>"}}
```
Server responds on success:
```json
{"type":"connected","data":{"status":"authenticated"}}
```

**Step 2 - Subscribe** to a specific order:
```json
{"type":"subscribe","data":{"order_id":"<id>"}}
```
Server responds:
```json
{"type":"subscription","data":{"order_id":"<id>","scope":"order","status":"subscribed"}}
```

**Subscribe to all orders** in your organization (requires signed connect; omit `order_id` or leave it empty):
```json
{"type":"subscribe","data":{}}
```
Server responds:
```json
{"type":"subscription","data":{"scope":"organization","status":"subscribed"}}
```

**Unsubscribe** from a specific order:
```json
{"type":"unsubscribe","data":{"order_id":"<id>"}}
```
**Unsubscribe** from all org orders:
```json
{"type":"unsubscribe","data":{}}
```

**Server push - Order event:**
```json
{"type":"event","data":{...order event payload...}}
```

**Server message types:**
- `connected` - authentication succeeded
- `subscription` - confirms subscribe/unsubscribe; includes `scope` (`"order"` or `"organization"`)
- `event` - real-time order status change
- `error` - describes what went wrong (e.g. invalid api_key, not authenticated, access denied)

**Notes:**
- Clients must send `connect` before any `subscribe`/`unsubscribe` messages.
- Clients can only subscribe to orders belonging to their own organization.
- Organization-wide subscriptions require a valid `authorization_signature`; API-key-only connections can subscribe to specific orders only.
- A client subscribed at org level receives events for all orders; specific-order and org-level subscriptions can coexist.




## OpenAPI

````yaml https://api.coinvoyage.io/v2/openapi.json get /ws
openapi: 3.1.0
info:
  title: CoinVoyage API
  description: Cryptocurrency payment processing API
  version: 2.2.0
servers:
  - url: https://api.coinvoyage.io/v2
security: []
paths:
  /ws:
    get:
      tags:
        - websocket
      summary: Order Status WebSocket
      description: >
        Upgrade to a WebSocket connection to receive real-time order status
        events.


        Authentication is performed over the WebSocket protocol using a
        `connect` message, so no HTTP headers are required during the upgrade
        handshake.


        ### Protocol


        **Step 1 - Authenticate** (must be the first message sent):

        ```json

        {"type":"connect","data":{"api_key":"<your_api_key>"}}

        ```

        For organization-wide subscriptions, include an authorization signature
        generated for `GET /ws`:

        ```json

        {"type":"connect","data":{"api_key":"<your_api_key>","authorization_signature":"APIKey=<your_api_key>,signature=<signature>,timestamp=<timestamp>"}}

        ```

        Server responds on success:

        ```json

        {"type":"connected","data":{"status":"authenticated"}}

        ```


        **Step 2 - Subscribe** to a specific order:

        ```json

        {"type":"subscribe","data":{"order_id":"<id>"}}

        ```

        Server responds:

        ```json

        {"type":"subscription","data":{"order_id":"<id>","scope":"order","status":"subscribed"}}

        ```


        **Subscribe to all orders** in your organization (requires signed
        connect; omit `order_id` or leave it empty):

        ```json

        {"type":"subscribe","data":{}}

        ```

        Server responds:

        ```json

        {"type":"subscription","data":{"scope":"organization","status":"subscribed"}}

        ```


        **Unsubscribe** from a specific order:

        ```json

        {"type":"unsubscribe","data":{"order_id":"<id>"}}

        ```

        **Unsubscribe** from all org orders:

        ```json

        {"type":"unsubscribe","data":{}}

        ```


        **Server push - Order event:**

        ```json

        {"type":"event","data":{...order event payload...}}

        ```


        **Server message types:**

        - `connected` - authentication succeeded

        - `subscription` - confirms subscribe/unsubscribe; includes `scope`
        (`"order"` or `"organization"`)

        - `event` - real-time order status change

        - `error` - describes what went wrong (e.g. invalid api_key, not
        authenticated, access denied)


        **Notes:**

        - Clients must send `connect` before any `subscribe`/`unsubscribe`
        messages.

        - Clients can only subscribe to orders belonging to their own
        organization.

        - Organization-wide subscriptions require a valid
        `authorization_signature`; API-key-only connections can subscribe to
        specific orders only.

        - A client subscribed at org level receives events for all orders;
        specific-order and org-level subscriptions can coexist.
      operationId: wsOrderStatus
      responses:
        '101':
          description: Switching Protocols - WebSocket connection established
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Bad Request - WebSocket upgrade failed
components:
  schemas:
    ErrorResponse:
      example:
        code: 400
        error: Bad Request
        message: Invalid request parameters
      properties:
        error:
          example: Bad Request
          type: string
        message:
          example: Invalid request parameters
          type: string
        code:
          example: 400
          format: int64
          type: integer
        details:
          anyOf:
            - type: string
            - type: number
            - type: object
      required:
        - error
        - message
        - code
      type: object

````