> 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/trading/dca.md).

# DCA

Dollar Cost Averaging — automatically split trades over time.

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

**Base URL:** `https://api-us.dexhunterv3.app`
{% endhint %}

***

## Create DCA Order

Build a DCA order transaction.

**Endpoint**

`POST /dca/create`

**Payload**

| Field             | Type   | Required | Description                  |
| ----------------- | ------ | -------- | ---------------------------- |
| `user_address`    | string | ✓        | User's Cardano address       |
| `token_in`        | string | ✓        | Token to sell (`""` for ADA) |
| `token_out`       | string | ✓        | Token to buy                 |
| `amount_in`       | number | ✓        | Total amount in ADA          |
| `interval`        | string | ✓        | Interval type                |
| `interval_length` | number | ✓        | Interval multiplier          |
| `slippage`        | number | ✓        | Slippage %                   |
| `cycles`          | number | ✓        | Number of trades             |
| `dex_allowlist`   | array  |          | Limit to specific DEXes      |

**Response**

| Field  | Type   | Description              |
| ------ | ------ | ------------------------ |
| `cbor` | string | Transaction CBOR to sign |

***

## Get User DCAs

Fetch active DCA orders for an address.

**Endpoint**

`GET /dca/{address}`

**Response**

Array of DCA order objects:

| Field              | Type   | Description              |
| ------------------ | ------ | ------------------------ |
| `_id`              | string | DCA order ID             |
| `user_address`     | string | User's address           |
| `token_in`         | string | Token being sold         |
| `token_out`        | string | Token being bought       |
| `amount_in`        | number | Amount per cycle         |
| `interval`         | string | Interval type            |
| `interval_length`  | number | Interval multiplier      |
| `cycles`           | number | Total cycles             |
| `cycles_completed` | number | Completed cycles         |
| `next_execution`   | string | Next execution timestamp |
| `status`           | string | Order status             |

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

```javascript
const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://api-us.dexhunterv3.app';
const headers = { 'X-Partner-Id': API_KEY };

const address = 'addr1qx2kd28nq8ac5pr...';

const { data: dcas } = await axios.get(`${BASE_URL}/dca/${address}`, {
  headers,
});

console.log(dcas);
// [
//   {
//     _id: "dca_abc123",
//     token_in: "",
//     token_out: "0691b2fec...",
//     amount_in: 10,
//     interval: "daily",
//     cycles: 10,
//     cycles_completed: 3,
//     next_execution: "2024-01-16T10:00:00Z",
//     status: "ACTIVE"
//   }
// ]
```

{% endtab %}
{% endtabs %}

***

## Interval Types

| interval   | interval\_length | Result           |
| ---------- | ---------------- | ---------------- |
| `minutely` | 1                | Every 1 minute   |
| `minutely` | 5                | Every 5 minutes  |
| `minutely` | 15               | Every 15 minutes |
| `minutely` | 30               | Every 30 minutes |
| `hourly`   | 1                | Every 1 hour     |
| `hourly`   | 2                | Every 2 hours    |
| `hourly`   | 4                | Every 4 hours    |
| `daily`    | 1                | Every 1 day      |
| `weekly`   | 1                | Every 1 week     |
| `monthly`  | 1                | Every 1 month    |

***

## Create Examples

{% tabs %}
{% tab title="Daily for 10 days" %}
100 ADA total → 10 daily purchases of 10 ADA each

```javascript
const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://api-us.dexhunterv3.app';
const headers = { 'X-Partner-Id': API_KEY };

const payload = {
  user_address: 'addr1qx2kd28nq8ac5pr...',
  token_in: '',
  token_out:
    '0691b2fecca1ac4f53cb6dfb00b7013e561d1f34403b957cbb5af1fa4e49474854',
  amount_in: 100,
  interval: 'daily',
  interval_length: 1,
  slippage: 5,
  cycles: 10,
};

const { data: swap } = await axios.post(`${BASE_URL}/dca/create`, payload, {
  headers,
});
const signatures = await wallet.signTx(swap.cbor, true);
const { data: signed } = await axios.post(
  `${BASE_URL}/swap/sign`,
  { txCbor: swap.cbor, signatures },
  { headers }
);
const txHash = await wallet.submitTx(signed.cbor);
```

{% endtab %}

{% tab title="Every 4 hours for 1 week" %}
420 ADA total → 42 purchases of 10 ADA each

```javascript
const payload = {
  user_address: 'addr1qx2kd28nq8ac5pr...',
  token_in: '',
  token_out:
    '0691b2fecca1ac4f53cb6dfb00b7013e561d1f34403b957cbb5af1fa4e49474854',
  amount_in: 420,
  interval: 'hourly',
  interval_length: 4,
  slippage: 5,
  cycles: 42,
};
```

{% endtab %}

{% tab title="Weekly for 1 year" %}
520 ADA total → 52 weekly purchases of 10 ADA each

```javascript
const payload = {
  user_address: 'addr1qx2kd28nq8ac5pr...',
  token_in: '',
  token_out:
    '0691b2fecca1ac4f53cb6dfb00b7013e561d1f34403b957cbb5af1fa4e49474854',
  amount_in: 520,
  interval: 'weekly',
  interval_length: 1,
  slippage: 5,
  cycles: 52,
};
```

{% endtab %}
{% endtabs %}
