1- import MetaTrader5 as mt5
2- import time
3- import sys
4- import os
1+ """Integration test for MetaTrader5 connection.
2+
3+ This module tests the ability to establish a connection with MT5 platform.
4+ """
5+
56import logging
7+ import os
8+ import time
9+
10+ import MetaTrader5 as mt5 # noqa: N813
611
712# Configure logging
813logger = logging .getLogger (__name__ )
914logger .setLevel (logging .INFO )
1015
1116
12- print ( ' Testing MT5 initialization...' )
17+ logger . info ( " Testing MT5 initialization..." )
1318
1419success = False
1520for attempt in range (10 ):
16- if mt5 .initialize (login = int (os .getenv ('MT5_LOGIN' )),
17- password = os .getenv ('MT5_PASSWORD' ),
18- server = os .getenv ('MT5_SERVER' ),
19- path = os .getenv ('MT5_PATH' )):
20- print ('MT5 initialized successfully' )
21+ if mt5 .initialize (
22+ login = os .getenv ("MT5_LOGIN" ),
23+ password = os .getenv ("MT5_PASSWORD" ),
24+ server = os .getenv ("MT5_SERVER" ),
25+ path = os .getenv ("MT5_PATH" ),
26+ ):
27+ logger .info ("MT5 initialized successfully" )
2128 mt5 .shutdown ()
2229 success = True
2330 break
2431 else :
25- print ( f' Attempt { attempt + 1 } : Not ready yet, sleeping...' )
32+ logger . info ( f" Attempt { attempt + 1 } : Not ready yet, sleeping..." )
2633 time .sleep (5 )
2734
2835if not success :
29- print ( ' Failed to initialize MT5 after waiting.' )
30- sys . exit ( 1 )
36+ logger . info ( " Failed to initialize MT5 after waiting." )
37+ mt5 . shutdown ( )
0 commit comments