1
- name : Test | MetaTrader5 Integration Test
1
+ name : MetaTrader5 Integration Test
2
2
3
3
on : [push]
4
4
5
5
jobs :
6
- build :
7
- strategy :
8
- matrix :
9
- os : [windows-latest]
10
- runs-on : ${{ matrix.os }}
6
+ test :
7
+ runs-on : windows-latest
8
+ timeout-minutes : 15 # Increased timeout
11
9
steps :
12
- - name : Checkout repository
10
+ - name : Checkout code
13
11
uses : actions/checkout@v4
14
12
15
- - name : Set up Python
16
- uses : actions/setup-python@v4
17
- with :
18
- python-version : ' 3.11'
19
-
20
- - name : Download MetaTrader5 Installer
21
- run : |
22
- $url = "https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mt5setup.exe"
23
- $output = "$env:GITHUB_WORKSPACE\mt5setup.exe"
24
- Invoke-WebRequest -Uri $url -OutFile $output
13
+ - name : Install MT5 (Portable)
25
14
shell : pwsh
26
-
27
- - name : Install MetaTrader5
28
15
run : |
29
- $process = Start-Process -FilePath ".\mt5setup.exe" -ArgumentList "/auto", "/portable" -PassThru
30
- $process.WaitForExit(300000)
31
- if (-not $process.HasExited) {
32
- Write-Host "MT5 installer stuck, killing..."
33
- Stop-Process -Id $process.Id -Force
34
- exit 1
16
+ # Clean previous installation
17
+ if (Test-Path ".\MetaTrader 5") {
18
+ Remove-Item -Recurse -Force ".\MetaTrader 5"
35
19
}
36
- shell : pwsh
37
20
38
- - name : Launch MetaTrader5
39
- run : |
40
- $mt5Path = "$env:GITHUB_WORKSPACE\MT5Portable\terminal64.exe"
41
- $configPath = "$env:GITHUB_WORKSPACE\MT5Portable\config"
21
+ # Download with retries
22
+ $retries = 3
23
+ do {
24
+ try {
25
+ Invoke-WebRequest https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mt5setup.exe `
26
+ -OutFile mt5setup.exe -TimeoutSec 60
27
+ break
28
+ } catch {
29
+ $retries--
30
+ if ($retries -eq 0) { throw }
31
+ Write-Host "Download failed, retries left: $retries"
32
+ Start-Sleep 5
33
+ }
34
+ } while ($retries -gt 0)
35
+
36
+ # Install with explicit paths
37
+ $installProcess = Start-Process .\mt5setup.exe `
38
+ -ArgumentList @("/portable", "/skipupdate", "/auto") `
39
+ -PassThru -NoNewWindow
42
40
43
- # Create basic configuration
41
+ # Wait with timeout
42
+ if (-not $installProcess.WaitForExit(180000)) {
43
+ Write-Error "Installation timed out after 3 minutes"
44
+ exit 1
45
+ }
46
+
47
+ # Verify installation
48
+ if (-not (Test-Path ".\MetaTrader 5\terminal64.exe")) {
49
+ Write-Host "Installed directory contents:"
50
+ Get-ChildItem ".\MetaTrader 5" -Recurse
51
+ throw "Installation failed - terminal64.exe missing"
52
+ }
53
+
54
+ - name : Configure Server
55
+ shell : pwsh
56
+ run : |
57
+ $configPath = ".\MetaTrader 5\config"
44
58
New-Item -Path $configPath -ItemType Directory -Force
45
- Set-Content -Path "$configPath\servers.dat" -Value "YourServerHere,Demo,ServerAddressHere,443"
59
+
60
+ # Create server configuration
61
+ @"
62
+ DemoServer,Demo,demo.example.com,443
63
+ " @ | Set-Content " $configPath\servers.dat"
64
+
65
+ # Create basic terminal configuration
66
+ @"
67
+ [Common]
68
+ Language=English
69
+ AutoUpdate=0
70
+ EnableNews=0
71
+ [Connection]
72
+ EnableWebRequest=0
73
+ " @ | Set-Content " $configPath\terminal.ini"
46
74
47
- # Launch with headless options
48
- $process = Start-Process $mt5Path -ArgumentList @(
49
- "/portable",
50
- "/headless",
51
- "/config:$configPath",
52
- "/login:12345 /password:demo /server:ServerAddressHere"
53
- ) -PassThru
75
+ - name : Launch MT5
76
+ shell : pwsh
77
+ run : |
78
+ $mt5Path = Resolve-Path ".\MetaTrader 5\terminal64.exe"
54
79
55
- # Wait and verify process
56
- Start-Sleep -Seconds 60
57
- if ($process.HasExited -or -not (Get-Process terminal64 -ErrorAction SilentlyContinue)) {
58
- Write-Error "Failed to launch MT5"
59
- Get-Content "$env:GITHUB_WORKSPACE\MT5Portable\logs\*.log" | Write-Host
60
- exit 1
80
+ # Kill existing instances
81
+ taskkill /IM terminal64.exe /F 2>&1 | Out-Null
82
+
83
+ # Launch with diagnostics
84
+ Start-Process $mt5Path -ArgumentList @(
85
+ "/portable",
86
+ "/headless",
87
+ "/config:config",
88
+ "/noreport"
89
+ ) -NoNewWindow
90
+
91
+ # Verify process start
92
+ $attempts = 0
93
+ while ($attempts -lt 10) {
94
+ if (Get-Process terminal64 -ErrorAction SilentlyContinue) {
95
+ Write-Host "MT5 process detected"
96
+ break
97
+ }
98
+ $attempts++
99
+ Start-Sleep 5
100
+ }
101
+
102
+ if (-not (Get-Process terminal64 -ErrorAction SilentlyContinue)) {
103
+ Get-Content ".\MetaTrader 5\logs\*.log" | Write-Host
104
+ throw "MT5 failed to start"
61
105
}
62
- shell : pwsh
63
106
64
- - name : Run MT5 Test
107
+ - name : Test Connection
108
+ shell : pwsh
65
109
run : |
66
- python -c "import os, MetaTrader5 as mt5
67
- print('Python version:', os.sys.version)
68
- for i in range(10):
69
- try:
70
- if mt5.initialize():
71
- print('MT5 initialized successfully')
72
- print(mt5.terminal_info())
73
- mt5.shutdown()
74
- exit(0)
75
- print(f'Attempt {i+1} failed')
76
- except Exception as e:
77
- print(f'Error: {str(e)}')
78
- import time; time.sleep(10)
79
- print('All attempts failed')
80
- exit(1)"
110
+ # Allow more time for terminal initialization
111
+ Start-Sleep -Seconds 45
112
+
113
+ python -c "
114
+ import MetaTrader5 as mt5
115
+ from time import sleep
116
+ import sys
117
+
118
+ max_attempts = 8
119
+ for attempt in range(max_attempts) :
120
+ try :
121
+ if mt5.initialize() :
122
+ print(f'Successfully connected to MT5 {mt5.version()}')
123
+ print('Terminal info:', mt5.terminal_info()._asdict())
124
+ mt5.shutdown()
125
+ sys.exit(0)
126
+ print(f'Attempt {attempt+1}/{max_attempts} : Initialize failed')
127
+ except Exception as e :
128
+ print(f'Attempt {attempt+1}/{max_attempts} : Error - {str(e)}')
129
+ sleep(10)
130
+ print('All connection attempts failed')
131
+ sys.exit(1)
132
+ "
0 commit comments