# WickBot — Linux/Docker deployment via Wine # # This runs a real Windows MT5 terminal inside Wine, a small RPyC server # next to it (mt5linux), and the bot itself (Linux-native Python) talking # to that server over localhost. See mt5_connector.py for the client side. # # IMPORTANT — read before deploying: # - This is inherently more fragile than running WickBot natively on # Windows. Wine + a GUI trading terminal in a headless container is a # known-workable but occasionally finicky combination. # - The MT5 terminal needs to be logged in at least once. Headless # containers have no screen to click through a login dialog, so the # first login is easiest done via the VNC port exposed below — # connect a VNC viewer to it once, log in, and (if your storage is # persistent) it should stay logged in on restarts. On Hugging Face # Spaces specifically, storage may not persist across a full rebuild, # so you may need to re-login after those. # - Long-running background processes on free-tier hosting can be # paused/killed on inactivity or resource limits — check your # platform's policy for always-on containers before relying on this # for anything beyond training/paper trading. # # Build: docker build -t wickbot -f docker/Dockerfile . # Run: docker run -p 5900:5900 --env-file .env wickbot # Then connect a VNC client to :5900 to log into MT5 the first time. FROM ubuntu:22.04 ENV DEBIAN_FRONTEND=noninteractive \ WINEARCH=win64 \ WINEPREFIX=/root/.wine \ DISPLAY=:99 # --- System deps: Wine, a virtual display, VNC (for the one-time login), supervisor --- RUN dpkg --add-architecture i386 && \ apt-get update && \ apt-get install -y --no-install-recommends \ wget gnupg2 software-properties-common ca-certificates \ xvfb x11vnc supervisor cabextract unzip winbind \ python3 python3-pip curl && \ wget -nc https://dl.winehq.org/wine-builds/winehq.key -O /usr/share/keyrings/winehq-archive.key && \ echo "deb [signed-by=/usr/share/keyrings/winehq-archive.key] https://dl.winehq.org/wine-builds/ubuntu/ jammy main" \ > /etc/apt/sources.list.d/winehq.list && \ apt-get update && \ apt-get install -y --no-install-recommends winehq-stable && \ rm -rf /var/lib/apt/lists/* # --- Install uv (for the Linux-side bot process) --- RUN curl -LsSf https://astral.sh/uv/install.sh | sh ENV PATH="/root/.local/bin:${PATH}" # --- Initialize the Wine prefix --- RUN wineboot --init && sleep 5 # --- Install Python for Windows, inside Wine --- # Pin a version known to work with the MetaTrader5 Windows package. RUN wget -q https://www.python.org/ftp/python/3.10.11/python-3.10.11-amd64.exe -O /tmp/wine-python.exe && \ xvfb-run -a wine /tmp/wine-python.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 && \ rm /tmp/wine-python.exe # --- Install MetaTrader5 + mt5linux server package inside Wine-Python --- RUN xvfb-run -a wine python -m pip install --upgrade pip && \ xvfb-run -a wine python -m pip install MetaTrader5 mt5linux # --- App code --- # The mt5_terminal/ directory is NOT copied here — it's uploaded separately # via Git LFS using scripts/upload_to_hf.py --mt5 to keep image builds fast. # At runtime the HF Space will have mt5_terminal/ at /app/mt5_terminal/. WORKDIR /app COPY . /app RUN uv sync --extra linux-wine # --- Supervisor config (Xvfb, VNC, wine MT5 terminal, mt5linux server, bot) --- COPY docker/supervisord.conf /etc/supervisor/conf.d/wickbot.conf EXPOSE 5900 8000 # Default WEBAPP_PORT=8000 matches .env.example. HF Spaces overrides this # via its Space Settings → Variables (the convention on HF is 7860). ENV MT5_BACKEND=linux \ MT5LINUX_HOST=localhost \ MT5LINUX_PORT=18812 \ WEBAPP_HOST=0.0.0.0 \ WEBAPP_PORT=8000 \ HF_APP_PORT=7860 CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/wickbot.conf"]