mtcli 3.4.0.dev0__tar.gz → 3.4.0.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/PKG-INFO +1 -1
- mtcli-3.4.0.dev1/mtcli/mt5_context.py +62 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/pyproject.toml +1 -1
- mtcli-3.4.0.dev0/mtcli/mt5_context.py +0 -36
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/LICENSE +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/README.md +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/commands/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/commands/bars.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/commands/conf.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/commands/logs.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/conecta.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/conf.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/data/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/data/base.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/data/csv.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/data/mt5.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/logger.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/models/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/models/bar_model.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/models/bars_model.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/models/chart_model.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/models/conf_model.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/models/consecutive_bars_model.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/models/rates_model.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/models/signals_model.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/models/unconsecutive_bar_model.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/mt.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugin.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/media_movel/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/media_movel/command.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/media_movel/conf.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/media_movel/models/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/media_movel/models/model_media_movel.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/media_movel/tests/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/media_movel/tests/test_mm.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/media_movel/tests/test_model_media_movel.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/range_medio/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/range_medio/command.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/range_medio/conf.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/range_medio/models/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/range_medio/models/average_range_model.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/range_medio/tests/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/range_medio/tests/test_rm.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/volume_medio/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/volume_medio/command.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/volume_medio/conf.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/volume_medio/models/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/volume_medio/models/model_average_volume.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/volume_medio/tests/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/volume_medio/tests/test_vm.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/__init__.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/close_view.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/full_view.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/high_view.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/low_view.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/min_view.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/open_view.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/ranges_view.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/rates_view.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/vars_view.py +0 -0
- {mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/views/volumes_view.py +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Gerencia o ciclo de conexão com o MetaTrader 5.
|
|
3
|
+
Fornece o contexto 'mt5_conexao' para uso seguro em blocos with.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from contextlib import contextmanager
|
|
7
|
+
import MetaTrader5 as mt5
|
|
8
|
+
from mtcli.logger import setup_logger
|
|
9
|
+
|
|
10
|
+
log = setup_logger()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@contextmanager
|
|
14
|
+
def mt5_conexao(login: int | None = None, password: str | None = None, server: str | None = None):
|
|
15
|
+
"""
|
|
16
|
+
Context manager para conexão direta com o MetaTrader 5.
|
|
17
|
+
|
|
18
|
+
Parâmetros opcionais:
|
|
19
|
+
- login (int): número da conta MT5.
|
|
20
|
+
- password (str): senha da conta.
|
|
21
|
+
- server (str): nome do servidor.
|
|
22
|
+
|
|
23
|
+
Uso:
|
|
24
|
+
>>> with mt5_conexao(login=123456, password="senha", server="ClearInvestimentos-Real"):
|
|
25
|
+
... info = mt5.account_info()
|
|
26
|
+
... print(info)
|
|
27
|
+
|
|
28
|
+
Comportamento:
|
|
29
|
+
- Se as credenciais forem fornecidas, tenta autenticar a conta.
|
|
30
|
+
- Caso contrário, conecta-se à sessão já ativa do terminal MT5.
|
|
31
|
+
- Garante encerramento seguro da conexão.
|
|
32
|
+
"""
|
|
33
|
+
try:
|
|
34
|
+
log.info("Inicializando conexão com MetaTrader 5 via API oficial...")
|
|
35
|
+
|
|
36
|
+
if login and password and server:
|
|
37
|
+
if not mt5.initialize(login=login, password=password, server=server):
|
|
38
|
+
error = mt5.last_error()
|
|
39
|
+
log.error(f"Falha ao conectar ao MetaTrader 5: {error}")
|
|
40
|
+
raise RuntimeError(f"Erro ao conectar ao MT5: {error}")
|
|
41
|
+
else:
|
|
42
|
+
log.info(f"Conectado à conta MT5 {login} ({server}).")
|
|
43
|
+
else:
|
|
44
|
+
if not mt5.initialize():
|
|
45
|
+
error = mt5.last_error()
|
|
46
|
+
log.error(f"Falha ao inicializar MetaTrader 5: {error}")
|
|
47
|
+
raise RuntimeError(f"Erro ao conectar ao MT5: {error}")
|
|
48
|
+
else:
|
|
49
|
+
log.info("Conectado à sessão ativa do MetaTrader 5.")
|
|
50
|
+
|
|
51
|
+
yield
|
|
52
|
+
|
|
53
|
+
except Exception as e:
|
|
54
|
+
log.error(f"Erro durante o uso da conexão MT5: {e}")
|
|
55
|
+
raise
|
|
56
|
+
|
|
57
|
+
finally:
|
|
58
|
+
try:
|
|
59
|
+
mt5.shutdown()
|
|
60
|
+
log.info("Conexão com MetaTrader 5 encerrada com sucesso.")
|
|
61
|
+
except Exception as e:
|
|
62
|
+
log.error(f"Erro ao encerrar conexão MT5: {e}")
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Gerencia o ciclo de conexão com o MetaTrader 5.
|
|
3
|
-
Fornece o contexto 'mt5_conexao' para uso seguro em blocos with.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from contextlib import contextmanager
|
|
7
|
-
import MetaTrader5 as mt5
|
|
8
|
-
from mtcli.logger import setup_logger
|
|
9
|
-
|
|
10
|
-
log = setup_logger()
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@contextmanager
|
|
14
|
-
def mt5_conexao():
|
|
15
|
-
"""
|
|
16
|
-
Context manager para conexão direta com o MetaTrader 5.
|
|
17
|
-
- Chama `mt5.initialize()` ao entrar no contexto.
|
|
18
|
-
- Chama `mt5.shutdown()` ao sair.
|
|
19
|
-
- Loga falhas e garante fechamento seguro.
|
|
20
|
-
"""
|
|
21
|
-
try:
|
|
22
|
-
log.info("Inicializando conexão com MetaTrader 5 via API oficial...")
|
|
23
|
-
if not mt5.initialize():
|
|
24
|
-
error = mt5.last_error()
|
|
25
|
-
log.error(f"Falha ao inicializar MetaTrader 5: {error}")
|
|
26
|
-
raise RuntimeError(f"Erro ao conectar ao MT5: {error}")
|
|
27
|
-
yield
|
|
28
|
-
except Exception as e:
|
|
29
|
-
log.error(f"Erro durante o uso da conexão MT5: {e}")
|
|
30
|
-
raise
|
|
31
|
-
finally:
|
|
32
|
-
try:
|
|
33
|
-
mt5.shutdown()
|
|
34
|
-
log.info("Conexão com MetaTrader 5 encerrada com sucesso.")
|
|
35
|
-
except Exception as e:
|
|
36
|
-
log.error(f"Erro ao encerrar conexão MT5: {e}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/media_movel/tests/test_model_media_movel.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/range_medio/models/average_range_model.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mtcli-3.4.0.dev0 → mtcli-3.4.0.dev1}/mtcli/plugins/volume_medio/models/model_average_volume.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|