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

# DCA strategies

> How DCA works: a strategy and the orders Olympex creates from it, units, the amount of each order, price bounds, the lifecycle, cancelling, and how the execution gas is paid.

Dollar-cost averaging (DCA) spreads a purchase over time. A DCA strategy spends a total amount of one token in equal orders, one every `frequency` seconds, buying another token on the same chain. You create the strategy once with [`POST /dca-order/strategies`](/api-reference/dca/create-dca-strategy). Olympex creates the strategy's orders as it runs and executes each one from the maker's wallet, under the maker's pair signature and token allowance.

## Strategies and orders

A strategy is the plan; its orders are the executions.

| | Strategy | Order |
| - | - | - |
| Created by | You, with `POST /dca-order/strategies` | Olympex, as the strategy runs. There is no endpoint to create one. |
| Describes | The tokens, the total amount, the number of orders, the frequency and the price bounds | One execution: its amount, status, transaction and result |
| Statuses | `active`, `cancelled`, `finished` | `pending`, `executing`, `successful`, `cancelled`, `error`, `expired` |
| Read with | [`GET /dca-order/strategies`](/api-reference/dca/list-dca-strategies), [`GET /dca-order/strategies/{id}`](/api-reference/dca/get-dca-strategy) | [`GET /dca-order/strategies/{id}/orders`](/api-reference/dca/list-dca-strategy-orders), [`GET /dca-order/orders/{id}`](/api-reference/dca/get-dca-order) |
| Change with | [`PATCH /dca-order/strategies/{id}`](/api-reference/dca/update-dca-strategy): cancel it, or change its price bounds | Nothing: orders are read-only. Olympex creates and updates them. |

## Units

| Field | Type and unit | Example |
| - | - | - |
| `totalAmount` | JSON number. Human-readable amount of `tokenAddressFrom` to spend across all orders. Not base units. | `100` is 100 USDC. |
| `iterations` | Integer. The number of orders. | `10` |
| `frequency` | Integer. Seconds between orders. | `86400` is one day. |
| `slippage` | JSON number. Maximum slippage per order, in percent. Always send it: responses show `0` when it's missing. | `1` is 1%. |
| `minPrice`, `maxPrice` | Optional JSON numbers. Units of `tokenAddressTo` per 1 `tokenAddressFrom`. | See [Price bounds](#price-bounds). |
| `chainIdFrom`, `chainIdTo` | Numbers, and they must be equal: DCA runs on one chain. | `137` |
| `pair` | `"<tokenSymbolFrom>/<tokenSymbolTo>"`, with the tokens' real symbols. Take a symbol from [`GET /tokens`](/api-reference/tokens/list-tokens) trimmed and without a trailing `_<number>`: `STRK_1` becomes `STRK`. It isn't returned in responses. | `"USDC/WETH"` |

`accountTo` is the maker: the EOA that sells `tokenAddressFrom`, receives `tokenAddressTo` and signs the pair. Send it in EIP-55 checksummed form. `accountTo`, `tokenAddressFrom` and `tokenAddressTo` must be valid EVM addresses: `0x` and 40 hexadecimal digits, in lowercase or EIP-55 checksummed form. A mixed-case address with a wrong checksum returns `400 VALIDATION_ERROR` with `"Must be a valid EVM address"`.

`status` is optional. Omit it and the strategy starts `active`. Send `"cancelled"` to create a stopped strategy, for example to test your integration without scheduling orders. Other fields in the schema are set by Olympex; don't send them.

<Note>
  Unlike the rest of the API, DCA strategies take amounts, prices and slippage as JSON numbers, not strings. A string such as `"100"` fails validation with `400`.
</Note>

## The amount of each order

Each order spends `totalAmount / iterations` of `tokenAddressFrom`. A strategy with a `totalAmount` of `100` USDC, `10` iterations and a `frequency` of `86400` places 10 orders of 10 USDC each. Olympex places the orders one `frequency` apart.

A new strategy starts as `active` immediately, unless you create it with `"status": "cancelled"`, and has no orders until its first order is scheduled. A strategy whose orders have all run has the status `finished`.

## Price bounds

`minPrice` and `maxPrice` are optional, in units of `tokenAddressTo` per 1 `tokenAddressFrom`. Olympex executes an order only while the price is within the bounds you set. You can set both, one or neither.

For a strategy that buys WETH with USDC, the bounds are in WETH per 1 USDC: a WETH price of 4,200 USDC is `1/4200`, about `0.000238`.

You can change the bounds of a running strategy with `PATCH /dca-order/strategies/{id}`. You can't remove them: to run without bounds, cancel the strategy and create a new one.

<Warning>
  The bounds and an order's `executionPrice` use opposite orientations. The bounds are in the token bought per 1 token sold; `executionPrice` is in the token sold per 1 token bought. An order that spent 10 USDC and received 0.00238 WETH reports an `executionPrice` of `4201.68`, in USDC per WETH.
</Warning>

## Lifecycle

**Strategy statuses:**

| Status | Meaning |
| - | - |
| `active` | Running. New strategies start here. |
| `cancelled` | Stopped by you, or created stopped. Cancelling can't be undone. |
| `finished` | Every order ran. |
| `pending` | Reserved for Olympex. |

**Order statuses:**

| Status | Meaning |
| - | - |
| `pending` | Scheduled. |
| `executing` | In progress. It can't be stopped. |
| `successful` | Executed. `transactionHash` is the execution transaction, `amountReceived` is the amount of the token bought, and `executionPrice` is the price it executed at. |
| `cancelled` | Skipped. |
| `error` | Failed. `errorMessage` says why. |
| `expired` | Not executed in time. |

Treat any status not in these tables as not final.

### Follow a strategy

* [`GET /dca-order/strategies`](/api-reference/dca/list-dca-strategies) lists your strategies newest first, each with its `orders` array. Filter it with `?accountTo=` and `?status=`. Other query parameters, such as `chainId`, are ignored, so a misspelt filter returns every strategy. Send each parameter once: a repeated parameter returns an empty list.
* [`GET /dca-order/strategies/{id}`](/api-reference/dca/get-dca-strategy) returns one strategy, without its orders.
* [`GET /dca-order/strategies/{id}/orders`](/api-reference/dca/list-dca-strategy-orders) lists one strategy's orders, oldest first.
* [`GET /dca-order/orders/{id}`](/api-reference/dca/get-dca-order) returns one order.

The lists are unpaginated. They return only strategies created with your API key, and an ID from another API key returns `404 NOT_FOUND`. `accountTo` is stored as you sent it, and `?accountTo=` matches case-sensitively, so send the EIP-55 checksummed form everywhere.

## Cancel a strategy

To stop a strategy and everything it has scheduled:

<Steps>
  <Step title="Cancel the strategy">
    Send `PATCH /dca-order/strategies/{id}` with `{"status":"cancelled"}`. It stops new orders, and it can't be undone.
  </Step>

  <Step title="Lower the allowance">
    Cancelling doesn't reduce the maker's token allowance, and the orders Olympex already created are read-only: you can't cancel them through the API. Set the allowance to what the maker's other orders still need, or to `0`: see [Stop everything](/concepts/order-authorization#stop-everything-set-the-allowance-to-0).
  </Step>
</Steps>

`PATCH` changes only a strategy's status and price bounds. To change anything else, such as the amount, the frequency or the tokens, cancel the strategy and create a new one.

## Creating a strategy is not safe to repeat

Each successful `POST /dca-order/strategies` creates a new strategy, and Olympex ignores any `id` you send. If a create call times out, the strategy may still exist. Don't retry it blindly: list your strategies for the maker and look for one that matches your tokens, amounts and creation time before you send the call again. [Handle errors and retries](/guides/handle-errors-and-retries) covers the pattern.

## Funds and fees

* **Nothing moves at creation.** The tokens stay in the maker's wallet, and nothing is reserved. The wallet must hold each order's amount, and the allowance must cover it, when the order runs.
* **Each order** pulls its amount of `tokenAddressFrom` from `accountTo` through the Olympex order contract and swaps it for `tokenAddressTo`, which goes to `accountTo`.
* **Gas is reimbursed out of the token bought.** Olympex pays the gas of each execution and takes it out of the token bought, so the maker needs no native token for the executions.
* **So the allowance must cover `totalAmount`** of `tokenAddressFrom`, with no extra amount for gas. If the maker has other open orders or strategies that sell the same token on the same chain, approve the sum: see [One allowance per token and chain](/concepts/order-authorization#one-allowance-per-token-and-chain).

[Gas and fees](/concepts/gas-and-fees#limit-orders-and-dca) compares the costs of swaps, limit orders and DCA.

## What can't be sold

| Token or wallet | Why | What to do |
| - | - | - |
| Native tokens (`0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`, in any casing) | `tokenAddressFrom` must be an ERC-20. | Wrap first, and sell the wrapped token: WETH, WBNB or WPOL. [Token addresses](/concepts/supported-chains#token-addresses) lists their addresses. |
| ERC-20 tokens whose `transfer` and `approve` don't return a boolean | The order contract can't move them. USDT on Ethereum isn't supported as the token you sell in limit orders or DCA on Ethereum. | Offer a different token on that chain. |
| Fee-on-transfer tokens | The amount that arrives differs from the amount sent. | Don't offer them as the token you sell. |
| Smart-contract wallets as the maker | Only 65-byte ECDSA signatures are accepted. | Use an EOA as `accountTo`. |
| A token on another chain | DCA runs on one chain: `chainIdTo` must equal `chainIdFrom`. | Choose both tokens on the same chain. |

Strategies run only on chains that have an [order contract](/concepts/order-authorization#the-order-contract) and that [`GET /chains`](/api-reference/chains/list-chains) returns.

When you create a strategy, Olympex checks the types, the required fields and that each address is a valid EVM address. It doesn't check the rules on this page or the pair signature: a strategy that breaks one is created, and its orders can't execute. Check them before you send the request.

## What this means for your integration

* Send `totalAmount`, `slippage` and the price bounds as JSON numbers, and expect each order to spend `totalAmount / iterations`.
* Sign the pair once, and keep the allowance at what the maker's strategies and orders still need to spend.
* To stop a strategy, cancel it, then lower the allowance.
* Never retry a create call blindly: list your strategies and match first.

## Related

<CardGroup cols={2}>
  <Card title="Order signatures and allowances" icon="signature" href="/concepts/order-authorization">
    The pair signature, the allowance and the order contract.
  </Card>

  <Card title="Run a DCA strategy" icon="bolt" href="/guides/build-a-dca-strategy">
    The step-by-step guide.
  </Card>

  <Card title="Create a DCA strategy reference" icon="code" href="/api-reference/dca/create-dca-strategy">
    Every field of `POST /dca-order/strategies`.
  </Card>

  <Card title="Limit orders" icon="bullseye" href="/concepts/limit-orders">
    Sell at a target price instead.
  </Card>
</CardGroup>


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