@@ -77,41 +77,53 @@ jobs:
77
77
portable_path = os.environ.get('MT5_PORTABLE_PATH')
78
78
mt5_path = os.path.join(portable_path, 'terminal64.exe')
79
79
80
- # First attempt: using portable path
81
- result = mt5.initialize(
82
- path=mt5_path,
83
- login=0,
84
- password='',
85
- server='',
86
- timeout=60000
87
- )
80
+ print('Starting MT5 initialization...')
88
81
89
- print(f'Result with portable path: {result}, Error code: {mt5.last_error()}')
82
+ # Set environment variable directly in Python
83
+ os.environ['MT5_HEADLESS'] = '1'
90
84
91
- # If first attempt fails, try alternative approach
85
+ # Initialize with minimal parameters
86
+ result = mt5.initialize()
87
+
88
+ print(f'Initial result: {result}, Error code: {mt5.last_error()}')
89
+
90
+ # If the initial attempt fails, try additional methods
92
91
if not result:
93
- print('First attempt failed. Trying default initialization...')
94
- mt5.shutdown()
95
- time.sleep(2)
96
-
97
- # Second attempt: default init
98
- result = mt5.initialize(timeout=60000)
99
- print(f'Result with default init: {result}, Error code: {mt5.last_error()}')
100
-
101
- # Third attempt: standard path
92
+ print('Initial attempt failed. Trying with portable path...')
93
+ result = mt5.initialize(
94
+ path=mt5_path,
95
+ login=0,
96
+ password='',
97
+ server='',
98
+ timeout=60000
99
+ )
100
+
101
+ print(f'Result with portable path: {result}, Error code: {mt5.last_error()}')
102
+
103
+ # If first attempt fails, try alternative approach
102
104
if not result:
103
- print('Second attempt failed. Trying with standard path ...')
105
+ print('First attempt failed. Trying default initialization ...')
104
106
mt5.shutdown()
105
107
time.sleep(2)
106
- result = mt5.initialize(
107
- path='C:\\\\Program Files\\\\MetaTrader 5\\\\terminal64.exe',
108
- timeout=60000
109
- )
110
- print(f'Result with standard path: {result}, Error code: {mt5.last_error()}')
111
108
109
+ # Second attempt: default init
110
+ result = mt5.initialize(timeout=60000)
111
+ print(f'Result with default init: {result}, Error code: {mt5.last_error()}')
112
+
113
+ # Third attempt: standard path
112
114
if not result:
113
- print('All initialization attempts failed')
114
- sys.exit(1)
115
+ print('Second attempt failed. Trying with standard path...')
116
+ mt5.shutdown()
117
+ time.sleep(2)
118
+ result = mt5.initialize(
119
+ path='C:\\\\Program Files\\\\MetaTrader 5\\\\terminal64.exe',
120
+ timeout=60000
121
+ )
122
+ print(f'Result with standard path: {result}, Error code: {mt5.last_error()}')
123
+
124
+ if not result:
125
+ print('All initialization attempts failed')
126
+ sys.exit(1)
115
127
116
128
print('MT5 initialized successfully')
117
129
account_info = mt5.account_info()
0 commit comments