dYdX Chain / Keep a schedule
DCA bot.
Buy or sell a fixed base-asset quantity at an interval you choose. Durable scheduling preserves the next due time when the bot restarts.
How scheduled execution works
DCA repeats a fixed base-asset quantity at an interval you choose. Use it when your strategy calls for execution on a schedule, rather than at a sequence of limit-price levels. On dYdX, these are perpetual trades: buying BTC-USD changes a derivatives position, rather than depositing spot BTC into a wallet.
The first order is due immediately. Each attempt uses a short-term immediate-or-cancel order with a side-aware slippage protection price. The bot records the actual executed quantity and fees once the result is terminal. If an order only partially executes, it records that fill and does not place a replacement for the remainder.
A configuration example
A size of 0.001, frequency of 1,800 and slippage of 0.01 means an attempt to trade 0.001 units of the market's base asset every 30 minutes, with a 1% protection bound. It does not mean spending a fixed dollar amount. The quote value changes with the execution price.
The next interval begins after the previous result is observed. The saved schedule and pending client ID survive a restart. Missed intervals do not produce a burst of catch-up orders.
What to monitor
Check cumulative exposure, collateral, order results and the next due time. An IOC order can fill partially or not at all. The schedule does not guarantee a target quantity by a particular date. DCA does not implement an automatic exit or take-profit target; manage the resulting position separately.
Get it running
You need Git, Docker with Compose, and a funded dYdX Chain testnet wallet to use the supplied example. The bot needs the wallet's mnemonic and a matching Chain address. Old v3 API keys, STARK keys and v3 state do not work here.
- Clone the repository and create your environment file:
git clone https://github.com/akilibots/akili-dca.git
cd akili-dca
cp .env.example .env
Edit
.env. SetDYDX_MNEMONICto your Chain wallet's mnemonic, in quotes. Leave the Telegram values empty if you do not want notifications.Edit
data/strategy.json. Setexchange.addressto that wallet's address, check its subaccount and review the strategy quantities and prices. The sample endpoints select testnet.Build and start the bot:
docker compose up --build -d
docker compose logs -f
To stop it:
docker compose down
Stopping the process leaves its exchange orders in place. Check and cancel those orders separately when needed. Do not run two instances from the same data folder.
How it works
dca.side is buy or sell, dca.size is a base-asset quantity, and dca.freq
is the interval in seconds. The sample interval is 1,800 seconds. dca.slippage
is the maximum fractional move from the relevant best bid or ask for a market
order, for example 0.01 for 1%. Buy and sell protection prices are side-aware.
The first order is due immediately. Each attempt is a short-term IOC order, and its actual executed quantity and fees are recorded when terminal. A partial IOC fill is recorded as a partial execution; the remainder is not resubmitted. The next interval begins after the result is observed. Restarting preserves the schedule and pending client ID. Missed intervals do not create a catch-up burst. There is no automatic position exit or profit target.
Configuration notes
| Setting | What to check |
|---|---|
main.market |
The perpetual market, such as BTC-USD |
exchange.address |
The Chain address matching DYDX_MNEMONIC |
exchange.subaccount |
A cross-margin subaccount from 0 to 127, with collateral |
exchange.network |
testnet or mainnet |
exchange.indexer, websocket, node |
Endpoints for the same selected network |
exchange.poll_seconds |
Seconds between status checks for the strategy loops |
The node value is a TLS gRPC host and port, without http:// or https://.
Review market sizes and prices before running any sample. Quantities are in the
base asset, not a dollar budget. To use mainnet, change the network and all its
endpoints together and configure the corresponding wallet and collateral.
You can supply JSON5 through the strategy environment variable instead of the
strategy file. Settings are tied to saved strategy state; reconcile existing
orders before changing an active strategy. Telegram notifications use
TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID in .env.
Restarting and recovery
Compose mounts ./data, so state survives a container replacement.
data/state.json records progress and data/exchange.json records client IDs
before order submission. Keep them together and keep them out of Git.
An uncertain submission is checked using its existing client ID. The bot does not turn a timeout into a second trade. If it cannot reconcile an order, it stops so you can inspect the exchange and saved state. Do not delete state to bypass an error. Partial-fill and cancellation handling is described above.
For a v3 migration, reconcile old orders and positions first, archive the old
state, then start with a fresh data folder. Use a separate data folder and
subaccount for each strategy. Never commit wallet mnemonics or .env.
Limit orders use Chain long-term orders with a default 24-hour expiry. Prices
follow market ticks and sizes must be exact multiples of stepSize. Market
orders use short-term IOC orders with a slippage bound. Profit figures, where
reported, include actual fill prices and trading fees, but exclude funding,
network transaction fees and unrealised positions.
Test it yourself
docker build --target test -t bot-test .
docker run --rm --network none bot-test
The suite uses simulated exchange responses with networking disabled. It covers order handling and recovery; SDK checks also build and sign transactions locally. Passing tests is not a promise of live execution or profitable trading.
Running directly with Python
Use Python 3.15.2 and install the native C/C++ and Rust build tools required by the wallet dependencies. Docker includes these prerequisites in its build stage.
python3 -m venv .venv
. .venv/bin/activate
PIP_BUILD_CONSTRAINT="$PWD/build-constraints.txt" python3 -m pip install -r requirements-dev.txt
python3 -m pip check
Export the values from .env into your shell, then run python3 app.py.
The direct Python entrypoint does not automatically read .env.
The dYdX SDK constrains some signing packages to older compatible versions;
build-constraints.txt supplies the build tools those packages require.
Use DCA in your workspace
Manage your DCA strategy through the Akilibots app. Keep the bot configuration, exchange connection and execution history together.
Set up your account and exchange
- Create your account and sign in to your workspace.
- Open exchange connections and add your dYdX Chain account and select the correct network and subaccount.
- Check that the connection uses the intended account and has the funds needed for the strategy. Use testnet to check the configuration first.
- Create a bot and select DCA.
Configure the strategy
- Choose the perpetual market and buy or sell direction.
- Enter the base-asset quantity for each order.
- Set the interval in seconds and the permitted slippage fraction.
- Review the resulting position exposure before starting the schedule.
Review and run
- Review the market, network, order quantities and maximum exposure. Save the configuration.
- Start the bot, then check the first action against the exchange account.
- Use the bot detail view to monitor orders, executions, logs and errors. A queued request or submitted order is not a confirmed fill.
- Pause the bot before changing its strategy. Check the exchange for open orders and positions; stopping a bot does not itself close a position.
- If execution stops with a reconciliation error, compare the saved bot state with exchange orders and fills before resuming.
Commercial access
For account access and deployment enquiries, contact Akilibots. Never include wallet mnemonics, private keys or API secrets in an email.
Commercial service guide