> For the complete documentation index, see [llms.txt](https://dexhunter.gitbook.io/dexhunter-partners/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dexhunter.gitbook.io/dexhunter-partners/data/charts.md).

# Charts

Get OHLCV candlestick data for trading pairs.

{% hint style="warning" %}
**Required:** Include `X-Partner-Id` header with your API key on all requests.

**Base URL:** `https://charts.dhapi.io`
{% endhint %}

***

## Get Chart Data

Fetch historical OHLCV data.

**Endpoint**

`POST /charts`

**Payload**

| Field      | Type   | Required | Description                    |
| ---------- | ------ | -------- | ------------------------------ |
| `tokenIn`  | string | ✓        | Base token (`""` for ADA)      |
| `tokenOut` | string | ✓        | Quote token                    |
| `period`   | string | ✓        | Candle period                  |
| `from`     | number | ✓        | Start timestamp (unix seconds) |
| `to`       | number | ✓        | End timestamp (unix seconds)   |

**Response**

| Field  | Type  | Description   |
| ------ | ----- | ------------- |
| `data` | array | OHLCV candles |

**Candle Object**

| Field    | Type   | Description    |
| -------- | ------ | -------------- |
| `time`   | number | Unix timestamp |
| `open`   | number | Open price     |
| `high`   | number | High price     |
| `low`    | number | Low price      |
| `close`  | number | Close price    |
| `volume` | number | Volume         |

***

## Period Types

| Period  | Description |
| ------- | ----------- |
| `20s`   | 20 seconds  |
| `1min`  | 1 minute    |
| `5min`  | 5 minutes   |
| `15min` | 15 minutes  |
| `1hour` | 1 hour      |
| `4hour` | 4 hours     |
| `1day`  | 1 day       |
| `1week` | 1 week      |

***

## Examples

{% tabs %}
{% tab title="24h hourly chart" %}

```javascript
const API_KEY = 'YOUR_API_KEY';
const CHART_URL = 'https://charts.dhapi.io';
const headers = { 'X-Partner-Id': API_KEY };

const NIGHT = '0691b2fecca1ac4f53cb6dfb00b7013e561d1f34403b957cbb5af1fa4e49474854';
const to = Math.floor(Date.now() / 1000);
const from = to - 24 * 60 * 60;

const { data } = await axios.post(`${CHART_URL}/charts`, {
  tokenIn: '',
  tokenOut: NIGHT,
  period: '1hour',
  from,
  to,
}, { headers });
```

{% endtab %}

{% tab title="7-day 4h chart" %}

```javascript
const to = Math.floor(Date.now() / 1000);
const from = to - 7 * 24 * 60 * 60;

const { data } = await axios.post(`${CHART_URL}/charts`, {
  tokenIn: '',
  tokenOut: NIGHT,
  period: '4hour',
  from,
  to,
}, { headers });
```

{% endtab %}
{% endtabs %}

***

## WebSocket (Real-time)

Subscribe to live candle updates.

**URL Format**

`wss://charts.dhapi.io/ws/lastCandle/{pair}/{period}`

**Pair Format**

* ADA pair: `ADA/{tokenId}`
* Token pair: `{tokenId1}/{tokenId2}`

**Supported Periods**

`20s` · `1min` · `5min` · `15min` · `1hour` · `4hour`

{% hint style="info" %}
`1day` and `1week` do not support WebSocket streaming.
{% endhint %}

{% tabs %}
{% tab title="Example" %}

```javascript
const NIGHT = '0691b2fecca1ac4f53cb6dfb00b7013e561d1f34403b957cbb5af1fa4e49474854';

const socket = new WebSocket(`wss://charts.dhapi.io/ws/lastCandle/ADA/${NIGHT}/5min`);

socket.onmessage = (event) => {
  const candle = JSON.parse(event.data);
  console.log('Live candle:', candle);
};
```

{% endtab %}
{% endtabs %}
