mtcli-risco 1.2.0__tar.gz → 2.0.0__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_risco-1.2.0 → mtcli_risco-2.0.0}/PKG-INFO +5 -1
- mtcli_risco-1.2.0/mtcli_risco/plugin.py → mtcli_risco-2.0.0/mtcli_risco/checar.py +12 -10
- {mtcli_risco-1.2.0 → mtcli_risco-2.0.0}/mtcli_risco/conf.py +1 -0
- mtcli_risco-2.0.0/mtcli_risco/monitorar.py +58 -0
- mtcli_risco-2.0.0/mtcli_risco/plugin.py +20 -0
- {mtcli_risco-1.2.0 → mtcli_risco-2.0.0}/pyproject.toml +11 -5
- {mtcli_risco-1.2.0 → mtcli_risco-2.0.0}/LICENSE +0 -0
- {mtcli_risco-1.2.0 → mtcli_risco-2.0.0}/README.md +0 -0
- {mtcli_risco-1.2.0 → mtcli_risco-2.0.0}/mtcli_risco/__init__.py +0 -0
- {mtcli_risco-1.2.0 → mtcli_risco-2.0.0}/mtcli_risco/risco.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: mtcli-risco
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: Plugin do mtcli
|
|
5
5
|
License: GPL-3.0
|
|
6
6
|
Author: Valmir França da Silva
|
|
@@ -13,6 +13,10 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.13
|
|
15
15
|
Requires-Dist: mtcli (>=1.18.1)
|
|
16
|
+
Project-URL: Documentation, https://mtcli-risco.readthedocs.io
|
|
17
|
+
Project-URL: Homepage, https://github.com/vfranca/mtcli-risco
|
|
18
|
+
Project-URL: Repository, https://github.com/vfranca/mtcli-risco
|
|
19
|
+
Project-URL: issues, https://github.com/vfranca/mtcli-risco/issues
|
|
16
20
|
Description-Content-Type: text/markdown
|
|
17
21
|
|
|
18
22
|
# mtcli-risco
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Comando
|
|
1
|
+
"""Comando checar - verifica se o loss limit foi atingido."""
|
|
2
2
|
|
|
3
3
|
import click
|
|
4
4
|
from datetime import date
|
|
@@ -18,8 +18,7 @@ from .risco import (
|
|
|
18
18
|
log = setup_logger()
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
@click.command("
|
|
22
|
-
@click.version_option(package_name="mtcli-risco")
|
|
21
|
+
@click.command("checar")
|
|
23
22
|
@click.option(
|
|
24
23
|
"--limite",
|
|
25
24
|
"-l",
|
|
@@ -32,13 +31,14 @@ log = setup_logger()
|
|
|
32
31
|
default=False,
|
|
33
32
|
help="Exibe o lucro total do dia atualizado e sai.",
|
|
34
33
|
)
|
|
35
|
-
def
|
|
36
|
-
"""
|
|
34
|
+
def checar(limite, lucro):
|
|
35
|
+
"""Verifica e bloqueia ordens se o limite de prejuízo for atingido."""
|
|
37
36
|
conectar()
|
|
38
37
|
|
|
39
38
|
if lucro:
|
|
40
39
|
lucro = calcular_lucro_total_dia()
|
|
41
40
|
click.echo(f"Lucro total do dia: {lucro:.2f}")
|
|
41
|
+
log.info(f"Lucro total do dia: {lucro:.2f}")
|
|
42
42
|
shutdown()
|
|
43
43
|
return
|
|
44
44
|
|
|
@@ -47,25 +47,27 @@ def cli(limite, lucro):
|
|
|
47
47
|
|
|
48
48
|
if estado["data"] != hoje.isoformat():
|
|
49
49
|
estado["bloqueado"] = False
|
|
50
|
-
salvar_estado(STATUS_FILE, hoje, False)
|
|
51
50
|
|
|
52
51
|
if estado["bloqueado"]:
|
|
53
|
-
click.echo("
|
|
52
|
+
click.echo("Bloqueado hoje por risco. Nenhuma ordem deve ser enviada.")
|
|
54
53
|
shutdown()
|
|
55
54
|
return
|
|
56
55
|
|
|
57
56
|
if risco_excedido(limite):
|
|
58
57
|
click.echo(
|
|
59
|
-
f"
|
|
58
|
+
f"Limite {limite:.2f} excedido. Encerrando posições e bloqueando novas ordens."
|
|
60
59
|
)
|
|
60
|
+
log.info(f"Risco {limite:.2f} excedido, iniciando encerramento de posições.")
|
|
61
61
|
encerrar_todas_posicoes()
|
|
62
62
|
cancelar_todas_ordens()
|
|
63
|
-
|
|
63
|
+
estado["bloqueado"] = True
|
|
64
64
|
else:
|
|
65
65
|
click.echo("Dentro do limite de risco.")
|
|
66
|
+
log.info(f"Risco dentro do limite {limite:.2f}")
|
|
66
67
|
|
|
68
|
+
salvar_estado(STATUS_FILE, hoje, estado["bloqueado"])
|
|
67
69
|
shutdown()
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
if __name__ == "__main__":
|
|
71
|
-
|
|
73
|
+
checar()
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Comando monitorar - monitora o prejuízo do dia."""
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
import click
|
|
5
|
+
from datetime import date
|
|
6
|
+
from mtcli.conecta import conectar, shutdown
|
|
7
|
+
from mtcli.logger import setup_logger
|
|
8
|
+
from .conf import LOSS_LIMIT, STATUS_FILE, INTERVALO
|
|
9
|
+
from .risco import (
|
|
10
|
+
carregar_estado,
|
|
11
|
+
salvar_estado,
|
|
12
|
+
risco_excedido,
|
|
13
|
+
encerrar_todas_posicoes,
|
|
14
|
+
cancelar_todas_ordens,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
log = setup_logger()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@click.command("monitorar")
|
|
21
|
+
@click.option("--limite", "-l", default=LOSS_LIMIT, help="Limite de perda diária.")
|
|
22
|
+
@click.option(
|
|
23
|
+
"--intervalo", "-i", default=INTERVALO, help="Intervalo entre verificações (segundos) default 60."
|
|
24
|
+
)
|
|
25
|
+
def monitorar(limite, intervalo):
|
|
26
|
+
"""Monitora continuamente o risco em tempo real."""
|
|
27
|
+
conectar()
|
|
28
|
+
click.echo(f"Monitorando risco a cada {intervalo}s. Limite: {limite}")
|
|
29
|
+
try:
|
|
30
|
+
while True:
|
|
31
|
+
hoje = date.today()
|
|
32
|
+
estado = carregar_estado(STATUS_FILE)
|
|
33
|
+
|
|
34
|
+
if estado.get("data") != hoje.isoformat():
|
|
35
|
+
estado["bloqueado"] = False
|
|
36
|
+
salvar_estado(STATUS_FILE, hoje, False)
|
|
37
|
+
|
|
38
|
+
if not estado.get("bloqueado") and risco_excedido(limite):
|
|
39
|
+
click.echo("Limite {limite} excedido. Encerrando posições.")
|
|
40
|
+
encerrar_todas_posicoes()
|
|
41
|
+
cancelar_todas_ordens()
|
|
42
|
+
salvar_estado(STATUS_FILE, hoje, True)
|
|
43
|
+
elif estado.get("bloqueado"):
|
|
44
|
+
click.echo(f"O limite {limite} foi excedido")
|
|
45
|
+
shutdown()
|
|
46
|
+
return
|
|
47
|
+
else:
|
|
48
|
+
click.echo(f"Dentro do limite {limite}")
|
|
49
|
+
|
|
50
|
+
time.sleep(intervalo)
|
|
51
|
+
except KeyboardInterrupt:
|
|
52
|
+
click.echo("Monitoramento interrompido.")
|
|
53
|
+
finally:
|
|
54
|
+
shutdown()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
monitorar()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Comando risco adiciona risco ao mtcli."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
from .checar import checar
|
|
5
|
+
from .monitorar import monitorar
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@click.group("risco")
|
|
9
|
+
@click.version_option(package_name="mtcli-risco")
|
|
10
|
+
def cli():
|
|
11
|
+
"""Monitora e bloqueia ordens se o limite de prejuízo for atingido."""
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
cli.add_command(checar)
|
|
16
|
+
cli.add_command(monitorar)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
cli()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "mtcli-risco"
|
|
3
|
-
version = "
|
|
3
|
+
version = "2.0.0"
|
|
4
4
|
description = "Plugin do mtcli"
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "Valmir França da Silva",email = "vfranca3@gmail.com"}
|
|
@@ -12,8 +12,14 @@ dependencies = [
|
|
|
12
12
|
"mtcli>=1.18.1"
|
|
13
13
|
]
|
|
14
14
|
|
|
15
|
+
[project.urls]
|
|
16
|
+
homepage = "https://github.com/vfranca/mtcli-risco"
|
|
17
|
+
documentation = "https://mtcli-risco.readthedocs.io"
|
|
18
|
+
repository = "https://github.com/vfranca/mtcli-risco"
|
|
19
|
+
issues = "https://github.com/vfranca/mtcli-risco/issues"
|
|
20
|
+
|
|
15
21
|
[project.entry-points."mtcli.plugins"]
|
|
16
|
-
|
|
22
|
+
risco = "mtcli_risco.plugin:cli"
|
|
17
23
|
|
|
18
24
|
[build-system]
|
|
19
25
|
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
@@ -24,8 +30,8 @@ black = "^25.1.0"
|
|
|
24
30
|
pytest = "^8.4.1"
|
|
25
31
|
pytest-cov = "^7.0.0"
|
|
26
32
|
|
|
27
|
-
|
|
28
33
|
[tool.poetry.group.docs.dependencies]
|
|
29
34
|
mkdocs = "^1.6.1"
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
mkdocs-material = "^9.5.15"
|
|
36
|
+
mkdocs-material-extensions = "^1.3"
|
|
37
|
+
pymdown-extensions = "^10.7"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|