Wickfleet

Freqtrade Docker Compose: many bots, one address

Freqtrade's own docker-compose.yml runs one bot and publishes its API and FreqUI on 127.0.0.1:8080. With several bots each one gets its own port, and FreqUI in the browser then talks to several addresses. That is where the CORS error comes from. This page covers what the API settings do, what breaks and why, and how to put every bot behind one address.

Where the CORS error comes from

What the api_server settings do

SettingWhat it does
enabledturns the REST API on. FreqUI is served from the same port
listen_ip_addressthe address the API binds to. The sample config uses 127.0.0.1. In Docker it has to be 0.0.0.0, or the published port reaches nothing. Who can reach the bot is then decided by the ports line
listen_portthe port inside the container, 8080 in the samples
username, passwordthe API login. FreqUI sends them once and gets two tokens back
jwt_secret_keysigns those tokens: an access token valid for 15 minutes and a refresh token valid for 30 days. The docs ask for a random value of 32 characters or more. Freqtrade logs a security warning when it is still a sample value. A token signed with an old key is no longer accepted, so after a change every browser logs in again
CORS_originsthe list of origins that may call this API from a browser, such as ["http://localhost:8080"]. No trailing slash. A * entry is not allowed by the standard for requests with credentials
ws_tokena fixed token for the message websocket at /api/v1/message/ws, for other programs such as a consumer bot in producer and consumer mode. FreqUI does not need it. It opens the same websocket with its access token, and the API accepts either

What breaks, and why

What you seeCause
Login to a second bot fails with the CORS hintCORS_origins of that bot does not hold the address in your browser bar, or holds it with a trailing slash
The published port answers nothinglisten_ip_address is still 127.0.0.1 inside the container
The API answers from the whole networkthe port is published as "8080:8080". "127.0.0.1:8080:8080" keeps it on the host. The docs advise against exposing the API to the internet and name an SSH tunnel or a VPN for remote access
The websocket fails behind nginxnginx needs the Upgrade and Connection headers set for websockets. Traefik and Caddy v2 support websockets out of the box
A second browser or device shows no botsFreqUI keeps its bot list and the tokens in that browser's local storage

One origin by hand

Requests to the origin the page came from are not cross-origin, so no CORS rule applies to them. A reverse proxy can give FreqUI and every bot API the same scheme, host and port. FreqUI appends /api/v1 to the address you enter for a bot, so a bot can sit under a path such as /bots/meanrev as long as the proxy strips that prefix before it passes the request on.

With Traefik, one bot serves FreqUI at the root and every further bot gets a path:

services:
  traefik:
    image: traefik:v3.7.17
    restart: unless-stopped
    command:
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --entrypoints.web.address=:8000
    ports:
      - "127.0.0.1:8000:8000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
  trend:
    image: freqtradeorg/freqtrade:stable
    restart: unless-stopped
    volumes:
      - ./trend/user_data:/freqtrade/user_data
    command: trade --config /freqtrade/user_data/config.json --db-url sqlite:////freqtrade/user_data/tradesv3.sqlite --strategy Trend
    labels:
      traefik.enable: "true"
      traefik.http.routers.trend.rule: "PathPrefix(`/`)"
      traefik.http.routers.trend.entrypoints: web
      traefik.http.routers.trend.priority: "1"
      traefik.http.services.trend.loadbalancer.server.port: "8080"
  meanrev:
    image: freqtradeorg/freqtrade:stable
    restart: unless-stopped
    volumes:
      - ./meanrev/user_data:/freqtrade/user_data
    command: trade --config /freqtrade/user_data/config.json --db-url sqlite:////freqtrade/user_data/tradesv3.sqlite --strategy MeanRev
    labels:
      traefik.enable: "true"
      traefik.http.routers.meanrev.rule: "PathPrefix(`/bots/meanrev/`)"
      traefik.http.routers.meanrev.entrypoints: web
      traefik.http.routers.meanrev.priority: "50"
      traefik.http.routers.meanrev.middlewares: meanrev-strip
      traefik.http.middlewares.meanrev-strip.stripprefix.prefixes: /bots/meanrev
      traefik.http.services.meanrev.loadbalancer.server.port: "8080"

No bot publishes a port. Each bot's config.json carries:

"api_server": {
    "enabled": true,
    "listen_ip_address": "0.0.0.0",
    "listen_port": 8080,
    "jwt_secret_key": "32 random characters or more, per bot",
    "CORS_origins": [],
    "username": "trend",
    "password": "a strong password, per bot"
}

Open http://localhost:8000, log in to the first bot at that address, then add the second with the API URL http://localhost:8000/bots/meanrev. CORS_origins stays empty on both.

What stays manual: every bot keeps its own login, typed into each browser. The proxy itself has no login, so keep the port on 127.0.0.1 or behind a VPN. Each further bot is one more block of labels.

How Wickfleet sets it up

Wickfleet's deploy/compose/compose.yml is the same idea with a login in front. The bots are not in the compose file. The hub creates one container per bot file in the registry and writes the route labels itself.

ServiceJob
traefikthe only published port, 127.0.0.1:8000 by default. It reads container labels through a read-only Docker socket proxy
uithe FreqUI fork as static files, for every path outside /api, /bots/ and /hub/
hubthe login and the API under /hub/. Traefik asks the hub before it passes a request to the UI or to a bot
dockerguardsits between the hub and a second socket proxy. It lets the hub create containers only from the listed Freqtrade image, with the listed bind paths, network and user
Bot containersone per bot, routed at /bots/<name>/ with the prefix stripped, to port 8080, with no published port

The hub also writes the api_server block of every bot:

SettingValue the hub writes
enabled, listen_ip_address, listen_porttrue, 0.0.0.0, 8080
CORS_origins[]. Every bot is on the origin of the UI
usernamethe bot's name
password, jwt_secret_keyrandom, 32 bytes each, made per bot on first use and kept in the hub's state directory
ws_tokennot set
Fleet overview: totals per stake currency and one row per bot, amounts blurred
Every bot of the registry on one address

Try it

git clone https://github.com/wickfleet/wickfleet.git
cd wickfleet
make quickstart

Needs Docker with Compose v2, git and make, on macOS or Linux. Everything runs on one machine, bound to 127.0.0.1, and a dry-run demo bot is waiting in the fleet. More in the install guide.

More on running a fleet

Wickfleet is software for running trading bots, not a recommendation to buy or sell anything. Backtests and replays describe the past, not the future. Every bot is a dry run on a simulated wallet by default.