Skip to content

Commit 8b6f883

Browse files
committed
another way to try
1 parent a6b4403 commit 8b6f883

File tree

2 files changed

+69
-118
lines changed

2 files changed

+69
-118
lines changed

.github/workflows/test-metatrader5-integration.yml

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
build:
77
strategy:
88
matrix:
9-
os: [windows-latest, windows-2025]
9+
os: [windows-latest]
1010
runs-on: ${{ matrix.os }}
1111
steps:
1212
- name: Checkout repository
@@ -19,51 +19,65 @@ jobs:
1919

2020
- name: Download MetaTrader5 Installer
2121
run: |
22-
Invoke-WebRequest `
23-
-Uri "https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mt5setup.exe" `
24-
-OutFile "mt5setup.exe"
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
2525
shell: pwsh
2626

2727
- name: Install MetaTrader5
2828
run: |
29-
$process = Start-Process -FilePath ".\mt5setup.exe" -ArgumentList "/auto", "/portable" -PassThru
30-
$process.WaitForExit(300000) # Wait for up to 5 minutes
31-
if (-not $process.HasExited) {
32-
Write-Host "MT5 installer stuck, killing..."
33-
Stop-Process -Id $process.Id -Force
29+
$installArgs = @(
30+
"/S",
31+
"/portable=$env:GITHUB_WORKSPACE\MT5Portable",
32+
"/skipupdate"
33+
)
34+
Start-Process "$env:GITHUB_WORKSPACE\mt5setup.exe" -ArgumentList $installArgs -Wait -NoNewWindow
35+
if (-not (Test-Path "$env:GITHUB_WORKSPACE\MT5Portable\terminal64.exe")) {
36+
Write-Error "Installation failed - terminal.exe not found"
3437
exit 1
3538
}
3639
shell: pwsh
3740

38-
- name: Kill any existing MT5 processes
41+
- name: Launch MetaTrader5
3942
run: |
40-
Get-Process terminal64 -ErrorAction SilentlyContinue | Stop-Process -Force
41-
shell: pwsh
43+
$mt5Path = "$env:GITHUB_WORKSPACE\MT5Portable\terminal64.exe"
44+
$configPath = "$env:GITHUB_WORKSPACE\MT5Portable\config"
45+
46+
# Create basic configuration
47+
New-Item -Path $configPath -ItemType Directory -Force
48+
Set-Content -Path "$configPath\servers.dat" -Value "YourServerHere,Demo,ServerAddressHere,443"
4249
43-
- name: Launch MetaTrader5 Terminal in portable mode
44-
run: |
45-
$mt5Paths = @(
46-
"C:\Program Files\MetaTrader 5\terminal64.exe",
47-
".\MetaTrader 5\terminal64.exe",
48-
".\MetaTrader5\terminal64.exe"
49-
)
50-
foreach ($path in $mt5Paths) {
51-
if (Test-Path $path) {
52-
Start-Process -FilePath $path -ArgumentList "/portable" -WindowStyle Hidden
53-
Write-Host "Launched MT5 from $path"
54-
break
55-
}
50+
# Launch with headless options
51+
$process = Start-Process $mt5Path -ArgumentList @(
52+
"/portable",
53+
"/headless",
54+
"/config:$configPath",
55+
"/login:12345 /password:demo /server:ServerAddressHere"
56+
) -PassThru
57+
58+
# Wait and verify process
59+
Start-Sleep -Seconds 60
60+
if ($process.HasExited -or -not (Get-Process terminal64 -ErrorAction SilentlyContinue)) {
61+
Write-Error "Failed to launch MT5"
62+
Get-Content "$env:GITHUB_WORKSPACE\MT5Portable\logs\*.log" | Write-Host
63+
exit 1
5664
}
57-
Start-Sleep -Seconds 30 # Increase wait time for MT5 to fully launch
5865
shell: pwsh
5966

60-
- name: Check MT5 process running
67+
- name: Run MT5 Test
6168
run: |
62-
Get-Process terminal64 -ErrorAction Stop
63-
shell: pwsh
64-
65-
- name: Install MetaTrader5 Python package
66-
run: pip install MetaTrader5
67-
68-
- name: Run MT5 test script
69-
run: python tests/integration/test_mt5_connection.py
69+
python -c "import os, MetaTrader5 as mt5
70+
print('Python version:', os.sys.version)
71+
for i in range(10):
72+
try:
73+
if mt5.initialize():
74+
print('MT5 initialized successfully')
75+
print(mt5.terminal_info())
76+
mt5.shutdown()
77+
exit(0)
78+
print(f'Attempt {i+1} failed')
79+
except Exception as e:
80+
print(f'Error: {str(e)}')
81+
import time; time.sleep(10)
82+
print('All attempts failed')
83+
exit(1)"
Lines changed: 20 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,20 @@
1-
name: Test | MetaTrader5 Integration Test
2-
3-
on: [push]
4-
5-
jobs:
6-
build:
7-
strategy:
8-
matrix:
9-
os: [windows-latest]
10-
runs-on: ${{ matrix.os }}
11-
steps:
12-
- name: Checkout repository
13-
uses: actions/checkout@v4
14-
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
25-
shell: pwsh
26-
27-
- name: Install MetaTrader5
28-
run: |
29-
$installArgs = @(
30-
"/S",
31-
"/portable=$env:GITHUB_WORKSPACE\MT5Portable",
32-
"/skipupdate"
33-
)
34-
Start-Process "$env:GITHUB_WORKSPACE\mt5setup.exe" -ArgumentList $installArgs -Wait -NoNewWindow
35-
if (-not (Test-Path "$env:GITHUB_WORKSPACE\MT5Portable\terminal64.exe")) {
36-
Write-Error "Installation failed - terminal.exe not found"
37-
exit 1
38-
}
39-
shell: pwsh
40-
41-
- name: Launch MetaTrader5
42-
run: |
43-
$mt5Path = "$env:GITHUB_WORKSPACE\MT5Portable\terminal64.exe"
44-
$configPath = "$env:GITHUB_WORKSPACE\MT5Portable\config"
45-
46-
# Create basic configuration
47-
New-Item -Path $configPath -ItemType Directory -Force
48-
Set-Content -Path "$configPath\servers.dat" -Value "YourServerHere,Demo,ServerAddressHere,443"
49-
50-
# Launch with headless options
51-
$process = Start-Process $mt5Path -ArgumentList @(
52-
"/portable",
53-
"/headless",
54-
"/config:$configPath",
55-
"/login:12345 /password:demo /server:ServerAddressHere"
56-
) -PassThru
57-
58-
# Wait and verify process
59-
Start-Sleep -Seconds 60
60-
if ($process.HasExited -or -not (Get-Process terminal64 -ErrorAction SilentlyContinue)) {
61-
Write-Error "Failed to launch MT5"
62-
Get-Content "$env:GITHUB_WORKSPACE\MT5Portable\logs\*.log" | Write-Host
63-
exit 1
64-
}
65-
shell: pwsh
66-
67-
- name: Run MT5 Test
68-
run: |
69-
python -c "import os, MetaTrader5 as mt5
70-
print('Python version:', os.sys.version)
71-
for i in range(10):
72-
try:
73-
if mt5.initialize():
74-
print('MT5 initialized successfully')
75-
print(mt5.terminal_info())
76-
mt5.shutdown()
77-
exit(0)
78-
print(f'Attempt {i+1} failed')
79-
except Exception as e:
80-
print(f'Error: {str(e)}')
81-
import time; time.sleep(10)
82-
print('All attempts failed')
83-
exit(1)"
1+
import MetaTrader5 as mt5
2+
import time
3+
import sys
4+
5+
print('Testing MT5 initialization...')
6+
7+
success = False
8+
for attempt in range(12):
9+
if mt5.initialize():
10+
print('MT5 initialized successfully')
11+
mt5.shutdown()
12+
success = True
13+
break
14+
else:
15+
print(f'Attempt {attempt+1}: Not ready yet, sleeping...')
16+
time.sleep(5)
17+
18+
if not success:
19+
print('Failed to initialize MT5 after waiting.')
20+
sys.exit(1)

0 commit comments

Comments
 (0)