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:
Executable
+50
@@ -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)"
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Install the .NET SDK locally — no root, no system packages — into ~/.dotnet.
|
||||
# This is the only prerequisite for compiling cBots into .algo files on Linux.
|
||||
#
|
||||
# Usage: ./scripts/install-dotnet.sh [channel] # channel defaults to 8.0
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
INSTALL_DIR="${DOTNET_ROOT:-$HOME/.dotnet}"
|
||||
CHANNEL="${1:-8.0}"
|
||||
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -fsSL https://dot.net/v1/dotnet-install.sh -o /tmp/dotnet-install.sh
|
||||
else
|
||||
wget -qO /tmp/dotnet-install.sh https://dot.net/v1/dotnet-install.sh
|
||||
fi
|
||||
|
||||
bash /tmp/dotnet-install.sh --channel "$CHANNEL" --install-dir "$INSTALL_DIR" --no-path
|
||||
|
||||
cat <<EOF
|
||||
|
||||
.NET SDK installed to $INSTALL_DIR
|
||||
|
||||
Add it to your shell so 'dotnet' is on PATH:
|
||||
|
||||
fish:
|
||||
set -gx DOTNET_ROOT $INSTALL_DIR
|
||||
fish_add_path $INSTALL_DIR
|
||||
|
||||
bash / zsh:
|
||||
export DOTNET_ROOT="$INSTALL_DIR"
|
||||
export PATH="\$DOTNET_ROOT:\$PATH"
|
||||
|
||||
(The build script picks up ~/.dotnet automatically, so this is only needed for
|
||||
running 'dotnet' by hand.)
|
||||
EOF
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Run / backtest a compiled .algo headlessly using Spotware's OFFICIAL cTrader CLI
|
||||
# Docker image — no cTrader desktop GUI, no Windows. Available since cTrader 5.4.
|
||||
#
|
||||
# This is a thin wrapper: it mounts your built .algo files (dist/) into the
|
||||
# container at /mnt/Robots and forwards all arguments to the cTrader console.
|
||||
#
|
||||
# Discover the exact subcommands/flags for your image version first:
|
||||
#
|
||||
# ./scripts/run-console.sh --help
|
||||
#
|
||||
# Then backtest or run, e.g. (flag names follow the container's --help output):
|
||||
#
|
||||
# ./scripts/run-console.sh backtest --robot SmaCrossOverBot.algo \
|
||||
# --symbol EURUSD --period h1 --start 2024-01-01 --end 2024-06-01 \
|
||||
# --balance 10000
|
||||
#
|
||||
# Live trading additionally needs cTrader ID credentials passed to the console.
|
||||
#
|
||||
# Official image + documented commands:
|
||||
# https://github.com/spotware/ctrader-console-docker
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
IMAGE="${CTRADER_CONSOLE_IMAGE:-ghcr.io/spotware/ctrader-console:latest}"
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "docker not found — install Docker to run the cTrader console image." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker pull "$IMAGE"
|
||||
|
||||
exec docker run --rm -it \
|
||||
-v "$REPO_ROOT/dist:/mnt/Robots" \
|
||||
"$IMAGE" "$@"
|
||||
Reference in New Issue
Block a user