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
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
#
# Compile every cBot/indicator project in src/ into .algo files — on Linux, with
# no Windows and no cTrader desktop app. The .algo files are collected into dist/.
#
# Usage: ./scripts/build.sh [Release|Debug] # defaults to Release
#
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
CONFIG="${1:-Release}"
# Pick up the locally-installed SDK (see scripts/install-dotnet.sh).
export DOTNET_ROOT="${DOTNET_ROOT:-$HOME/.dotnet}"
export PATH="$DOTNET_ROOT:$PATH"
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_NOLOGO=1
if ! command -v dotnet >/dev/null 2>&1; then
echo "dotnet not found. Run ./scripts/install-dotnet.sh first." >&2
exit 1
fi
SLN="$REPO_ROOT/cTraderBots.sln"
if [[ ! -f "$SLN" ]]; then
echo ">> Creating solution and adding projects..."
dotnet new sln --name cTraderBots --output "$REPO_ROOT"
find "$REPO_ROOT/src" -name '*.csproj' -print0 \
| xargs -0 -I{} dotnet sln "$SLN" add {}
fi
echo ">> Building ($CONFIG)..."
dotnet build "$SLN" --configuration "$CONFIG"
DIST="$REPO_ROOT/dist"
mkdir -p "$DIST"
# Collect artifacts. cTrader.Automate names the raw .algo after the project's parent
# folder (which collides across bots), so rename each to <ProjectName>.algo here.
while IFS= read -r -d '' csproj; do
name="$(basename "${csproj%.csproj}")"
algo="$(find "$(dirname "$csproj")/bin/$CONFIG" -name '*.algo' 2>/dev/null | head -1)"
if [[ -n "$algo" ]]; then
cp -v "$algo" "$DIST/$name.algo"
fi
done < <(find "$REPO_ROOT/src" -name '*.csproj' -print0)
echo
echo ">> .algo artifacts in $DIST:"
ls -1 "$DIST"/*.algo 2>/dev/null || echo " (none found — check the build output above)"