1
- name : Test |Test MetaTrader5 Integration
1
+ name : Test MetaTrader5 Integration
2
2
3
3
on :
4
4
push :
5
- branches : ['*'] # <<<<<<<<<<<<<<<<<<<<<<<<<< Return to main before merging
5
+ branches : ['*']
6
6
pull_request :
7
7
8
8
jobs :
@@ -17,135 +17,12 @@ jobs:
17
17
with :
18
18
python-version : ' 3.11'
19
19
20
- - name : Download MetaTrader 5
21
- run : |
22
- Invoke-WebRequest -Uri "https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mt5setup.exe" -OutFile mt5setup.exe
23
- # Verify download was successful
24
- if (!(Test-Path "mt5setup.exe")) {
25
- Write-Error "MetaTrader 5 download failed."
26
- exit 1
27
- }
28
-
29
- - name : Install MetaTrader 5 silently
30
- run : |
31
- Start-Process -FilePath .\mt5setup.exe -ArgumentList "/auto" -Wait
32
- # Give installation some time to complete
33
- Start-Sleep -Seconds 60
34
-
35
- - name : Create MetaTrader configuration
36
- run : |
37
- # Create directory for MetaTrader configuration
38
- $mt5ConfigDir = "C:\Users\runneradmin\AppData\Roaming\MetaQuotes\Terminal"
39
- if (!(Test-Path $mt5ConfigDir)) {
40
- New-Item -Path $mt5ConfigDir -ItemType Directory -Force
41
- Write-Host "Created MetaTrader configuration directory: $mt5ConfigDir"
42
- }
43
-
44
- - name : Verify MetaTrader 5 Installation and Start Terminal
45
- run : |
46
- $mtPath = "C:\Program Files\MetaTrader 5\terminal64.exe"
47
- if (!(Test-Path $mtPath)) {
48
- Write-Error "MetaTrader 5 installation failed. Terminal executable not found."
49
- exit 1
50
- }
51
- Write-Host "MetaTrader 5 found at: $mtPath"
52
-
53
- # List installation directory contents for debugging
54
- Write-Host "Listing MetaTrader 5 installation directory:"
55
- Get-ChildItem "C:\Program Files\MetaTrader 5"
56
-
57
- # Start MT5 terminal without UI and give it time to initialize
58
- # Use /portable mode to avoid login requirements
59
- $process = Start-Process -FilePath $mtPath -ArgumentList "/portable", "/skipupdate" -PassThru -WindowStyle Hidden
60
- $pid = $process.Id
61
- Write-Host "Started MetaTrader 5 terminal with PID: $pid"
62
-
63
- # Give more time for initialization
64
- Write-Host "Waiting 60 seconds for MetaTrader 5 to initialize..."
65
- Start-Sleep -Seconds 60
66
-
67
- # Verify MT5 process is still running
68
- try {
69
- $runningProcess = Get-Process -Id $pid -ErrorAction Stop
70
- Write-Host "MetaTrader 5 terminal is still running with PID: $pid"
71
- } catch {
72
- Write-Error "MetaTrader 5 terminal is no longer running. It may have crashed."
73
- exit 1
74
- }
75
-
76
20
- name : Install Python dependencies
77
21
run : |
78
22
python -m pip install --upgrade pip
79
23
pip install MetaTrader5
80
24
81
- - name : Debug MetaTrader environment
82
- run : |
83
- # Check running processes
84
- Write-Host "Checking for MetaTrader processes:"
85
- Get-Process | Where-Object { $_.Name -like "*terminal*" -or $_.Name -like "*meta*" } | Format-Table Id, Name, Path, StartTime
86
-
87
- # Check MT5 installation directories
88
- Write-Host "Checking MetaTrader installation directories:"
89
- if (Test-Path "C:\Program Files\MetaTrader 5") {
90
- Get-ChildItem "C:\Program Files\MetaTrader 5" -Recurse | Select-Object -First 30 | Format-Table FullName
91
- }
92
-
93
- # Check for MetaQuotes directories in AppData
94
- Write-Host "Checking AppData for MetaQuotes directories:"
95
- if (Test-Path "C:\Users\runneradmin\AppData\Roaming\MetaQuotes") {
96
- Get-ChildItem "C:\Users\runneradmin\AppData\Roaming\MetaQuotes" -Recurse | Select-Object -First 30 | Format-Table FullName
97
- }
98
-
99
- - name : Test MetaTrader5 connection with retry
25
+ - name : Verify MetaTrader5 package installation
100
26
run : |
101
- # Print environment information
102
- Write-Host "Environment variables:"
103
- Get-ChildItem Env: | Format-Table -AutoSize
104
-
105
- # Create a retry script for connection
106
- $script = @"
107
- import MetaTrader5 as mt5
108
- import time
109
- import sys
110
-
111
- print(f"MetaTrader5 package version: {mt5.__version__}")
112
-
113
- # Try to connect with retries
114
- max_attempts = 5
115
- for attempt in range(max_attempts):
116
- print(f"Connection attempt {attempt+1}/{max_attempts}...")
117
-
118
- # Initialize MT5 connection
119
- if mt5.initialize():
120
- print("MetaTrader5 initialized successfully")
121
- # Get terminal info
122
- terminal_info = mt5.terminal_info()
123
- if terminal_info is not None:
124
- print(f"Terminal info: connected={terminal_info.connected}, community_account={terminal_info.community_account}")
125
- else:
126
- print("Failed to get terminal info")
127
-
128
- # Get account info
129
- account_info = mt5.account_info()
130
- if account_info is not None:
131
- print(f"Account info: server={account_info.server}, balance={account_info.balance}")
132
- else:
133
- print("Failed to get account info - this is normal without login credentials")
134
-
135
- mt5.shutdown()
136
- sys.exit(0)
137
- else:
138
- error = mt5.last_error()
139
- print(f"initialize() failed, error code = {error}")
140
- # Wait before retrying
141
- time.sleep(10)
142
-
143
- # If we got here, all attempts failed
144
- sys.exit(1)
145
- "@
146
-
147
- # Save the script to a file
148
- $script | Out-File -FilePath "retry_connection.py" -Encoding utf8
27
+ python -c "import MetaTrader5 as mt5; print(f'MetaTrader5 package version: {mt5.__version__}')"
149
28
150
- # Run the script
151
- python retry_connection.py
0 commit comments