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: Direct Download and Install MetaTrader 5 | |
| run: | | |
| # Download latest MT5 setup directly from official source | |
| Invoke-WebRequest -Uri "https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mt5setup.exe" -OutFile mt5setup.exe | |
| # Install with modern silent parameters | |
| Start-Process -FilePath .\mt5setup.exe -ArgumentList "/auto", "/portable" -Wait | |
| # Check standard and portable locations for both 32-bit and 64-bit versions | |
| $possiblePaths = @( | |
| "C:\Program Files\MetaTrader 5\terminal64.exe", | |
| "C:\Program Files\MetaTrader 5\terminal.exe", | |
| ".\MetaTrader 5\terminal64.exe", | |
| ".\MetaTrader 5\terminal.exe", | |
| "$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal64.exe", | |
| "$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal.exe" | |
| ) | |
| $found = $false | |
| foreach ($path in $possiblePaths) { | |
| if (Test-Path $path) { | |
| Write-Host "MetaTrader 5 found at: $path" | |
| $found = $true | |
| break | |
| } | |
| } | |
| if (-not $found) { | |
| Write-Error "MetaTrader 5 installation not found in expected locations" | |
| # Search for installation | |
| Write-Host "Searching for MT5 installation..." | |
| $foundPaths = Get-ChildItem -Path "C:\" -Filter "terminal*.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName | |
| foreach ($path in $foundPaths) { | |
| Write-Host "Found MT5 at: $path" | |
| } | |
| # Add details about system architecture | |
| $architecture = [System.Environment]::Is64BitOperatingSystem ? "64-bit" : "32-bit" | |
| Write-Host "System Architecture: $architecture" | |
| Write-Host "PowerShell Architecture: $([IntPtr]::Size * 8)-bit" | |
| exit 1 | |
| } | |
| - name: Install Python dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install MetaTrader5 pytest | |
| - name: Configure MT5 for headless operation | |
| run: | | |
| # Create data directory for portable mode | |
| $mt5DataDir = ".\MT5_Data" | |
| New-Item -Path $mt5DataDir -ItemType Directory -Force | |
| # Set environment variables for headless operation | |
| echo "MT5_HEADLESS=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "MT5_TIMEOUT=60000" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "MT5_DEBUG=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| # Find MT5 path to pass to the test - check both 32-bit and 64-bit versions | |
| $mt5Path = "" | |
| $possiblePaths = @( | |
| "C:\Program Files\MetaTrader 5\terminal64.exe", | |
| "C:\Program Files\MetaTrader 5\terminal.exe", | |
| ".\MetaTrader 5\terminal64.exe", | |
| ".\MetaTrader 5\terminal.exe", | |
| "$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal64.exe", | |
| "$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal.exe" | |
| ) | |
| foreach ($path in $possiblePaths) { | |
| if (Test-Path $path) { | |
| $mt5Path = $path | |
| $mt5Dir = Split-Path -Parent $mt5Path | |
| echo "MT5_PATH=$mt5Path" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "MT5_DIR=$mt5Dir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| Write-Host "Setting MT5_PATH to $mt5Path" | |
| Write-Host "Setting MT5_DIR to $mt5Dir" | |
| # Create minimal configuration file to help with headless mode | |
| $configLines = @( | |
| '[Common]', | |
| 'Login=0', | |
| 'ProxyEnable=0', | |
| 'CertCheckDisable=1', | |
| 'AutoUpdate=0', | |
| 'DisableStartupCompany=1', | |
| 'EnableOpenCL=0', | |
| 'News=0', | |
| 'StartupCompany=0', | |
| 'Community=0', | |
| 'AutoUpdate.Enable=0' | |
| ) | |
| $configPath = Join-Path $mt5Dir "config\default.ini" | |
| New-Item -Path (Split-Path -Parent $configPath) -ItemType Directory -Force | |
| $configLines | Out-File -FilePath $configPath -Encoding utf8 | |
| Write-Host "Created default config at $configPath" | |
| break | |
| } | |
| } | |
| - name: Configure system for MT5 communication | |
| run: | | |
| # Create registry settings that can help with IPC communication | |
| Write-Host "Configuring system registry for MT5 communication" | |
| # Ensure the MetaTrader registry key exists | |
| $registryPath = "HKCU:\Software\MetaQuotes" | |
| if (-not (Test-Path $registryPath)) { | |
| New-Item -Path $registryPath -Force | Out-Null | |
| } | |
| # Configure Terminal settings if needed | |
| $terminalPath = "$registryPath\Terminal" | |
| if (-not (Test-Path $terminalPath)) { | |
| New-Item -Path $terminalPath -Force | Out-Null | |
| } | |
| # Set some registry values that may help with IPC | |
| Set-ItemProperty -Path $terminalPath -Name "HeadlessMode" -Value 1 -Type DWORD -Force | |
| Set-ItemProperty -Path $terminalPath -Name "AllowDllImport" -Value 1 -Type DWORD -Force | |
| # Check if Python DLLs are accessible from the MT5 installation | |
| $pythonDllPath = Join-Path (Split-Path -Parent (Get-Command python).Path) "python311.dll" | |
| if (Test-Path $pythonDllPath) { | |
| Write-Host "Python DLL found at: $pythonDllPath" | |
| # Copy Python DLL to MT5 directory to help with IPC | |
| if (Test-Path $env:MT5_DIR) { | |
| Copy-Item -Path $pythonDllPath -Destination $env:MT5_DIR -Force | |
| Write-Host "Copied Python DLL to MT5 directory" | |
| } | |
| } else { | |
| Write-Host "Python DLL not found at expected location" | |
| } | |
| - name: Debug environment | |
| run: | | |
| Write-Host "Environment variables:" | |
| Get-ChildItem Env: | |
| Write-Host "MT5 directory contents:" | |
| if (Test-Path $env:MT5_DIR) { | |
| Get-ChildItem -Path $env:MT5_DIR -Recurse -Depth 1 | Select-Object FullName | |
| } | |
| Write-Host "System processes:" | |
| Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | Format-Table -AutoSize | |
| - name: Test MT5 initialization | |
| run: | | |
| # Kill any existing MT5 processes | |
| Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | ForEach-Object { | |
| Write-Host "Killing process $($_.Name) with ID $($_.Id)" | |
| Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue | |
| } | |
| # Give system time to clean up processes | |
| Start-Sleep -Seconds 5 | |
| # Start MT5 with more aggressive IPC settings | |
| $env:MT5_IPC_HOST = "localhost" | |
| $env:MT5_IPC_PORT = "8228" # Use a standard port for IPC | |
| # Start MT5 manually with a combination of flags known to work better in CI | |
| $mt5Process = Start-Process -FilePath $env:MT5_PATH -ArgumentList "/portable", "/config:default.ini", "/skipupdate", "/minimize" -PassThru | |
| Write-Host "Started MT5 process with ID $($mt5Process.Id)" | |
| # Give MT5 more time to initialize - increase wait time | |
| Start-Sleep -Seconds 30 | |
| # Check process is still running and get details | |
| $mt5Running = Get-Process -Id $mt5Process.Id -ErrorAction SilentlyContinue | |
| if ($mt5Running) { | |
| Write-Host "MT5 process is still running with ID $($mt5Process.Id)" | |
| Write-Host "Process details: $($mt5Running | Format-List | Out-String)" | |
| } else { | |
| Write-Host "Warning: MT5 process is no longer running" | |
| } | |
| # Use the existing test script with expanded timeout | |
| python test/integration/test_mt5_initialization.py | |
| env: | |
| MT5_HEADLESS: 1 | |
| MT5_TIMEOUT: 120000 # Increase timeout to 2 minutes | |
| MT5_DEBUG: 1 | |
| MT5_WAIT_PERIOD: 5000 # Wait 5 seconds between attempts |