Getting Started
cTrader Markets is a Python 3.12 FastAPI service. Credentials come from an Open API application at openapi.ctrader.com , plus a one-time browser OAuth2 flow.
Create a virtualenv and install
cd ctrader-markets
python3.12 -m venv .venv
.venv/bin/python -m pip install -e '.[dev]'
cp .env.example.forex .env.forexFill credentials (in this order)
1. CTRADER_CLIENT_ID / CTRADER_CLIENT_SECRET
Register an application at openapi.ctrader.com . The client id and secret are shown on the application page.
2. CTRADER_ACCESS_TOKEN / CTRADER_REFRESH_TOKEN
A one-time browser OAuth2 flow, done by hand. Open this URL (substituting your client id and the redirect URI registered with the application):
https://openapi.ctrader.com/apps/auth
?client_id=YOUR_CLIENT_ID
&redirect_uri=YOUR_REDIRECT_URI
&scope=tradingLog in, approve, and copy the code query parameter from the redirect. Exchange
it for tokens:
curl -s 'https://openapi.ctrader.com/apps/token' \
-d grant_type=authorization_code \
-d code=THE_CODE \
-d redirect_uri=YOUR_REDIRECT_URI \
-d client_id=YOUR_CLIENT_ID \
-d client_secret=YOUR_CLIENT_SECRETPut accessToken and refreshToken into the env file. The service refreshes them
from then on and persists the rotated pair to TOKEN_CACHE_PATH — see
Token Lifecycle.
3. CTRADER_ACCOUNT_ID
This is the numeric ctidTraderAccountId, not your account login number. It
needs only the access token, so discover it once the tokens are in place:
ctrader-markets --profile forex --discover-accounts4. SYMBOLS
Exact, case-sensitive cTrader symbolName values. Startup fails closed if any
cannot be resolved, so list the real ones:
ctrader-markets --profile forex --discover-symbolsFor a Deriv profile, do not copy the symbol names from
mt5-trader/.env.example.deriv. Those are Deriv’s MT5 synthetic indices and will
not resolve on a cTrader broker.
Start against CTRADER_ENVIRONMENT=demo with a demo account. Demo and live are
fully separated connections and cannot be mixed.
Run
ctrader-markets --profile forex # reads .env.forex → :8010
ctrader-markets --profile deriv # reads .env.deriv → :8011
ctrader-markets # reads .envRunning without --profile reads .env. A missing env file is a startup error
naming the example to copy.
Next steps
- Profiles — one process per account and port mapping.
- API Reference — endpoints and SSE shape.
- Deployment — launchd via
ops/install.sh.