diff --git a/bridge/mt5_bridge.py b/bridge/mt5_bridge.py index 74764ea..b5cc6d6 100644 --- a/bridge/mt5_bridge.py +++ b/bridge/mt5_bridge.py @@ -4,7 +4,7 @@ import time # Connect to the trading bot container sio = socketio.Client() # Replace with the appropriate URL and port of your trading bot container -sio.connect('http://trading_bot:8000') +sio.connect('http://trading_bot:3000') # Handle events from the trading bot container diff --git a/docker-compose.yml b/docker-compose.yml index e780520..1c37341 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,21 +1,27 @@ version: "3" services: metatrader_service: + build: + context: . + dockerfile: docker/DockerFile.xorg container_name: metatrader - image: ejtrader/metatrader:5 restart: unless-stopped + environment: + - DISPLAY=$DISPLAY + privileged: true + volumes: + - /tmp/.X11-unix:/tmp/.X11-unix + - ./mt5:/mt5 + devices: + - /dev/dri:/dev/dri ports: - "5900:5900" - "15555:15555" - "15556:15556" - "15557:15557" - "15558:15558" - volumes: - - ejtraderMT:/data - environment: - - DISPLAY=host.docker.internal:0 - - MT5_PASSWORD=your_password - - MT5_SERVER=your_server + networks: + - trading_network trading_bot: container_name: trading_bot @@ -24,8 +30,12 @@ services: dockerfile: docker/DockerFile volumes: - ./app:/app + ports: + - 3000:3000 depends_on: - metatrader_service + networks: + - trading_network mt5_bridge: container_name: mt5_bridge @@ -37,6 +47,9 @@ services: depends_on: - metatrader_service - trading_bot + networks: + - trading_network -volumes: - ejtraderMT: {} +networks: + trading_network: + driver: bridge diff --git a/docker/DockerFile.xorg b/docker/DockerFile.xorg new file mode 100644 index 0000000..99e133f --- /dev/null +++ b/docker/DockerFile.xorg @@ -0,0 +1,39 @@ +# Base docker image. +FROM ubuntu:focal + +# Install Wine and necessary dependencies +RUN dpkg --add-architecture i386 && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + gnupg \ + software-properties-common \ + wget \ + winbind \ + xauth \ + xvfb \ + cabextract + +# Download and install Wine from WineHQ repository +RUN wget -qO- https://dl.winehq.org/wine-builds/winehq.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/winehq.gpg && \ + add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ focal main' && \ + apt-get update && \ + apt-get install -y --install-recommends winehq-stable winetricks + +# Create a non-root user +RUN useradd -m -s /bin/bash trader + +# Set the working directory +WORKDIR /home/trader + +# Install X server utilities +RUN apt-get install -y x11-xserver-utils x11vnc xvfb + +# Configure X server +RUN mkdir /tmp/.X11-unix && \ + chown trader:trader /tmp/.X11-unix + +# Set up entrypoint script +COPY mt5/entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/mt5/entrypoint.sh b/mt5/entrypoint.sh new file mode 100644 index 0000000..fdeaeb1 --- /dev/null +++ b/mt5/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Start the X server +Xvfb :0 -screen 0 1024x768x16 & + +# Set the X display +export DISPLAY=:0 + +# Install necessary dependencies using winetricks +winetricks -q corefonts + +# Run MetaTrader 5 +su - trader -c 'wine "/home/trader/.wine/drive_c/Program Files/MetaTrader 5/terminal64.exe"'