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 | MetaTrader5 Integration Test | ||
| on: [push] | ||
| jobs: | ||
| build: | ||
| strategy: | ||
| matrix: | ||
| os: [windows-latest, windows-2022] # run on both Win runners | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.11' | ||
| - name: Download MetaTrader5 Installer | ||
| run: | | ||
| Invoke-WebRequest ` | ||
| -Uri "https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mt5setup.exe" ` | ||
| -OutFile "mt5setup.exe" | ||
| shell: pwsh | ||
| - name: Install MetaTrader5 | ||
| run: | | ||
| $process = Start-Process -FilePath ".\mt5setup.exe" -ArgumentList "/auto", "/portable" -PassThru | ||
| $process.WaitForExit(300000) # 5 minutes timeout | ||
| if (-not $process.HasExited) { | ||
| Write-Host "MT5 installer stuck, killing..." | ||
| Stop-Process -Id $process.Id -Force | ||
| exit 1 | ||
| } | ||
| shell: pwsh | ||
| - name: Kill any existing MT5 processes | ||
| run: | | ||
| Get-Process terminal64 -ErrorAction SilentlyContinue | Stop-Process -Force | ||
| shell: pwsh | ||
| - name: Launch MetaTrader5 Terminal in portable mode | ||
| run: | | ||
| $mt5Paths = @( | ||
| "C:\Program Files\MetaTrader 5\terminal64.exe", | ||
| ".\MetaTrader 5\terminal64.exe", | ||
| ".\MetaTrader5\terminal64.exe" | ||
| ) | ||
| foreach ($path in $mt5Paths) { | ||
| if (Test-Path $path) { | ||
| Start-Process -FilePath $path -ArgumentList "/portable" -WindowStyle Hidden | ||
| Write-Host "Launched MT5 from $path" | ||
| break | ||
| } | ||
| } | ||
| Start-Sleep -Seconds 15 | ||
| shell: pwsh | ||
| - name: Check MT5 process running | ||
| run: | | ||
| Get-Process terminal64 -ErrorAction Stop | ||
| shell: pwsh | ||
| - name: Install MetaTrader5 Python package | ||
| run: pip install MetaTrader5 | ||
| - name: Run Python inline script | ||
| shell: pwsh | ||
| run: | | ||
| python -c "import MetaTrader5 as mt5; import time; print('Testing MT5 initialization...'); \ | ||
| for attempt in range(12): \ | ||
| if mt5.initialize(): \ | ||
| print('MT5 initialized successfully'); \ | ||
| mt5.shutdown(); \ | ||
| break; \ | ||
| else: \ | ||
| print(f'Attempt {attempt+1}: Not ready yet, sleeping...'); \ | ||
| time.sleep(5); \ | ||
| else: \ | ||
| print('Failed to initialize MT5 after waiting.'); \ | ||
| exit(1)" | ||