Run a cBot around the clock¶
A cBot that only runs while your laptop is open is no use for a session that opens at 3 a.m. This guide walks through reading the cBot's parameters, starting it on a remote host, confirming it is running and stopping it cleanly when the session ends.
Tip
Define your credentials in shell variables once. Every interactive command below reuses them, so the steps stay short and the script stays portable.
export CTID=1234567
export ACC=7654321
export PWD_FILE=$HOME/.ctrader/pwd
1. Read the cBot's parameters¶
metadata lists the parameter names and types the cBot accepts, so you know exactly which flags to pass to run or which keys to put in a .cbotset file. metadata is a batch command and takes --ctid and --pwd-file directly.
ctrader-cli metadata --ctid=$CTID --pwd-file=$PWD_FILE $ALGO
2. Write a saved parameter set¶
A .cbotset file is a plain text file with one key=value per line. It is easier to edit and reuse than a long command line.
cat > mycbot.cbotset <<'EOF'
SlowPeriods=20
StopLossPips=30
TakeProfitPips=60
EOF
Use the parameter names printed by metadata in step 1.
3. Start the cBot on a VPS¶
run is a homonym command that can run in batch or interactive mode. In batch mode (no -q) it takes --ctid and --pwd-file without -q, and the CLI blocks until the cBot exits. Run it inside a process supervisor on the VPS (systemd, tmux, screen, the official Docker image or --exit-on-stop).
ctrader-cli run --ctid=$CTID --pwd-file=$PWD_FILE \
--account=$ACC $ALGO mycbot.cbotset --symbol=EURUSD --period=h1 --exit-on-stop
--exit-on-stop tells the CLI process to terminate when the cBot stops, which keeps a systemd or Docker supervisor clean.
For a long-running host, run the same command inside the official cTrader CLI Docker image. The image accepts the same flags and exits on the same signals. The full Docker walkthrough is in the cBots article.
4. Verify the cBot is running¶
From a second terminal, cbots lists every cBot instance currently running on the account. The output includes the instance identifier you need for the next step.
ctrader-cli cbots --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q
5. Read live prices while the cBot runs¶
While the cBot is working, price lets you check the market from a separate terminal without disturbing the running instance.
ctrader-cli price --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q --symbol=EURUSD
6. Stop the cBot when the session ends¶
stop terminates the instance by its identifier. Capture the identifier from the cbots output in step 4.
ctrader-cli stop --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
--instance=13579246
If you started the CLI inside the interactive shell, append all and yes to stop every running instance at once: stop all yes.
7. Combine into a managed run script¶
Save the full sequence as start-cbot.sh and call it from systemd, a cron job or a deployment pipeline. The script writes the parameter set, starts the cBot in the background, waits for verification and prints the instance identifier for later use.
#!/usr/bin/env bash
set -euo pipefail
CTID=1234567
ACC=7654321
PWD_FILE=$HOME/.ctrader/pwd
ALGO=/opt/mycbot.algo
SYMBOL=EURUSD
PERIOD=h1
cat > /opt/mycbot.cbotset <<'EOF'
SlowPeriods=20
StopLossPips=30
TakeProfitPips=60
EOF
nohup ctrader-cli run --ctid=$CTID --pwd-file=$PWD_FILE \
--account=$ACC $ALGO /opt/mycbot.cbotset --symbol=$SYMBOL --period=$PERIOD --exit-on-stop \
> /var/log/mycbot.log 2>&1 &
sleep 10
ctrader-cli cbots --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q
To stop the instance later, run the matching stop call from step 6. The instance identifier stays stable across cbots queries, so capture it once and reuse it.
The CLI references lists all available options for the commands used in this workflow.
Warning
cTrader CLI is a tool for trading and automation. It does not provide financial, investment, legal or tax advice. Commands that place or change orders can trigger real trades and result in losses. Verify every command before you run it, test on a demo account first and protect your credentials.