# cTrader Open API with Python

Independent and unofficial. Not affiliated with or endorsed by any broker or platform named here. Educational only: nothing here is advice, and nothing here recommends a broker or a trade.

This is the markdown version of https://openbrokerapi.com/guides/ctrader-open-api-python, written from the same records as that page.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

cTrader's API is not REST. It is Protobuf messages over a persistent socket, which is why a Python script that works against IG or OANDA will not translate. This is what changes.

- Last reviewed: 2026-09-20

Unverified in part: carried over from an earlier version of this site. The links below are the sources it was written from, but its statements have not been re-read at source since the date shown, so check anything you rely on.

## What you need to know before you write a line

ctrader-open-api, published by Spotware as spotware/OpenApiPy. Official, asynchronous and built on Twisted, which shapes how your whole script is written: you register callbacks on a reactor rather than awaiting calls.

Source: [GitHub: spotware/OpenApiPy](https://github.com/spotware/OpenApiPy) checked 18 Sep 2026

192 stars and unpushed since August 2024. It is the official client and there is no serious alternative, but treat it as stable rather than actively developed.

Source: [Public GitHub search API](https://api.github.com/search/repositories?q=OpenApiPy) checked 19 Sep 2026

A TCP socket, not an HTTP base URL: live.ctraderapi.com or demo.ctraderapi.com on port 5035 for Protobuf and 5036 for JSON. Demo and live are fully separated environments.

Source: [cTrader Open API documentation](https://help.ctrader.com/open-api/) checked 18 Sep 2026

OAuth 2.0 authorisation code flow. The access token lasts about 30 days and the refresh token does not expire. Scopes are accounts or trading, so ask for accounts if you only intend to read.

Source: [cTrader Open API documentation](https://help.ctrader.com/open-api/) checked 18 Sep 2026

Register at openapi.ctrader.com. Spotware reviews new applications, so describe the use case properly rather than leaving the form thin. This is the step that costs days, not the code.

Source: [cTrader Open API documentation](https://help.ctrader.com/open-api/) checked 18 Sep 2026

50 requests a second per connection, and 5 a second for historical data. Exceeding them returns REQUEST_FREQUENCY_EXCEEDED, code 108.

Source: [cTrader Open API FAQ](https://ctrader.com/faq/open-api) checked 19 Sep 2026

The newest protobuf message release is Release 91, 15 Jul 2024. If a tutorial is a year old the message set has probably not changed under it.

Source: [spotware/openapi-proto-messages releases](https://github.com/spotware/openapi-proto-messages/releases) checked 19 Sep 2026

## What catches Python developers first

- There is no request and response pairing to await. Every reply arrives as a message on the same socket, keyed by payloadType, so you match replies to requests yourself.
- Twisted's reactor runs the show. Mixing it with asyncio or calling it from a Jupyter cell is where most first attempts stall.
- A heartbeat every 10 seconds keeps the connection alive. Drop it and the server drops you.
- Authenticating the application and authenticating the trading account are two separate messages. CH_CLIENT_NOT_AUTHENTICATED, code 102, means you sent a command before finishing both.

## Where to go next

- [cTrader Open API: app to first call in Python](https://openbrokerapi.com/platforms/ctrader/quickstart)The step by step from registering an app to a working request
- Every Open API message with its payloadTypeNumber, direction and purpose for the whole message set
- [cTrader Open API error codes](https://openbrokerapi.com/errors/ctrader)What each numeric error code means and what to do
- [The cTrader Open API platform page](https://openbrokerapi.com/platforms/ctrader)Limits, auth, demo access and the brokers that run cTrader

## More on the cTrader API

- [cTrader API quickstart](https://openbrokerapi.com/platforms/ctrader/quickstart): From credentials to a first call on a demo account, step by step.
- [cTrader API error codes](https://openbrokerapi.com/errors/ctrader): 53 decoded, each with what it means, and the fix where the source gives one.
- [cTrader messages](https://openbrokerapi.com/platforms/ctrader/messages): 49 documented, each with its fields and source.
- [cTrader API page](https://openbrokerapi.com/platforms/ctrader): The full record: access, authentication, limits and the source for each.

## Licence and how to cite

The records behind this page are all rights reserved. This file is the page itself, at its own address, in another format. It is not part of the CC BY 4.0 downloads listed at https://openbrokerapi.com/data. Quote from it with a link to the page.

Cite as: cTrader Open API with Python. Broker API Hub, https://openbrokerapi.com/guides/ctrader-open-api-python, newest check 2026-09-20.

Where you rely on a single figure, cite the source and the checked date printed beside it as well. Where this page and a broker's own documentation differ, the documentation wins.
