dYdX Chain / Link your orders

One triggers other bot.

Build an order sequence from groups. When an order fills, its siblings are cancelled and the next group takes over. Define a loop or a finite sequence.

UNDERSTAND THE BOT

The strategy
in detail.

How linked order groups work

One triggers other lets you express a trading sequence as connected order groups. Use it when the next action depends on which order fills, such as moving between two sides of a channel or ending after a specific execution.

Every order has an integer group id and a successor next, along with its side, price and base-asset size. Orders in group 0 start together. When one fills, the bot cancels its siblings and confirms their status before advancing to the successor group. A successor of -1 ends the sequence. Linking successors back to earlier groups creates a loop.

A sequence example

Group 0 can contain a buy below the current price and a sell above it. The buy can lead to a group containing the next sell, while the initial sell leads to a different group containing the next buy. Those groups can link back to each other or finish with -1. Choose quantities against the position already held: selling twice a previous buy quantity can close that long and open a short.

What to monitor

Review every route through the groups before starting, including repeated loops. A loop has no inherent budget or fixed end. Orders are not automatically sized to flatten a position.

Transitions are persisted before cancellation so they can recover after a restart. If a sibling also executes or a cancelled order partially fills, the bot stops for reconciliation. This prevents it from advancing under the assumption that only the first observed order changed the position. OTO supersedes the older akili-channel implementation.

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.

  1. Clone the repository and create your environment file:
git clone https://github.com/akilibots/akili-oto.git
cd akili-oto
cp .env.example .env
  1. Edit .env. Set DYDX_MNEMONIC to your Chain wallet's mnemonic, in quotes. Leave the Telegram values empty if you do not want notifications.

  2. Edit data/strategy.json. Set exchange.address to that wallet's address, check its subaccount and review the strategy quantities and prices. The sample endpoints select testnet.

  3. 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

Each item in orders has an integer id, a successor next, a positive price and size, and a side of buy or sell. All orders in group 0 are placed initially. Once one fills, the bot cancels its siblings, confirms their status, and advances to next. A successor of -1 stops the bot. Groups can form loops.

The sample starts with two ATOM-USD orders and then alternates between groups 1 and 2. Later orders have twice the first size, which can close the previous position and open an opposite one. Quantities are base-asset units.

Transitions are persisted before cancellation and recover after restart. Unfilled cancelled orders are recreated with a new client ID. If a sibling also executes, or a cancelled order partially fills, the bot stops for position reconciliation instead of advancing under an incorrect assumption.

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 run.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 One triggers other in your workspace

Manage your One triggers other strategy through the Akilibots app. Keep the bot configuration, exchange connection and execution history together.

Set up your account and exchange

  1. Create your account and sign in to your workspace.
  2. Open exchange connections and add your dYdX Chain account and select the correct network and subaccount.
  3. Check that the connection uses the intended account and has the funds needed for the strategy. Use testnet to check the configuration first.
  4. Create a bot and select One triggers other.

Configure the strategy

  1. Choose the market and subaccount.
  2. Assign each order a group id, price, size and side.
  3. Set next to the successor group, or -1 to finish.
  4. Review all routes through the groups, including loops and position reversals.

Review and run

  1. Review the market, network, order quantities and maximum exposure. Save the configuration.
  2. Start the bot, then check the first action against the exchange account.
  3. Use the bot detail view to monitor orders, executions, logs and errors. A queued request or submitted order is not a confirmed fill.
  4. Pause the bot before changing its strategy. Check the exchange for open orders and positions; stopping a bot does not itself close a position.
  5. 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