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

# orders

Subscribe to real-time user order status updates.

## Example Request

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "subscribe",
  "params": {
    "channel": "orders",
    "user": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
  }
}
```

## Example Response

```json theme={null}
{
  "jsonrpc": "2.0",
  "method": "event",
  "params": {
    "channel": "orders@0x42C183edba036906447372a7c81Eb89D0B9f2175",
    "data": {
      "instrument_id": 1,
      "instrument": "BTC-PERP",
      "account": "0x42C183edba036906447372a7c81Eb89D0B9f2175",
      "tif": "GTC",
      "order_id": 172561523,
      "cloid": "69901641-e0ad-47eb-80bf-f285321f5bd0",
      "side": "b",
      "position_side": "BOTH",
      "limit_price": "67977",
      "size": "0.06107",
      "old_price": "67977",
      "old_size": "0.06107",
      "unfilled": "0.05737",
      "state": "open",
      "reduce_only": false,
      "post_only": false,
      "timestamp": 1770854411081
    }
  }
}
```

## WebSocket Client Examples

### Python

```python theme={null}
import websocket
import json

def on_message(ws, message):
    print(f"Received: {message}")

def on_open(ws):
    subscribe_msg = {
        "jsonrpc": "2.0",
        "id": "1",
        "method": "subscribe",
        "params": {
            "channel": "orders",
            "user": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
        }
    }
    ws.send(json.dumps(subscribe_msg))

ws = websocket.WebSocketApp("wss://api.hotstuff.trade/ws",
                          on_message=on_message,
                          on_open=on_open)
ws.run_forever()
```

### JavaScript

```javascript theme={null}
const ws = new WebSocket("wss://api.hotstuff.trade/ws");

ws.onopen = function () {
  const subscribeMsg = {
    jsonrpc: "2.0",
    id: "1",
    method: "subscribe",
    params: {
      channel: "orders",
      user: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
    },
  };
  ws.send(JSON.stringify(subscribeMsg));
};

ws.onmessage = function (event) {
  console.log("Received:", event.data);
};
```


## AsyncAPI

````yaml asyncapi/ws-subscriptions.json orders
id: orders
title: Orders
description: ''
servers:
  - id: production
    protocol: wss
    host: api.hotstuff.trade/ws
    bindings: []
    variables: []
address: /
parameters: []
bindings: []
operations:
  - &ref_10
    id: orders_sendSubscribe
    title: Orders_send subscribe
    type: receive
    messages:
      - &ref_12
        id: a_subscribeRequest
        contentType: application/json
        payload:
          - name: Subscription request
            description: Send subscribe/unsubscribe request
            type: object
            properties:
              - name: jsonrpc
                type: string
                description: JSON-RPC version
                examples: &ref_0
                  - '2.0'
                required: true
              - name: id
                type: integer
                description: Client request identifier
                examples: &ref_1
                  - 1
                required: true
              - name: method
                type: string
                description: Subscription action
                enumValues:
                  - subscribe
                  - unsubscribe
                examples: &ref_2
                  - subscribe
                required: true
              - name: params
                type: object
                description: Channel subscription parameters
                required: true
                properties:
                  - name: channel
                    type: string
                    description: Must be `orders`
                    examples: &ref_3
                      - orders
                    required: true
                  - name: user
                    type: string
                    description: 'Example: 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
                    examples: &ref_4
                      - '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
                    required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            jsonrpc:
              type: string
              default: '2.0'
              examples: *ref_0
              description: JSON-RPC version
              x-parser-schema-id: <anonymous-schema-212>
            id:
              type: integer
              default: 1
              examples: *ref_1
              description: Client request identifier
              x-parser-schema-id: <anonymous-schema-213>
            method:
              type: string
              enum:
                - subscribe
                - unsubscribe
              default: subscribe
              examples: *ref_2
              description: Subscription action
              x-parser-schema-id: <anonymous-schema-214>
            params:
              type: object
              properties:
                channel:
                  type: string
                  description: Must be `orders`
                  default: orders
                  examples: *ref_3
                  x-parser-schema-id: <anonymous-schema-216>
                user:
                  type: string
                  description: 'Example: 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
                  default: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
                  examples: *ref_4
                  x-parser-schema-id: <anonymous-schema-217>
              required:
                - channel
                - user
              description: Channel subscription parameters
              x-parser-schema-id: <anonymous-schema-215>
          required:
            - jsonrpc
            - id
            - method
            - params
          x-parser-schema-id: <anonymous-schema-211>
        title: Subscription request
        description: Send subscribe/unsubscribe request
        example: |-
          {
            "jsonrpc": "2.0",
            "id": 1,
            "method": "subscribe",
            "params": {
              "channel": "orders",
              "user": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: a_subscribeRequest
    bindings: []
    extensions: &ref_9
      - id: x-parser-unique-object-id
        value: orders
  - &ref_11
    id: orders_receiveEvent
    title: Orders_receive event
    type: send
    messages:
      - &ref_13
        id: event
        contentType: application/json
        payload:
          - name: Channel event
            description: Server-pushed JSON-RPC event
            type: object
            properties:
              - name: jsonrpc
                type: string
                description: JSON-RPC version, must be `2.0`
                examples: &ref_5
                  - '2.0'
                required: false
              - name: method
                type: string
                description: '`event`'
                examples: &ref_6
                  - event
                required: false
              - name: params
                type: object
                required: false
                properties:
                  - name: channel
                    type: string
                    description: '`orders@<user>`'
                    examples: &ref_7
                      - orders@0x42C183edba036906447372a7c81Eb89D0B9f2175
                    required: false
                  - name: data
                    type: object
                    required: false
                    properties:
                      - name: instrument_id
                        type: integer
                        required: false
                      - name: instrument
                        type: string
                        required: false
                      - name: account
                        type: string
                        required: false
                      - name: tif
                        type: string
                        description: time in force
                        examples: &ref_8
                          - GTC
                          - IOC
                          - FOK
                        required: false
                      - name: order_id
                        type: integer
                        required: false
                      - name: cloid
                        type: string
                        description: client order id, hex string
                        required: false
                      - name: side
                        type: string
                        description: side of the order, one of `b` (buy) or `s` (sell)
                        enumValues:
                          - b
                          - s
                        required: false
                      - name: position_side
                        type: string
                        description: >-
                          position side, one of `BOTH` (both long and short),
                          `LONG` (long only), or `SHORT` (short only)
                        enumValues:
                          - BOTH
                          - LONG
                          - SHORT
                        required: false
                      - name: limit_price
                        type: string
                        required: false
                      - name: size
                        type: string
                        required: false
                      - name: old_price
                        type: string
                        required: false
                      - name: old_size
                        type: string
                        required: false
                      - name: unfilled
                        type: string
                        required: false
                      - name: state
                        type: string
                        description: >-
                          state of the order, one of `open`, `filled`,
                          `cancelled`. `pending`, or `triggered` if order is a
                          TP/SL order
                        enumValues:
                          - open
                          - filled
                          - cancelled
                          - pending
                          - triggered
                        required: false
                      - name: reduce_only
                        type: boolean
                        description: reduce only flag
                        required: false
                      - name: post_only
                        type: boolean
                        description: post only flag
                        required: false
                      - name: timestamp
                        type: integer
                        required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            jsonrpc:
              type: string
              description: JSON-RPC version, must be `2.0`
              examples: *ref_5
              x-parser-schema-id: <anonymous-schema-219>
            method:
              type: string
              description: '`event`'
              examples: *ref_6
              x-parser-schema-id: <anonymous-schema-220>
            params:
              type: object
              properties:
                channel:
                  type: string
                  description: '`orders@<user>`'
                  examples: *ref_7
                  x-parser-schema-id: <anonymous-schema-222>
                data:
                  type: object
                  properties:
                    instrument_id:
                      type: integer
                      x-parser-schema-id: <anonymous-schema-224>
                    instrument:
                      type: string
                      x-parser-schema-id: <anonymous-schema-225>
                    account:
                      type: string
                      x-parser-schema-id: <anonymous-schema-226>
                    tif:
                      type: string
                      description: time in force
                      examples: *ref_8
                      x-parser-schema-id: <anonymous-schema-227>
                    order_id:
                      type: integer
                      x-parser-schema-id: <anonymous-schema-228>
                    cloid:
                      type: string
                      description: client order id, hex string
                      x-parser-schema-id: <anonymous-schema-229>
                    side:
                      type: string
                      enum:
                        - b
                        - s
                      description: side of the order, one of `b` (buy) or `s` (sell)
                      x-parser-schema-id: <anonymous-schema-230>
                    position_side:
                      type: string
                      enum:
                        - BOTH
                        - LONG
                        - SHORT
                      description: >-
                        position side, one of `BOTH` (both long and short),
                        `LONG` (long only), or `SHORT` (short only)
                      x-parser-schema-id: <anonymous-schema-231>
                    limit_price:
                      type: string
                      x-parser-schema-id: <anonymous-schema-232>
                    size:
                      type: string
                      x-parser-schema-id: <anonymous-schema-233>
                    old_price:
                      type: string
                      x-parser-schema-id: <anonymous-schema-234>
                    old_size:
                      type: string
                      x-parser-schema-id: <anonymous-schema-235>
                    unfilled:
                      type: string
                      x-parser-schema-id: <anonymous-schema-236>
                    state:
                      type: string
                      enum:
                        - open
                        - filled
                        - cancelled
                        - pending
                        - triggered
                      description: >-
                        state of the order, one of `open`, `filled`,
                        `cancelled`. `pending`, or `triggered` if order is a
                        TP/SL order
                      x-parser-schema-id: <anonymous-schema-237>
                    reduce_only:
                      type: boolean
                      description: reduce only flag
                      x-parser-schema-id: <anonymous-schema-238>
                    post_only:
                      type: boolean
                      description: post only flag
                      x-parser-schema-id: <anonymous-schema-239>
                    timestamp:
                      type: integer
                      x-parser-schema-id: <anonymous-schema-240>
                  x-parser-schema-id: <anonymous-schema-223>
              x-parser-schema-id: <anonymous-schema-221>
          x-parser-schema-id: <anonymous-schema-218>
        title: Channel event
        description: Server-pushed JSON-RPC event
        example: |-
          {
            "jsonrpc": "2.0",
            "method": "event",
            "params": {
              "channel": "orders@0x42C183edba036906447372a7c81Eb89D0B9f2175",
              "data": {
                "instrument_id": 1,
                "instrument": "BTC-PERP",
                "account": "0x42C183edba036906447372a7c81Eb89D0B9f2175",
                "tif": "GTC",
                "order_id": 172561523,
                "cloid": "69901641-e0ad-47eb-80bf-f285321f5bd0",
                "side": "b",
                "position_side": "BOTH",
                "limit_price": "67977",
                "size": "0.06107",
                "old_price": "67977",
                "old_size": "0.06107",
                "unfilled": "0.05737",
                "state": "open",
                "reduce_only": false,
                "post_only": false,
                "timestamp": 1770854411081
              }
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: event
    bindings: []
    extensions: *ref_9
sendOperations:
  - *ref_10
receiveOperations:
  - *ref_11
sendMessages:
  - *ref_12
receiveMessages:
  - *ref_13
extensions:
  - id: x-parser-unique-object-id
    value: orders
securitySchemes: []

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.