Skip to main content

PyneCore cTrader Plugin

cTrader Open API integration for PyneCore. A single plugin that works across the many brokers running cTrader (Pepperstone, IC Markets, FxPro, Spotware, and more), since they all speak the same Open API.

Status

Both the data provider (LiveProviderPlugin) and live order execution (BrokerPlugin) are implemented: OAuth2 authentication, symbol mapping, historical plus live OHLCV, and position-based order routing with server-side stop-loss / take-profit / trailing stop.

Demo first

Every cTrader broker offers demo accounts — run your strategy on one before risking funds. Set demo = true and the plugin connects to the demo host (demo.ctraderapi.com) and only sees your demo accounts; demo = false connects to live.ctraderapi.com and your live accounts. The OAuth token is stored per environment, so authorize once for each you use.

Configuration

Settings live in workdir/config/plugins/ctrader.toml, auto-generated from CTraderConfig on first run:

demo = true            # demo.ctraderapi.com vs. live.ctraderapi.com
client_id = ""         # your cTrader Open API application's client id
client_secret = ""     # ... and its client secret
account_id = ""        # optional ctidTraderAccountId (see Accounts below)

client_id / client_secret come from your own cTrader Open API application, registered on the Open API portal — there is no shared PyneSys secret and PyneSys never relays the trading socket. When registering the application, add http://localhost:8765 as a redirect URI (or another port, matched with --port below).

Authentication: pyne ctrader auth

The plugin ships a CLI command that runs the OAuth2 loopback consent flow:

pyne ctrader auth              # environment from the config's demo setting
pyne ctrader auth --live       # or force the environment explicitly

It opens the consent page in your browser (use --no-browser to print the URL instead, e.g. on a headless server), receives the redirect on localhost, exchanges the code, and stores the refreshable token pair in the workdir cache — tokens never touch the user-edited TOML file. Run it once per environment; after that the plugin refreshes tokens on its own.

Accounts

One access token can grant several trading accounts. The plugin selects the account to trade on in this order:

  1. an explicit account_id in the config always wins;
  2. otherwise the broker slug from the provider string selects it;
  3. otherwise the sole account of the right kind (demo/live) is used.

An ambiguous choice fails at startup with the candidate ctidTraderAccountId values listed — copy the one you want into account_id.

Symbols

cTrader is a multi-broker platform, so the provider string carries an optional broker segment before the symbol:

ctrader:EURUSD@60                  # sole account decides the broker
ctrader:pepperstoneuk:EURUSD@60    # broker slug selects the account

Discovery commands:

pyne data download ctrader --list-brokers            # your brokers' slugs
pyne data download ctrader:<broker> --list-symbols   # a broker's symbols

Symbols use the broker's native cTrader names; Pine scripts written with TradingView-style symbols keep working through the optional symbol_map translation table in the config.

Architecture

  • Transport: Protobuf v2 over a persistent TCP+TLS connection (demo.ctraderapi.com / live.ctraderapi.com, port 5035). The plugin ships a thin asyncio client built on the generated Protobuf message classes — it does not depend on the Twisted-based official SDK, to fit PyneCore's asyncio event loop.
  • Authentication: OAuth2. A registered cTrader application provides the client id and secret; the end user grants account access in the browser and the plugin stores the refreshable access token.
  • Market data: historical trendbars and live spot/trendbar subscriptions. The live stream hands on what the venue sends; closed bars it missed (at startup, during an outage, or a slot the socket never closed) are recovered by PyneCore through backfill_closed_bars, a plain history query for the closed trendbars after a given bar. cTrader publishes a closed M1 trendbar in its history up to about a minute after the close, and a minute without a tick gets no trendbar at all; the provider declares both to PyneCore.
  • Order model: position-based with server-side stop-loss / take-profit / trailing stop as position attributes. Netting (one-way) accounts use the direct execution path; hedging accounts run through PyneCore's one-way emulation layer, so Pine one-way semantics hold on both.
  • Closing an execution PyneCore never booked: when an entry's fill evidence never arrives and the strategy asks to close that exposure, PyneCore closes the venue position it reads (held_execution_close). Both account modes support it. On a netting account the plugin closes the symbol's position with ProtoOAClosePositionReq, never by more than the position holds and never on the other side. On a hedging account the leg the held entry's order opened is listed for PyneCore's one-way emulation, which closes it with the bot's other legs. The plugin finds that leg through the venue's order details (the position each of the order's deals executed into).
  • Recovering its own trouble without an operator: when the order stream missed an execution, PyneCore asks the plugin to read it back (fetch_order_execution). The plugin reads the order details (ProtoOAOrderDetailsReq) and returns the order's deals as the fills the stream would have delivered, under the same deal ids. A close the bot sent is judged from its journalled send and the position's deal history. A vanished order the venue no longer finds blocks new entries only until its deal history decides it, then the block is released. A fill of the bot's own order that no journal row tracks any more is adopted as the bot's exposure and booked at once, instead of waiting for a restart. After a restart, a send that filled into a position the startup adopted takes that position over, and the venue's offset ledger (ProtoOADealOffsetListReq) tells which part of its execution is still open.
  • Push order events: order state and fills arrive over the ProtoOAExecutionEvent stream — no polling. Bracket changes go through native atomic amends instead of cancel-and-recreate.

License

Apache-2.0. See LICENSE and NOTICE.

Metadata

Release files for pynesys-pynecore-ctrader 0.9.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pynesys-pynecore-ctrader 0.9.6
File Size Uploaded Provenance Actions
pynesys_pynecore_ctrader-0.9.6.tar.gz 517.0 kB With provenance Details for pynesys_pynecore_ctrader-0.9.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pynesys-pynecore-ctrader 0.9.6
File Interpreter ABI Platform Actions
pynesys_pynecore_ctrader-0.9.6-py3-none-any.whl Python 3 none any Details for pynesys_pynecore_ctrader-0.9.6-py3-none-any.whl

Total release size: 851.4 kB

Release files / pynesys_pynecore_ctrader-0.9.6.tar.gz

Download URL pynesys_pynecore_ctrader-0.9.6.tar.gz
Size 517.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8ee0eb92705cdf369241da728bc67c9c52aab7f39e2f8bb8057a88ac9f08c17e
BLAKE2b-256 checksum
How to use checksums
7a826bd9e47337b40a26d5021a774aa3ce2d779cc9b6183ed716fc5d4cf7ed25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / pynesys_pynecore_ctrader-0.9.6-py3-none-any.whl

Download URL pynesys_pynecore_ctrader-0.9.6-py3-none-any.whl
Size 334.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40981816c5d0fcd52de5fa138c0444c86cb988ce60d1d07d6e884b14ecf78d82
BLAKE2b-256 checksum
How to use checksums
f9067ca3f859979cd22d5565e867eb55e9b580553c2d57049d53426b033e024e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for pynesys-pynecore-ctrader 0.9.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pynesys_pynecore_ctrader-0.9.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page