Skip to main content
A DCA (dollar-cost averaging) strategy spends totalAmount of one token in iterations equal orders, one every frequency seconds, buying another token. Olympex creates each order as the strategy runs and executes it from the maker’s wallet. This guide spends 100 USDC on WETH on Polygon in 10 daily orders of 10 USDC, follows the orders, then cancels the strategy and lowers the allowance.
You need API credentials and the signing helper from Sign requests, and a wallet on Polygon that holds USDC and POL for gas. Order signatures and allowances explains what the wallet’s signature and allowance let Olympex do: read it before you run this with real funds.

Prerequisites

  • OLYMPEX_API_KEY_ID, OLYMPEX_SECRET_KEY and OLYMPEX_PASSPHRASE in your server’s environment, and sign-request.ts saved next to your code.
  • Node.js 22.18 or later, which runs .ts files directly, in an ES module project (npm pkg set type=module), and ethers v6 (npm install ethers).
  • An RPC URL for Polygon, as POLYGON_RPC_URL.
  • A wallet that is an externally owned account (EOA), with its private key in WALLET_PRIVATE_KEY. It holds the USDC to spend and POL for its approval transactions. Smart-contract wallets (Safe, ERC-4337) can’t sign orders: only 65-byte ECDSA signatures are accepted.

Steps

A new strategy starts active as soon as you create it, and each of its orders moves funds on mainnet. Use a small amount from a dedicated wallet. To test the calls without scheduling orders, create the strategy with "status": "cancelled" (step 5).
1

Set up and check the chain

The snippets in these steps form one script, run-dca-strategy.ts. Run it with node run-dca-strategy.ts.GET /chains returns the IDs of the chains Olympex has enabled, as integers. Check your chain there instead of hard-coding the list. Limit orders and DCA execute only on the chains in ORDER_CONTRACTS, where the Olympex order contract is deployed.
On Polygon the order contract is 0x50186B03dc7315271FB58da0d3b9f2c65A51dA76. It’s not the contractToApprove that POST /swap returns, which is for swaps.
2

Resolve the tokens with GET /tokens

GET /tokens returns every token Olympex lists on a chain, with its address, symbol, name and decimals. Match tokens by address, never by symbol, and compare addresses case-insensitively: their casing varies.
The list holds hundreds of tokens and changes rarely, so cache it on your side, for example for 24 hours. A listed symbol can differ from the token contract’s symbol(), for example with a suffix such as STRK_1 that tells tokens with the same symbol apart, so findToken trims it and drops a trailing _<number>.The token you spend must be an ERC-20. To spend a chain’s native token, wrap it first: WETH (0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2) on Ethereum, WBNB (0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c) on BNB Chain or WPOL (0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270) on Polygon. ERC-20 tokens whose transfer and approve don’t return a boolean can’t be spent either: USDT isn’t supported as the token you sell in limit orders or DCA on Ethereum. Neither are fee-on-transfer tokens.
3

Approve the order contract for totalAmount

Each order pulls its amount from the maker through the Olympex order contract. Olympex takes the execution gas out of the token bought, so the allowance covers totalAmount of the token you spend, with nothing on top.Read the wallet’s current allowance for the order contract, then approve that value plus totalAmount. The allowance is shared: every open limit order and active DCA strategy that sells the same token on the same chain draws on it. approve replaces the allowance instead of adding to it, so approving only this strategy’s amount would take it away from the others.
Nothing moves when you approve or create the strategy. The allowance is the on-chain limit on what Olympex can move from the wallet: approve only what your open orders and strategies need, and never an unlimited amount.
4

Sign the token pair

The maker signs the pair once: keccak256(abi.encodePacked(maker, maker, tokenIn, tokenOut)), signed with personal_sign over its 32 raw bytes. Save this helper as sign-order-pair.ts, the same file Place a limit order uses:
sign-order-pair.ts
Then sign USDC for WETH:
Olympex doesn’t check the signature when you create the strategy: a wrong one makes execution fail later, which the self-check in signOrderPair prevents.The signature lets the Olympex order contract swap USDC for WETH from this wallet. It doesn’t bind an amount, price, expiry, chain or order: Olympex enforces those when it executes. It stays valid after you cancel, and it’s the same signature a limit order that sells USDC for WETH uses.
5

Create the strategy with POST /dca-order/strategies

POST /dca-order/strategies stores the strategy. It starts active immediately.Olympex checks the types, the required fields and that each address is a valid EVM address. It doesn’t check the other rules in this table or the pair signature: a strategy that breaks one is created, and its orders can’t execute. Check them before you send the request. Other fields in the schema are set by Olympex; don’t send them.
Response
Each successful call creates a new strategy, and Olympex ignores any id you send. If the call times out or fails with a 5xx, don’t send it again: the strategy may exist. GET /dca-order/strategies lists your strategies newest first, so look there first:
The strategy list filters on accountTo and status only. It ignores any other query parameter, such as chainId, so a misspelt filter returns every strategy. Send each parameter once: a parameter sent twice returns an empty array.
6

Follow the orders

Olympex places the orders one frequency apart. A new strategy has no orders until its first order is scheduled. Olympex doesn’t notify you when an order changes, so check on your own schedule:Treat any other value as not final.
A response from the orders endpoint, after the first order ran:
Response
Route these GET requests through your retry wrapper: GET is safe to repeat.
To change the price bounds of a running strategy, send only minPrice or maxPrice to PATCH /dca-order/strategies/{id}. To change anything else, cancel the strategy and create a new one.
7

Cancel the strategy

Send {"status":"cancelled"} to PATCH /dca-order/strategies/{id}. Cancelling stops new orders and can’t be undone. Orders that Olympex already created are read-only: the next step lowers the allowance so they can’t spend what you release.
Sending the same PATCH again is safe.
8

Lower the allowance

Cancelling doesn’t touch your allowance, and the pair signature stays valid. Lower the allowance by the part of totalAmount the strategy won’t spend, and keep what your other open orders need:
If an order that was executing ends in error, lower the allowance by its amount too. When a strategy finishes, its orders have used their share of the allowance. To stop everything that spends USDC on Polygon at once, set the allowance to 0: that also stops every limit order that sells USDC there.

Verify

Run these at the end of the script:
  • The strategy is cancelled.
  • It appears in the strategy list filtered by the checksummed maker and status=cancelled. With the maker in lowercase, the list is empty: accountTo matches case-sensitively.
  • Once no order is executing, the allowance is back to its value before step 3: executed orders used their part, and you released the rest.

Common pitfalls

Strings in numeric fields. totalAmount, slippage, minPrice, maxPrice, frequency, iterations, chainIdFrom and chainIdTo are JSON numbers, unlike limit-order fields. A string returns 400 VALIDATION_ERROR.
Two different chains. chainIdFrom must equal chainIdTo: a strategy runs on one chain.
Overwriting a shared allowance. DCA strategies and limit orders that sell the same token on the same chain share one allowance. Approve the sum they need: approving one strategy’s totalAmount on its own takes the allowance away from the others.
Retrying a create. Each successful POST /dca-order/strategies creates a new strategy that starts active. After a timeout, list your strategies before you send it again, or two strategies spend from the same allowance.
Stopping at the strategy. Cancelling a strategy stops new orders, not the orders Olympex already created, which are read-only. Lower the allowance too.
An unlimited approval. The pair signature stays valid after you cancel, so the allowance is the only on-chain limit on what Olympex can move from the wallet. Keep it to what your open orders and strategies need.

What’s next

DCA

Strategies, orders, price bounds and statuses.

Order signatures and allowances

What the signature and the allowance let Olympex do.

Place a limit order

Sell a token when the market reaches your price.

Create a DCA strategy

Every field of POST /dca-order/strategies.