Repository navigation
Expand file tree
/
Copy pathinterfaz_pro.py
More file actions
343 lines (293 loc) · 15.7 KB
/
Copy pathinterfaz_pro.py
File metadata and controls
343 lines (293 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# interfaz_pro.py
# Interfaz gráfica del IQ Option Pro Bot v3.0
# Tema: Deep Charcoal Glass - Platinum Edition
# Características nuevas:
# * Tarjeta de análisis multi-timeframe
# * Visualización de patrones detectados
# * Indicador de fuerza del consenso
# * Estado de la memoria (operaciones guardadas)
# * Pestaña de estrategias activas
# * Botón para mostrar conocimiento del bot
import customtkinter as ctk
import config
ctk.set_appearance_mode("Dark")
ctk.set_default_color_theme("dark-blue")
class InterfazPro(ctk.CTk):
"""Interfaz principal del bot con tema Deep Charcoal Glass Platinum."""
def __init__(self, controlador=None):
super().__init__()
self.controlador = controlador
self.title(config.TITULO_VENTANA)
self.geometry(config.DIMENSIONES_VENTANA)
self.configure(fg_color=config.COLOR_FONDO_PRINCIPAL)
# Estado interno de la GUI
self._ultimo_mensaje_consola = ""
self._max_lineas_consola = 500
# Configurar grid principal
self.grid_columnconfigure(0, weight=1, minsize=300)
self.grid_columnconfigure(1, weight=5)
self.grid_rowconfigure(0, weight=1)
self._crear_panel_izquierdo()
self._crear_panel_derecho()
# ====================================================================
# PANEL IZQUIERDO: Configuración
# ====================================================================
def _crear_panel_izquierdo(self):
panel = ctk.CTkFrame(self, fg_color=config.COLOR_PANEL_OSCURO, corner_radius=12)
panel.grid(row=0, column=0, padx=12, pady=12, sticky="nsew")
# --- CONEXIÓN ---
ctk.CTkLabel(panel, text="🔌 Conexión de Bróker", font=("Roboto", 16, "bold"),
text_color="#ffffff").pack(anchor="w", padx=15, pady=(15, 10))
self.txt_email = ctk.CTkEntry(panel, placeholder_text="Correo electrónico",
fg_color="#242830", border_color="#343b47")
self.txt_email.pack(fill="x", padx=15, pady=5)
# NOTA: no se rellena email por defecto. Cargar desde variables de entorno.
self.txt_password = ctk.CTkEntry(panel, placeholder_text="Contraseña", show="*",
fg_color="#242830", border_color="#343b47")
self.txt_password.pack(fill="x", padx=15, pady=5)
ctk.CTkLabel(panel, text="Modo de Cuenta:", font=("Roboto", 11),
text_color=config.COLOR_TEXTO_MUTED).pack(anchor="w", padx=15, pady=(8, 2))
self.combo_cuenta = ctk.CTkOptionMenu(
panel, values=["Demo (Practice)", "Real"],
fg_color="#242830", button_color="#343b47",
)
self.combo_cuenta.pack(fill="x", padx=15, pady=2)
ctk.CTkLabel(panel, text="Tipo de Instrumento:", font=("Roboto", 11),
text_color=config.COLOR_TEXTO_MUTED).pack(anchor="w", padx=15, pady=(8, 2))
self.combo_instrumento = ctk.CTkOptionMenu(
panel, values=["Binarias", "Digitales"],
fg_color="#242830", button_color="#343b47",
)
self.combo_instrumento.pack(fill="x", padx=15, pady=2)
self.btn_conectar = ctk.CTkButton(
panel, text="🚀 Iniciar Bot",
fg_color=config.COLOR_VERDE_BOTON, hover_color="#059669",
font=("Roboto", 13, "bold"), command=self.al_clic_conectar,
)
self.btn_conectar.pack(fill="x", padx=15, pady=(15, 10))
ctk.CTkFrame(panel, height=2, fg_color=config.COLOR_BORDE).pack(fill="x", padx=15, pady=10)
# --- SELECCIÓN DE ACTIVO ---
ctk.CTkLabel(panel, text="💱 Selección de Activo", font=("Roboto", 16, "bold"),
text_color="#ffffff").pack(anchor="w", padx=15, pady=(5, 10))
self.combo_activo = ctk.CTkOptionMenu(
panel, values=config.ACTIVOS_DISPONIBLES,
fg_color="#242830", button_color="#343b47",
)
self.combo_activo.pack(fill="x", padx=15, pady=5)
ctk.CTkLabel(panel, text="Mercado:", font=("Roboto", 11),
text_color=config.COLOR_TEXTO_MUTED).pack(anchor="w", padx=15, pady=(8, 2))
self.combo_mercado = ctk.CTkOptionMenu(
panel, values=["Mercado Real", "Mercado OTC"],
fg_color="#242830", button_color="#343b47",
)
self.combo_mercado.pack(fill="x", padx=15, pady=2)
ctk.CTkLabel(panel, text="Timeframe:", font=("Roboto", 11),
text_color=config.COLOR_TEXTO_MUTED).pack(anchor="w", padx=15, pady=(8, 2))
self.combo_timeframe = ctk.CTkOptionMenu(
panel, values=["60s (1M)", "120s (2M)", "300s (5M)", "900s (15M)"],
fg_color="#242830", button_color="#343b47",
)
self.combo_timeframe.pack(fill="x", padx=15, pady=2)
self.btn_detener = ctk.CTkButton(
panel, text="🛑 Detener Bot",
fg_color=config.COLOR_ROJO_BOTON, hover_color="#dc2626",
font=("Roboto", 13, "bold"), command=self.al_clic_detener,
)
self.btn_detener.pack(fill="x", padx=15, pady=(20, 10))
ctk.CTkFrame(panel, height=2, fg_color=config.COLOR_BORDE).pack(fill="x", padx=15, pady=10)
# --- INFORMACIÓN DEL BOT ---
ctk.CTkLabel(panel, text="🧠 Cerebro del Bot", font=("Roboto", 14, "bold"),
text_color=config.COLOR_DORADO).pack(anchor="w", padx=15, pady=(5, 8))
info_text = (
"• Red Neuronal Profunda (5 capas)\n"
"• 60+ patrones de velas\n"
"• 15+ indicadores técnicos\n"
"• Multi-timeframe (1M, 2M, 5M, 15M)\n"
"• 9 estrategias simultáneas\n"
"• Memoria persistente (ganadas)\n"
"• Martingale inteligente limitado"
)
ctk.CTkLabel(panel, text=info_text, font=("Roboto", 10),
text_color=config.COLOR_TEXTO_MUTED,
justify="left", anchor="w").pack(fill="x", padx=15, pady=(0, 15))
# ====================================================================
# PANEL DERECHO: Monitores y KPIs
# ====================================================================
def _crear_panel_derecho(self):
panel_derecho = ctk.CTkFrame(self, fg_color="transparent")
panel_derecho.grid(row=0, column=1, padx=(0, 12), pady=12, sticky="nsew")
panel_derecho.grid_rowconfigure(0, weight=0) # KPIs
panel_derecho.grid_rowconfigure(1, weight=1) # Análisis
panel_derecho.grid_rowconfigure(2, weight=2) # Consola
panel_derecho.grid_columnconfigure(0, weight=1)
# 1. TARJETAS DE MÉTRICAS (KPIs)
grid_kpi = ctk.CTkFrame(panel_derecho, fg_color="transparent")
grid_kpi.grid(row=0, column=0, sticky="ew", pady=(0, 10))
for i in range(4):
grid_kpi.grid_columnconfigure(i, weight=1)
self.lbl_saldo_val = self._crear_kpi(grid_kpi, 0, "💰 SALDO", "$0.00",
config.COLOR_VERDE_NEON)
self.lbl_payout_val = self._crear_kpi(grid_kpi, 1, "📈 PAYOUT", "-- %",
config.COLOR_AZUL_IA)
self.lbl_ops_val = self._crear_kpi(grid_kpi, 2, "⚔️ OPERACIONES", "0G / 0P",
config.COLOR_DORADO)
self.lbl_ia_val = self._crear_kpi(grid_kpi, 3, "🧠 RED NEURONAL", "ESPERANDO",
config.COLOR_VIOLETA_IA)
# 2. PANEL DE ANÁLISIS
frame_analisis = ctk.CTkFrame(panel_derecho, fg_color=config.COLOR_PANEL_OSCURO, corner_radius=12)
frame_analisis.grid(row=1, column=0, sticky="nsew", pady=(0, 10))
ctk.CTkLabel(frame_analisis, text="📊 Análisis en Tiempo Real",
font=("Roboto", 12, "bold"),
text_color="#a0a5b1").pack(anchor="nw", padx=15, pady=10)
# Sub-paneles: Multi-TF y Patrones
sub_grid = ctk.CTkFrame(frame_analisis, fg_color="transparent")
sub_grid.pack(fill="x", padx=15, pady=(0, 10))
sub_grid.grid_columnconfigure(0, weight=1)
sub_grid.grid_columnconfigure(1, weight=1)
# Multi-TF
mtf = ctk.CTkFrame(sub_grid, fg_color="#0d0f12", corner_radius=8)
mtf.grid(row=0, column=0, padx=(0, 5), sticky="nsew")
ctk.CTkLabel(mtf, text="⏱ Multi-Timeframe", font=("Roboto", 11, "bold"),
text_color=config.COLOR_AZUL_IA).pack(anchor="w", padx=10, pady=(8, 4))
self.txt_mtf = ctk.CTkTextbox(mtf, fg_color="#0d0f12", text_color="#10b981",
font=("Consolas", 10), height=100)
self.txt_mtf.pack(fill="both", expand=True, padx=10, pady=(0, 8))
# Patrones
pat = ctk.CTkFrame(sub_grid, fg_color="#0d0f12", corner_radius=8)
pat.grid(row=0, column=1, padx=(5, 0), sticky="nsew")
ctk.CTkLabel(pat, text="🎯 Patrones Detectados", font=("Roboto", 11, "bold"),
text_color=config.COLOR_VIOLETA_IA).pack(anchor="w", padx=10, pady=(8, 4))
self.txt_patrones = ctk.CTkTextbox(pat, fg_color="#0d0f12", text_color="#10b981",
font=("Consolas", 10), height=100)
self.txt_patrones.pack(fill="both", expand=True, padx=10, pady=(0, 8))
# 3. CONSOLA DE LOGS
frame_consola = ctk.CTkFrame(panel_derecho, fg_color=config.COLOR_PANEL_OSCURO, corner_radius=12)
frame_consola.grid(row=2, column=0, sticky="nsew")
frame_consola.grid_rowconfigure(1, weight=1)
ctk.CTkLabel(frame_consola, text="📜 Consola del Bot",
font=("Roboto", 12, "bold"),
text_color="#a0a5b1").grid(row=0, column=0, sticky="w", padx=15, pady=10)
self.btn_limpiar_log = ctk.CTkButton(
frame_consola, text="Limpiar", width=70,
fg_color="#343b47", hover_color="#454c5a",
font=("Roboto", 10), command=self._limpiar_log,
)
self.btn_limpiar_log.grid(row=0, column=1, sticky="e", padx=15, pady=10)
self.txt_log = ctk.CTkTextbox(frame_consola, fg_color="#0a0c10", text_color="#10b981",
font=("Consolas", 10), corner_radius=8)
self.txt_log.grid(row=1, column=0, columnspan=2, sticky="nsew", padx=15, pady=(0, 15))
def _crear_kpi(self, parent, col, titulo, valor, color):
f = ctk.CTkFrame(parent, fg_color=config.COLOR_PANEL_OSCURO, corner_radius=10)
f.grid(row=0, column=col, padx=4, sticky="ew")
ctk.CTkLabel(f, text=titulo, font=("Roboto", 10, "bold"),
text_color=config.COLOR_TEXTO_MUTED).pack(pady=(8, 0))
lbl = ctk.CTkLabel(f, text=valor, font=("Roboto", 16, "bold"), text_color=color)
lbl.pack(pady=(0, 8))
return lbl
# ====================================================================
# EVENTOS DE BOTONES
# ====================================================================
def al_clic_conectar(self):
if not self.controlador:
self.escribir_log("[ERROR] El controlador no se ha vinculado correctamente.")
return
email = self.txt_email.get().strip()
password = self.txt_password.get().strip()
cuenta = self.combo_cuenta.get()
instrumento = self.combo_instrumento.get()
activo_base = self.combo_activo.get()
es_otc = "OTC" in self.combo_mercado.get()
activo_final = f"{activo_base}-OTC" if es_otc and not activo_base.endswith("-OTC") else activo_base
tf_map = {"60s (1M)": 60, "120s (2M)": 120, "300s (5M)": 300, "900s (15M)": 900}
timeframe = tf_map.get(self.combo_timeframe.get(), 60)
credenciales = {'email': email, 'password': password, 'tipo_cuenta': cuenta}
config_dict = {'activo': activo_final, 'instrumento': instrumento, 'timeframe': timeframe}
self.escribir_log(f"[INICIO] Bot v3.0 con Red Neuronal Profunda")
self.escribir_log(f"[INICIO] Conectando a IQ Option para {email} ({cuenta})...")
self.escribir_log(f"[INICIO] Activo: {activo_final} | TF: {timeframe}s | Multi-TF activado")
self.controlador.iniciar(credenciales, config_dict)
def al_clic_detener(self):
if self.controlador:
self.controlador.detener()
self.escribir_log("[SISTEMA] Solicitud de detención enviada.")
# ====================================================================
# PROCESAMIENTO DE MENSAJES
# ====================================================================
def escribir_log(self, mensaje: str):
"""
Procesa mensajes del motor e intercepta etiquetas de actualización de KPI
y de los paneles de análisis.
"""
# KPIs
if mensaje.startswith("[KPI_SALDO]"):
valor = mensaje.replace("[KPI_SALDO]", "").strip()
self.lbl_saldo_val.configure(text=valor)
return
if mensaje.startswith("[KPI_PAYOUT]"):
valor = mensaje.replace("[KPI_PAYOUT]", "").strip()
self.lbl_payout_val.configure(text=valor)
return
if mensaje.startswith("[KPI_OPS]"):
valor = mensaje.replace("[KPI_OPS]", "").strip()
self.lbl_ops_val.configure(text=valor)
return
if mensaje.startswith("[KPI_WINRATE]"):
valor = mensaje.replace("[KPI_WINRATE]", "").strip()
# Mostrar como tooltip o agregarlo a consola
pass
if mensaje.startswith("[RED NEURONAL]"):
if "->" in mensaje:
decision = mensaje.split("->")[-1].strip().split()[0]
color = ("#10b981" if "COMPRA" in decision else
"#ef4444" if "VENTA" in decision else
config.COLOR_VIOLETA_IA)
self.lbl_ia_val.configure(text=decision, text_color=color)
return
if mensaje.startswith("[PATRON ↑]"):
patron = mensaje.replace("[PATRON ↑]", "").strip()
self._agregar_patron("↑", patron)
return
if mensaje.startswith("[PATRON ↓]"):
patron = mensaje.replace("[PATRON ↓]", "").strip()
self._agregar_patron("↓", patron)
return
if mensaje.startswith("[MEMORIA]"):
# Mostrar info de memoria en el panel de patrones
self.txt_patrones.insert("end", f"{mensaje}\n")
self.txt_patrones.see("end")
return
# Mensaje normal → consola
try:
self.txt_log.configure(state="normal")
self.txt_log.insert("end", f"{mensaje}\n")
# Limitar número de líneas para evitar consumo de memoria
lineas = int(self.txt_log.index("end-1c").split(".")[0])
if lineas > self._max_lineas_consola:
self.txt_log.delete("1.0", f"{lineas - self._max_lineas_consola}.0")
self.txt_log.see("end")
self.txt_log.configure(state="disabled")
except Exception:
pass
def _agregar_patron(self, direccion, texto):
"""Agrega un patrón al panel de patrones detectados."""
color = "#10b981" if direccion == "↑" else "#ef4444"
try:
self.txt_patrones.insert("end", f"{direccion} {texto}\n")
lineas = int(self.txt_patrones.index("end-1c").split(".")[0])
if lineas > 50:
self.txt_patrones.delete("1.0", f"{lineas - 50}.0")
self.txt_patrones.see("end")
except Exception:
pass
def _limpiar_log(self):
try:
self.txt_log.configure(state="normal")
self.txt_log.delete("1.0", "end")
self.txt_log.configure(state="disabled")
except Exception:
pass
# Aliases de compatibilidad
def log(self, mensaje: str):
self.escribir_log(mensaje)
def consola(self):
return self.txt_log