Skip to content

Commit 47f429d

Browse files
committed
try integration test
1 parent ab8680e commit 47f429d

File tree

1 file changed

+54
-31
lines changed

1 file changed

+54
-31
lines changed

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

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,44 +40,67 @@ jobs:
4040
python -m pip install --upgrade pip
4141
pip install MetaTrader5
4242
43-
- name: Setup virtual display
43+
- name: Install Xvfb (Virtual Display)
4444
run: |
45-
# Install Chocolatey if not already installed
46-
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
47-
Set-ExecutionPolicy Bypass -Scope Process -Force
48-
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
49-
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
50-
}
51-
52-
# Install VcXsrv Windows X Server
53-
choco install vcxsrv -y
54-
55-
# Start VcXsrv in background
56-
Start-Process "C:\Program Files\VcXsrv\vcxsrv.exe" -ArgumentList "-multiwindow", "-ac", "-terminate", "-lesspointer", "-wgl", "-dpi auto"
45+
choco install -y xvfb
5746
58-
# Set DISPLAY environment variable
59-
[Environment]::SetEnvironmentVariable("DISPLAY", "127.0.0.1:0.0", "Process")
47+
- name: Start MT5 with Virtual Display
48+
run: |
49+
# Set display variable to use virtual display
50+
$env:DISPLAY = ":1"
6051
61-
Write-Host "Virtual display configured with DISPLAY=127.0.0.1:0.0"
52+
# Start Xvfb
53+
Start-Process -FilePath "C:\ProgramData\chocolatey\bin\xvfb.exe" -ArgumentList "-ac :1 -screen 0 1280x1024x24" -PassThru
6254
Start-Sleep -Seconds 5
63-
64-
- name: Run MT5 terminal with desktop parameter
65-
run: |
66-
# Kill any existing MT5 instances
67-
taskkill /F /IM terminal64.exe 2>$null
68-
Start-Sleep -Seconds 3
6955
70-
# Start MT5 with the /portable parameter
56+
# Start MT5 with virtual display
7157
$process = Start-Process -FilePath "C:\Program Files\MetaTrader 5\terminal64.exe" -ArgumentList "/portable" -PassThru
7258
$processId = $process.Id
7359
Write-Host "Started MetaTrader 5 terminal with PID $processId using virtual display"
74-
Start-Sleep -Seconds 30
60+
Start-Sleep -Seconds 45 # Give more time to initialize
7561
7662
- name: Test MT5 initialization
77-
run: >
78-
python -c "import sys, MetaTrader5 as mt5;
79-
print(f'MT5 version: {mt5.__version__}');
80-
print('Initializing...');
81-
result = mt5.initialize(path='C:\\\\Program Files\\\\MetaTrader 5\\\\terminal64.exe', timeout=60000);
82-
print(f'Result: {result}, Error: {mt5.last_error()}');
83-
sys.exit(0)"
63+
run: |
64+
# Set display variable to use virtual display
65+
$env:DISPLAY = ":1"
66+
67+
python -c "
68+
import sys, os, time
69+
import MetaTrader5 as mt5
70+
71+
print(f'MT5 version: {mt5.__version__}')
72+
print('Display environment:', os.environ.get('DISPLAY'))
73+
print('Initializing...')
74+
75+
# Try initialization with increased timeout
76+
result = mt5.initialize(
77+
path='C:\\Program Files\\MetaTrader 5\\terminal64.exe',
78+
login=0,
79+
password='',
80+
server='',
81+
timeout=120000
82+
)
83+
84+
print(f'Result: {result}, Error code: {mt5.last_error()}')
85+
86+
if not result:
87+
error_code = mt5.last_error()
88+
error_messages = {
89+
10001: 'Connection error',
90+
10002: 'Reconnection error',
91+
10003: 'Connection timeout',
92+
10004: 'Internal error',
93+
10005: 'Invalid version',
94+
10006: 'Invalid account',
95+
10007: 'Unsupported trading mode',
96+
10008: 'No connection'
97+
}
98+
error_desc = error_messages.get(error_code, 'Unknown error')
99+
print(f'Detailed error: {error_desc}')
100+
sys.exit(1)
101+
else:
102+
print('MT5 initialized successfully')
103+
print(f'Terminal info: {mt5.terminal_info()}')
104+
mt5.shutdown()
105+
sys.exit(0)
106+
"

0 commit comments

Comments
 (0)