virtual display #28
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test | Test MetaTrader5 Initialization | |
| on: | |
| push: | |
| branches: ['*'] | |
| pull_request: | |
| jobs: | |
| test: | |
| runs-on: windows-latest | |
| timeout-minutes: 15 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Download and Install MetaTrader 5 | |
| run: | | |
| # Download MT5 setup | |
| Invoke-WebRequest -Uri "https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mt5setup.exe" -OutFile mt5setup.exe | |
| # Install MT5 silently | |
| Start-Process -FilePath .\mt5setup.exe -ArgumentList "/auto" -Wait | |
| # Verify installation | |
| $mtPath = "C:\Program Files\MetaTrader 5\terminal64.exe" | |
| if (Test-Path $mtPath) { | |
| Write-Host "MetaTrader 5 installed successfully" | |
| } else { | |
| Write-Error "MetaTrader 5 installation failed" | |
| exit 1 | |
| } | |
| - name: Install Python dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install MetaTrader5 | |
| - name: Setup virtual display | |
| run: | | |
| # Install Chocolatey if not already installed | |
| if (-not (Get-Command choco -ErrorAction SilentlyContinue)) { | |
| Set-ExecutionPolicy Bypass -Scope Process -Force | |
| [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 | |
| Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) | |
| } | |
| # Install VcXsrv Windows X Server | |
| choco install vcxsrv -y | |
| # Start VcXsrv in background | |
| Start-Process "C:\Program Files\VcXsrv\vcxsrv.exe" -ArgumentList "-multiwindow", "-ac", "-terminate", "-lesspointer", "-wgl", "-dpi auto" | |
| # Set DISPLAY environment variable | |
| [Environment]::SetEnvironmentVariable("DISPLAY", "127.0.0.1:0.0", "Process") | |
| Write-Host "Virtual display configured with DISPLAY=127.0.0.1:0.0" | |
| Start-Sleep -Seconds 5 | |
| - name: Run MT5 terminal with desktop parameter | |
| run: | | |
| # Kill any existing MT5 instances | |
| taskkill /F /IM terminal64.exe 2>$null | |
| Start-Sleep -Seconds 3 | |
| # Start MT5 with the /portable parameter | |
| $process = Start-Process -FilePath "C:\Program Files\MetaTrader 5\terminal64.exe" -ArgumentList "/portable" -PassThru | |
| $processId = $process.Id | |
| Write-Host "Started MetaTrader 5 terminal with PID $processId using virtual display" | |
| Start-Sleep -Seconds 30 | |
| - name: Test MT5 initialization | |
| run: > | |
| python -c "import sys, MetaTrader5 as mt5; | |
| print(f'MT5 version: {mt5.__version__}'); | |
| print('Initializing...'); | |
| result = mt5.initialize(path='C:\\\\Program Files\\\\MetaTrader 5\\\\terminal64.exe', timeout=60000); | |
| print(f'Result: {result}, Error: {mt5.last_error()}'); | |
| sys.exit(0)" |