Add Linux-native cTrader cBot build/run scaffold

Build cBots in C# and compile them to .algo entirely on Linux via the
official cTrader.Automate NuGet package + 'dotnet build' — no Windows and
no cTrader desktop app. Run/backtest headless through Spotware's official
cTrader console Docker image.

Includes:
- src/SampleCBot: example SMA-crossover cBot (SDK-style net6.0 class library)
- scripts/install-dotnet.sh: root-free local .NET SDK install (~/.dotnet)
- scripts/build.sh: dotnet build -> dist/<ProjectName>.algo, with a workaround
  for cTrader.Automate naming the .algo after the project's parent folder
- scripts/run-console.sh: wrapper over ghcr.io/spotware/ctrader-console
- docs/research-findings.md: sourced research; .algo verified as a proprietary
  'algo'-magic container (not a ZIP); build verified end to end on Linux
This commit is contained in:
2026-06-18 20:54:56 +02:00
commit 9c39a743d0
10 changed files with 535 additions and 0 deletions
+111
View File
@@ -0,0 +1,111 @@
# Research: building & running cTrader cBots without Windows
This documents what was established before building the scaffold in this repo. The two
load-bearing claims were each adversarially fact-checked (the verifier was instructed to
*refute* them); both came back **CONFIRMED**. Where a fact was verified locally on this
machine rather than only from the web, it is marked **[verified locally]**.
## The claim under test
> It is possible to create cTrader cBots directly in C# with no Windows, produce `.algo`
> files, and run them in a container.
**Verdict: true**, in two officially-supported halves — but the second half is recent
enough that older sources (and people relying on them) say it's impossible.
## The era split (why answers conflict)
| Era | Build | Run on Linux |
|---|---|---|
| Old **cAlgo**, .NET Framework 4.x (≤ cTrader 4.1, pre-2022) | Windows-only `cTrader.exe /compile` (Spotware: *"not actually supported"*) | No |
| Modern **cTrader Automate**, .NET 6 (cTrader 4.2+, Mar 2022) | `dotnet build` + `cTrader.Automate` NuGet — cross-platform | Desktop only at first; **Linux Docker since cTrader 5.4 (~Aug 2025)** |
cTrader Desktop 4.2 (30 Mar 2022) *"removed any dependency from the cTrader application
for the build process"* and let developers *"compile cBots and indicators using the
'dotnet build' command and even write code and compile it on Linux or Mac."*
## 1. Compiling `.algo` on Linux — CONFIRMED
- **Official SDK package:** `cTrader.Automate` on NuGet, owner **spotware**
(Spotware Systems Ltd.). Description: *"Provides cTrader Automate SDK to build cBots
and Indicators in ALGO format."* Multi-targets **net6.0+** and net40, **no
dependencies** → installs and runs fine via `dotnet` on Linux. (Latest seen: 1.0.17,
2026-03-27.)
- **Mechanism:** the package ships MSBuild `.targets`. Building a class library that
references it and contains an algo type (a class deriving from `Robot`/`Indicator`)
bundles the compiled assembly into the `.algo`. **[verified locally]** — a clean
`dotnet build -c Release` on this Linux box produced a valid `.algo` with **0 errors**.
- **What you need on Linux:** just the .NET SDK + NuGet access. No Windows, no Wine, no
cTrader desktop.
- **Beware the name collision:** there is a *separate* third-party NuGet package
`cAlgo.API` (owner `st.alexofgod`, MIT). It is **not** the Spotware SDK. Use
`cTrader.Automate`.
### Build verified, plus a local finding
- The `.algo` filename quirk: `cTrader.Automate` 1.0.17 names the output after the
**parent directory of the project folder**`_AlgoFileName =
GetFileName(GetDirectoryName(MSBuildProjectDirectory))` in its
`cTrader.Automate.targets`, with no override property. **[verified locally]** Two bots
in one folder collide; this repo renames artifacts in `build.sh`.
- **`.algo` format — what it actually is. [verified locally]** A built `.algo` begins
with the ASCII magic bytes `algo` (`61 6c 67 6f`) and is **not** a ZIP (no `PK` header,
no central directory). So it is Spotware's own proprietary container, not a renamed
archive — settling a question the web sources left open. Per Spotware it wraps the
compiled assembly (+ referenced DLLs, + optional source/symbols) and is encrypted; the
encryption algorithm is undisclosed and there is no public byte-level spec.
## 2. Running `.algo` headless in a container — CONFIRMED (recent)
- **Official runner:** **cTrader CLI / Console**, distributed as a Linux Docker image
`ghcr.io/spotware/ctrader-console` (repo `spotware/ctrader-console-docker`). Docs:
it *"enables traders to manage account and algo-trading operations directly from a
console or terminal without launching or relying on the regular cTrader application"*
and *"is available as a Linux Docker image … All cTrader CLI features are available
when using the Docker image, including backtesting."* Mount `.algo` files to
`/mnt/Robots`.
- **Recency caveat:** available only in **cTrader 4.8+**, works only with **modern .NET 6
algos**, and the Linux image arrived with **cTrader 5.4 (~Aug 2025)**. As late as
**Nov 2024** a Spotware moderator wrote *"Unfortunately cTrader CLI is not supported on
Linux"*, and DIY Wine/Mono attempts failed. So pre-2025 sources correctly said it was
impossible — this is the single most likely source of disagreement.
- The runner is a **host, not a compiler** — it runs/backtests `.algo` files; it does not
build them. Compilation is the `dotnet build` step above.
## 3. cTrader Automate vs. Open API (don't conflate)
Two different products that can both run on headless Linux:
- **cTrader Automate (cBots / `.algo`)** — the strategy framework (`cAlgo.API`,
indicators, backtesting, optimization). Runs *inside* the cTrader runtime / the cTrader
CLI. This is what this repo targets.
- **cTrader Open API** — a *separate* protocol (Protobuf over TLS/TCP or WebSocket, OAuth2;
endpoints `live.ctraderapi.com` / `demo.ctraderapi.com`) for **external** apps that
connect to a broker backend. Official SDKs: .NET (`cTrader.OpenAPI.Net`) and Python
(`ctrader-open-api`); language-neutral otherwise. It gives you trading + market data +
account access, but **no** cBot framework, indicators, or backtesting — you write all
strategy logic yourself.
Choose **Automate + cTrader CLI** to reuse the cBot framework and backtesting on Linux;
choose **Open API** for a fully standalone, language-flexible service.
## Limitations / honesty notes
- The cTrader **desktop app** is Windows/macOS only — not needed for this workflow, but
there is no native Linux *desktop*.
- **Live** trading needs a broker account + cTrader ID credentials.
- The `.algo` container is proprietary and encrypted; any legitimate Linux build goes
*through* the official `cTrader.Automate` package — there is no independent OSS packer.
- cTrader's docs/tooling move quickly; version numbers above reflect mid-2026.
## Key sources
- cTrader Desktop 4.2 release — https://www.spotware.com/news/ctrader-desktop-4-2/
- Use Visual Studio and other IDEs — https://help.ctrader.com/ctrader-algo/documentation/visual-studio-ides/
- Compiler (MSBuild properties) — https://help.ctrader.com/ctrader-algo/documentation/all-algos/compiling/
- cTrader CLI — https://help.ctrader.com/ctrader-algo/documentation/ctrader-cli/
- Console Docker image — https://github.com/spotware/ctrader-console-docker
- `cTrader.Automate` package — https://www.nuget.org/packages/cTrader.Automate/
- Algo security measures (encryption) — https://help.ctrader.com/ctrader-algo/documentation/protection-measures/
- Open API getting started — https://help.ctrader.com/open-api/
- Forum: Linux not supported (Nov 2024) — https://community.ctrader.com/forum/ctrader-algo/45395/