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

# chart

Subscribe to real-time OHLCV chart data with configurable resolution and chart type for technical analysis.

## Chart Types

* `mark` - Mark price data
* `index` - Index price data
* `ltp` - LTP price data

## Resolutions

* `1`, `5`, `15`, `30` - Minute intervals (1, 5, 15, 30 minutes)
* `60`, `240` - Hour intervals (1 hour, 4 hours)
* `1D`, `1W` - Day/week intervals

## Example Request

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "subscribe",
  "params": {
    "channel": "chart",
    "symbol": "1",
    "chart_type": "mark",
    "resolution": "1"
  }
}
```

## Example Response

```json theme={null}
{
  "jsonrpc": "2.0",
  "method": "event",
  "params": {
    "channel": "chart:1:index:1",
    "data": {
      "time": 1770860580000,
      "open": "67965.20189",
      "high": "67965.20189",
      "low": "67951.616513",
      "close": "67951.616513",
      "volume": "0.0029"
    }
  }
}
```

## 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": "chart",
            "symbol": "1",
            "chart_type": "mark",
            "resolution": "1"
        }
    }
    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: "chart",
      symbol: "1",
      chart_type: "mark",
      resolution: "1",
    },
  };
  ws.send(JSON.stringify(subscribeMsg));
};

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


## AsyncAPI

````yaml asyncapi/ws-subscriptions.json chart
id: chart
title: Chart
description: ''
servers:
  - id: production
    protocol: wss
    host: api.hotstuff.trade/ws
    bindings: []
    variables: []
address: /
parameters: []
bindings: []
operations:
  - &ref_9
    id: chart_sendSubscribe
    title: Chart_send subscribe
    type: receive
    messages:
      - &ref_11
        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 `chart`
                    examples: &ref_3
                      - chart
                    required: true
                  - name: instrument_id
                    type: integer
                    description: instrument id, e.g. `1` for `BTC-PERP`
                    examples: &ref_4
                      - 1
                    required: false
                  - name: chart_type
                    type: string
                    enumValues:
                      - mark
                      - index
                      - ltp
                    examples: &ref_5
                      - mark
                      - index
                      - ltp
                    required: true
                  - name: resolution
                    type: string
                    enumValues:
                      - '1'
                      - '5'
                      - '15'
                      - '30'
                      - '60'
                      - '240'
                      - 1D
                      - 1W
                    examples: &ref_6
                      - '1'
                    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-89>
            id:
              type: integer
              default: 1
              examples: *ref_1
              description: Client request identifier
              x-parser-schema-id: <anonymous-schema-90>
            method:
              type: string
              enum:
                - subscribe
                - unsubscribe
              default: subscribe
              examples: *ref_2
              description: Subscription action
              x-parser-schema-id: <anonymous-schema-91>
            params:
              type: object
              properties:
                channel:
                  type: string
                  description: Must be `chart`
                  default: chart
                  examples: *ref_3
                  x-parser-schema-id: <anonymous-schema-93>
                instrument_id:
                  type: integer
                  description: instrument id, e.g. `1` for `BTC-PERP`
                  default: 1
                  examples: *ref_4
                  x-parser-schema-id: <anonymous-schema-94>
                chart_type:
                  type: string
                  enum:
                    - mark
                    - index
                    - ltp
                  default: mark
                  examples: *ref_5
                  x-parser-schema-id: <anonymous-schema-95>
                resolution:
                  type: string
                  enum:
                    - '1'
                    - '5'
                    - '15'
                    - '30'
                    - '60'
                    - '240'
                    - 1D
                    - 1W
                  default: '1'
                  examples: *ref_6
                  x-parser-schema-id: <anonymous-schema-96>
              required:
                - channel
                - symbol
                - chart_type
                - resolution
              description: Channel subscription parameters
              x-parser-schema-id: <anonymous-schema-92>
          required:
            - jsonrpc
            - id
            - method
            - params
          x-parser-schema-id: <anonymous-schema-88>
        title: Subscription request
        description: Send subscribe/unsubscribe request
        example: |-
          {
            "jsonrpc": "2.0",
            "id": 1,
            "method": "subscribe",
            "params": {
              "channel": "chart",
              "instrument_id": 1,
              "chart_type": "mark",
              "resolution": "1"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: a_subscribeRequest
    bindings: []
    extensions: &ref_8
      - id: x-parser-unique-object-id
        value: chart
  - &ref_10
    id: chart_receiveEvent
    title: Chart_receive event
    type: send
    messages:
      - &ref_12
        id: event
        contentType: application/json
        payload:
          - name: Chart channel event
            description: Server-pushed JSON-RPC event
            type: object
            properties:
              - name: jsonrpc
                type: string
                required: false
              - name: method
                type: string
                required: false
              - name: params
                type: object
                required: false
                properties:
                  - name: channel
                    type: string
                    description: >-
                      returns `chart:<instrument_id>:<chart_type>:<resolution>`
                      when subscribed to a specific instrument and resolution
                    examples: &ref_7
                      - chart:1:index:1
                      - chart:1:mark:1
                      - chart:1:ltp:1
                      - chart:1:index:5
                      - chart:1:mark:5
                      - chart:1:ltp:5
                      - chart:1:index:15
                      - chart:1:mark:15
                      - chart:1:ltp:15
                      - chart:1:index:30
                      - chart:1:mark:30
                      - chart:1:ltp:30
                      - chart:1:index:60
                      - chart:1:mark:60
                      - chart:1:ltp:60
                      - chart:1:index:240
                      - chart:1:mark:240
                      - chart:1:ltp:240
                      - chart:1:index:1D
                      - chart:1:mark:1D
                      - chart:1:ltp:1D
                      - chart:1:index:1W
                      - chart:1:mark:1W
                      - chart:1:ltp:1W
                    required: false
                  - name: data
                    type: object
                    required: false
                    properties:
                      - name: time
                        type: integer
                        required: false
                      - name: open
                        type: string
                        required: false
                      - name: high
                        type: string
                        required: false
                      - name: low
                        type: string
                        required: false
                      - name: close
                        type: string
                        required: false
                      - name: volume
                        type: string
                        required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            jsonrpc:
              type: string
              x-parser-schema-id: <anonymous-schema-98>
            method:
              type: string
              x-parser-schema-id: <anonymous-schema-99>
            params:
              type: object
              properties:
                channel:
                  type: string
                  description: >-
                    returns `chart:<instrument_id>:<chart_type>:<resolution>`
                    when subscribed to a specific instrument and resolution
                  examples: *ref_7
                  x-parser-schema-id: <anonymous-schema-101>
                data:
                  type: object
                  properties:
                    time:
                      type: integer
                      x-parser-schema-id: <anonymous-schema-103>
                    open:
                      type: string
                      x-parser-schema-id: <anonymous-schema-104>
                    high:
                      type: string
                      x-parser-schema-id: <anonymous-schema-105>
                    low:
                      type: string
                      x-parser-schema-id: <anonymous-schema-106>
                    close:
                      type: string
                      x-parser-schema-id: <anonymous-schema-107>
                    volume:
                      type: string
                      x-parser-schema-id: <anonymous-schema-108>
                  x-parser-schema-id: <anonymous-schema-102>
              x-parser-schema-id: <anonymous-schema-100>
          x-parser-schema-id: <anonymous-schema-97>
        title: Chart channel event
        description: Server-pushed JSON-RPC event
        example: |-
          {
            "jsonrpc": "2.0",
            "method": "event",
            "params": {
              "channel": "chart:1:index:1",
              "data": {
                "time": 1770860580000,
                "open": "67965.20189",
                "high": "67965.20189",
                "low": "67951.616513",
                "close": "67951.616513",
                "volume": "0.0029"
              }
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: event
    bindings: []
    extensions: *ref_8
sendOperations:
  - *ref_9
receiveOperations:
  - *ref_10
sendMessages:
  - *ref_11
receiveMessages:
  - *ref_12
extensions:
  - id: x-parser-unique-object-id
    value: chart
securitySchemes: []

````

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