Skip to content

Commit ac55a43

Browse files
committed
Fix the issue
1 parent 5755f9a commit ac55a43

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

test/integration/test_mt5_initialization.py

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,58 +10,40 @@ def test_mt5_initialization():
1010
print('MT5_PORTABLE_PATH:', os.environ.get('MT5_PORTABLE_PATH'))
1111
print('Initializing...')
1212

13-
# Try initialization using portable path and headless mode
14-
portable_path = os.environ.get('MT5_PORTABLE_PATH')
15-
if portable_path:
16-
mt5_path = os.path.join(portable_path, 'terminal64.exe')
17-
else:
18-
mt5_path = None
19-
20-
print('Starting MT5 initialization...')
21-
2213
# Set environment variable directly in Python to ensure it's available
2314
os.environ['MT5_HEADLESS'] = '1'
2415

2516
result = mt5.initialize()
2617
print(f'Initial result: {result}, Error code: {mt5.last_error()}')
2718

2819
# If the initial attempt fails, try additional methods
29-
if not result and mt5_path:
30-
print('Initial attempt failed. Trying with portable path...')
20+
if not result:
21+
print('Initial attempt failed. Trying with standard path...')
22+
23+
# Attempt 2: initialize with standard path
3124
result = mt5.initialize(
32-
path="C:\\Program Files\\MetaTrader 5\\terminal64.exe,
25+
path="C:\\Program Files\\MetaTrader 5\\terminal64.exe",
3326
login=0,
34-
password='',
35-
server='',
27+
password="",
28+
server="",
3629
timeout=60000
3730
)
3831

39-
print(f'Result with portable path: {result}, Error code: {mt5.last_error()}')
32+
print(f'Result with standard path: {result}, Error code: {mt5.last_error()}')
4033

4134
# If first attempt fails, try alternative approach
4235
if not result:
43-
print('First attempt failed. Trying default initialization...')
36+
print('Second attempt failed. Trying with increased timeout...')
4437
mt5.shutdown()
4538
time.sleep(2)
4639

47-
# Attempt 2: default init with timeout
48-
result = mt5.initialize(timeout=60000)
49-
print(f'Result with default init: {result}, Error code: {mt5.last_error()}')
50-
51-
# Attempt 3: standard path
52-
if not result:
53-
print('Second attempt failed. Trying with standard path...')
54-
mt5.shutdown()
55-
time.sleep(2)
56-
result = mt5.initialize(
57-
path='C:\\Program Files\\MetaTrader 5\\terminal64.exe',
58-
timeout=60000
59-
)
60-
print(f'Result with standard path: {result}, Error code: {mt5.last_error()}')
40+
# Attempt 3: default init with longer timeout
41+
result = mt5.initialize(timeout=120000)
42+
print(f'Result with increased timeout: {result}, Error code: {mt5.last_error()}')
6143

62-
if not result:
63-
print('All initialization attempts failed')
64-
return False
44+
if not result:
45+
print('All initialization attempts failed')
46+
return False
6547

6648
# Check if initialization was successful
6749
if result:

0 commit comments

Comments
 (0)