Place a protected order¶
This guide walks through reading the current price, placing a market order with stop loss and take profit attached, confirming the position is live and adjusting the protection as the trade develops.
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 price you are about to trade against¶
Before you send an order, confirm what the market is offering right now. price returns the live bid and ask for one symbol.
ctrader-cli price --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q --symbol=EURUSD
Use the printed ask for a buy or the bid for a sell to choose your entry, stop and target.
2. Place the market order with protection¶
order place-market fills at the next available price. Attach --sl and --tp in the same call so the position is protected as soon as it opens.
ctrader-cli order place-market --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
--symbol=EURUSD --side=buy --volume=1000 --sl=1.1050 --tp=1.1400
The CLI prints the new position identifier. Capture it for the next step.
3. Verify the position is open and protected¶
positions lists every open position. Confirm the new position appears with the stop loss and take profit you set.
ctrader-cli positions --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q
If the order has not filled yet, orders lists active pending orders instead.
ctrader-cli orders --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q
4. Adjust the protection as the trade develops¶
Once the position is live, position modify updates the stop loss or take profit without changing the volume. Pass only the option you want to change.
ctrader-cli position modify --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
--position=11223344 --sl=1.1100 --tp=1.1450
5. Close the position when you are done¶
position close exits the full position at the next available price.
ctrader-cli position close --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
--position=11223344
To exit only part of the volume, use position close-partial with --volume.
ctrader-cli position close-partial --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
--position=11223344 --volume=500
6. Combine into a single order workflow¶
Once each step works, save the full sequence as manage-trade.sh and run it whenever you enter a new position. Replace <position-id> with the identifier the CLI prints in step 2.
#!/usr/bin/env bash
set -euo pipefail
CTID=1234567
ACC=7654321
PWD_FILE=$HOME/.ctrader/pwd
SYMBOL=EURUSD
SIDE=buy
VOLUME=1000
SL=1.1050
TP=1.1400
POS_ID=<position-id>
ctrader-cli price --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q --symbol=$SYMBOL
ctrader-cli order place-market --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
--symbol=$SYMBOL --side=$SIDE --volume=$VOLUME --sl=$SL --tp=$TP
ctrader-cli positions --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q
ctrader-cli position modify --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
--position=$POS_ID --sl=1.1100 --tp=1.1450
ctrader-cli position close --ctid=$CTID --pwd-file=$PWD_FILE --account=$ACC -q \
--position=$POS_ID
Edit the variables at the top for each trade. The script reads the price, opens a protected position, confirms it, tightens the protection and closes the position on signal.
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.