Skip to content

Commit a6b4403

Browse files
committed
another way to try
1 parent 077ae29 commit a6b4403

File tree

1 file changed

+83
-20
lines changed

1 file changed

+83
-20
lines changed
Lines changed: 83 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,83 @@
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)
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)"

0 commit comments

Comments
 (0)