Spaces:
Sleeping
Sleeping
feat: Implementar melhorias no sistema de temas e funções de análise técnica
Browse files- Adicionar funções de análise técnica (RSI, Bollinger Bands, EMA, formatação)
- Corrigir importação de AdvancedMarketProcessor no app.py
- Adicionar novas variáveis CSS (--bg, --surface) para melhor suporte a temas
- Atualizar paleta de cores do tema escuro para melhor contraste
- Atualizar documentação do sistema de temas
- Atualizar CHANGELOG.md com versão 2.2.2
- Atualizar api-reference.md com novas funções utilitárias
- CHANGELOG.md +18 -0
- __pycache__/app.cpython-313.pyc +0 -0
- app.py +1 -0
- docs/api-reference.md +59 -0
- docs/theme_system.md +18 -14
- logs/application.db +0 -0
- src/analysis/__pycache__/fibonacci_analysis.cpython-313.pyc +0 -0
- src/core/__pycache__/advanced_market_processing.cpython-313.pyc +0 -0
- src/core/__pycache__/log_parser.cpython-313.pyc +0 -0
- src/core/__pycache__/performance_monitor.cpython-313.pyc +0 -0
- src/integrations/__pycache__/__init__.cpython-313.pyc +0 -0
- src/integrations/__pycache__/real_time_integration.cpython-313.pyc +0 -0
- src/ui/__pycache__/dark_theme_components.cpython-313.pyc +0 -0
- src/ui/__pycache__/gradio_interface.cpython-313.pyc +0 -0
- src/ui/__pycache__/log_viewer.cpython-313.pyc +0 -0
- src/ui/__pycache__/theme_manager.cpython-313.pyc +0 -0
- src/ui/gradio_interface.py +7 -7
- src/ui/theme_manager.py +4 -0
- src/utils/__pycache__/utils.cpython-313.pyc +0 -0
- src/utils/utils.py +71 -0
CHANGELOG.md
CHANGED
|
@@ -5,6 +5,24 @@ Todas as mudanças notáveis neste projeto serão documentadas neste arquivo.
|
|
| 5 |
O formato é baseado em [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
| 6 |
e este projeto adere ao [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
## [2.2.1] - 2024-01-29
|
| 9 |
|
| 10 |
### 🐛 Corrigido
|
|
|
|
| 5 |
O formato é baseado em [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
| 6 |
e este projeto adere ao [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
| 7 |
|
| 8 |
+
## [2.2.2] - 2024-01-29
|
| 9 |
+
|
| 10 |
+
### 🎉 Adicionado
|
| 11 |
+
- **Funções de Análise Técnica**: Implementadas `calculate_rsi()`, `calculate_bollinger_bands()`, `calculate_ema()` e `format_number()` em utils.py
|
| 12 |
+
- **Importação AdvancedMarketProcessor**: Adicionada importação correta no app.py para resolver dependências
|
| 13 |
+
- **Variáveis CSS Adicionais**: Novas variáveis `--bg` e `--surface` para melhor compatibilidade do tema
|
| 14 |
+
|
| 15 |
+
### 🐛 Corrigido
|
| 16 |
+
- **Erros de Sintaxe**: Corrigidos parênteses ausentes e extras em utils.py
|
| 17 |
+
- **Importação ExampleData**: Substituído `AppConfig.EXAMPLE_INPUT` por `ExampleData.SAMPLE_MARKET_DATA['bullish']` em gradio_interface.py
|
| 18 |
+
- **Compatibilidade de Tema**: Melhorada aplicação de variáveis CSS para componentes HTML customizados
|
| 19 |
+
- **Dependências de Módulos**: Resolvidos erros de importação que impediam inicialização da aplicação
|
| 20 |
+
|
| 21 |
+
### 🔄 Alterado
|
| 22 |
+
- **Sistema de Temas**: Aprimoradas variáveis CSS para melhor suporte a temas dinâmicos
|
| 23 |
+
- **Formatação HTML**: Componentes agora usam variáveis CSS (`var(--bg)`, `var(--surface)`) para compatibilidade com temas
|
| 24 |
+
- **Estrutura de Código**: Melhorada organização das funções utilitárias de análise técnica
|
| 25 |
+
|
| 26 |
## [2.2.1] - 2024-01-29
|
| 27 |
|
| 28 |
### 🐛 Corrigido
|
__pycache__/app.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ
|
|
|
app.py
CHANGED
|
@@ -13,6 +13,7 @@ try:
|
|
| 13 |
from src.utils.utils import LogUtils, ValidationUtils
|
| 14 |
from src.core.log_parser import VampireBotLogParser
|
| 15 |
from src.analysis.fibonacci_analysis import AdvancedFibonacciEngine
|
|
|
|
| 16 |
from src.integrations.real_time_integration import RealTimeIntegration, BotEvent
|
| 17 |
from src.core.performance_monitor import PerformanceMonitor, measure_analysis_time
|
| 18 |
from src.utils.request_logger import log_requests_responses, enable_logging, disable_logging
|
|
|
|
| 13 |
from src.utils.utils import LogUtils, ValidationUtils
|
| 14 |
from src.core.log_parser import VampireBotLogParser
|
| 15 |
from src.analysis.fibonacci_analysis import AdvancedFibonacciEngine
|
| 16 |
+
from src.core.advanced_market_processing import AdvancedMarketProcessor
|
| 17 |
from src.integrations.real_time_integration import RealTimeIntegration, BotEvent
|
| 18 |
from src.core.performance_monitor import PerformanceMonitor, measure_analysis_time
|
| 19 |
from src.utils.request_logger import log_requests_responses, enable_logging, disable_logging
|
docs/api-reference.md
CHANGED
|
@@ -6,6 +6,65 @@ Este documento descreve todas as APIs, interfaces e contratos entre os módulos
|
|
| 6 |
|
| 7 |
## 🔧 Core Engines
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
### TechnicalAnalysisEngine
|
| 10 |
|
| 11 |
#### Classe Principal
|
|
|
|
| 6 |
|
| 7 |
## 🔧 Core Engines
|
| 8 |
|
| 9 |
+
### Funções Utilitárias de Análise Técnica
|
| 10 |
+
|
| 11 |
+
#### calculate_rsi(prices: list, period: int = 14) -> float
|
| 12 |
+
```python
|
| 13 |
+
def calculate_rsi(prices: list, period: int = 14) -> float:
|
| 14 |
+
"""Calcula o RSI (Relative Strength Index).
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
prices (list): Lista de preços históricos
|
| 18 |
+
period (int): Período para cálculo (padrão: 14)
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
float: Valor do RSI (0-100)
|
| 22 |
+
"""
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
#### calculate_bollinger_bands(prices: list, period: int = 20, std_dev: float = 2.0) -> dict
|
| 26 |
+
```python
|
| 27 |
+
def calculate_bollinger_bands(prices: list, period: int = 20, std_dev: float = 2.0) -> dict:
|
| 28 |
+
"""Calcula as Bandas de Bollinger.
|
| 29 |
+
|
| 30 |
+
Args:
|
| 31 |
+
prices (list): Lista de preços históricos
|
| 32 |
+
period (int): Período para média móvel (padrão: 20)
|
| 33 |
+
std_dev (float): Multiplicador do desvio padrão (padrão: 2.0)
|
| 34 |
+
|
| 35 |
+
Returns:
|
| 36 |
+
dict: {'upper': float, 'middle': float, 'lower': float}
|
| 37 |
+
"""
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
#### calculate_ema(prices: list, period: int) -> float
|
| 41 |
+
```python
|
| 42 |
+
def calculate_ema(prices: list, period: int) -> float:
|
| 43 |
+
"""Calcula a EMA (Exponential Moving Average).
|
| 44 |
+
|
| 45 |
+
Args:
|
| 46 |
+
prices (list): Lista de preços históricos
|
| 47 |
+
period (int): Período para cálculo da EMA
|
| 48 |
+
|
| 49 |
+
Returns:
|
| 50 |
+
float: Valor da EMA
|
| 51 |
+
"""
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
#### format_number(value: float, decimals: int = 2) -> str
|
| 55 |
+
```python
|
| 56 |
+
def format_number(value: float, decimals: int = 2) -> str:
|
| 57 |
+
"""Formata um número para exibição.
|
| 58 |
+
|
| 59 |
+
Args:
|
| 60 |
+
value (float): Valor a ser formatado
|
| 61 |
+
decimals (int): Número de casas decimais (padrão: 2)
|
| 62 |
+
|
| 63 |
+
Returns:
|
| 64 |
+
str: Número formatado
|
| 65 |
+
"""
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
### TechnicalAnalysisEngine
|
| 69 |
|
| 70 |
#### Classe Principal
|
docs/theme_system.md
CHANGED
|
@@ -44,20 +44,20 @@ Componentes de interface com suporte a tema escuro:
|
|
| 44 |
## Paletas de Cores
|
| 45 |
|
| 46 |
### Tema Claro
|
| 47 |
-
- **Fundo Principal**: `#ffffff`
|
| 48 |
-
- **Fundo Secundário**: `#f8f9fa`
|
| 49 |
- **Texto Principal**: `#495057`
|
| 50 |
- **Texto Secundário**: `#6c757d`
|
| 51 |
- **Bordas**: `#dee2e6`
|
| 52 |
- **Accent**: `#007bff`
|
| 53 |
|
| 54 |
### Tema Escuro
|
| 55 |
-
- **Fundo Principal**: `#
|
| 56 |
-
- **Fundo Secundário**: `#
|
| 57 |
-
- **Texto Principal**: `#
|
| 58 |
-
- **Texto Secundário**: `#
|
| 59 |
-
- **Bordas**: `#
|
| 60 |
-
- **Accent**: `#
|
| 61 |
|
| 62 |
## Implementação
|
| 63 |
|
|
@@ -69,6 +69,8 @@ O sistema utiliza variáveis CSS para permitir alternância dinâmica:
|
|
| 69 |
:root {
|
| 70 |
--bg-primary: #ffffff;
|
| 71 |
--bg-secondary: #f8f9fa;
|
|
|
|
|
|
|
| 72 |
--text-primary: #495057;
|
| 73 |
--text-secondary: #6c757d;
|
| 74 |
--border-color: #dee2e6;
|
|
@@ -76,12 +78,14 @@ O sistema utiliza variáveis CSS para permitir alternância dinâmica:
|
|
| 76 |
}
|
| 77 |
|
| 78 |
[data-theme="dark"] {
|
| 79 |
-
--bg-primary: #
|
| 80 |
-
--bg-secondary: #
|
| 81 |
-
--
|
| 82 |
-
--
|
| 83 |
-
--
|
| 84 |
-
--
|
|
|
|
|
|
|
| 85 |
}
|
| 86 |
```
|
| 87 |
|
|
|
|
| 44 |
## Paletas de Cores
|
| 45 |
|
| 46 |
### Tema Claro
|
| 47 |
+
- **Fundo Principal**: `#ffffff` (`--bg-primary`, `--bg`)
|
| 48 |
+
- **Fundo Secundário**: `#f8f9fa` (`--bg-secondary`, `--surface`)
|
| 49 |
- **Texto Principal**: `#495057`
|
| 50 |
- **Texto Secundário**: `#6c757d`
|
| 51 |
- **Bordas**: `#dee2e6`
|
| 52 |
- **Accent**: `#007bff`
|
| 53 |
|
| 54 |
### Tema Escuro
|
| 55 |
+
- **Fundo Principal**: `#0f172a` (`--bg-primary`, `--bg`)
|
| 56 |
+
- **Fundo Secundário**: `#1e293b` (`--bg-secondary`, `--surface`)
|
| 57 |
+
- **Texto Principal**: `#f1f5f9`
|
| 58 |
+
- **Texto Secundário**: `#cbd5e1`
|
| 59 |
+
- **Bordas**: `#475569`
|
| 60 |
+
- **Accent**: `#60a5fa`
|
| 61 |
|
| 62 |
## Implementação
|
| 63 |
|
|
|
|
| 69 |
:root {
|
| 70 |
--bg-primary: #ffffff;
|
| 71 |
--bg-secondary: #f8f9fa;
|
| 72 |
+
--bg: #ffffff;
|
| 73 |
+
--surface: #f8f9fa;
|
| 74 |
--text-primary: #495057;
|
| 75 |
--text-secondary: #6c757d;
|
| 76 |
--border-color: #dee2e6;
|
|
|
|
| 78 |
}
|
| 79 |
|
| 80 |
[data-theme="dark"] {
|
| 81 |
+
--bg-primary: #0f172a;
|
| 82 |
+
--bg-secondary: #1e293b;
|
| 83 |
+
--bg: #0f172a;
|
| 84 |
+
--surface: #1e293b;
|
| 85 |
+
--text-primary: #f1f5f9;
|
| 86 |
+
--text-secondary: #cbd5e1;
|
| 87 |
+
--border-color: #475569;
|
| 88 |
+
--accent-color: #60a5fa;
|
| 89 |
}
|
| 90 |
```
|
| 91 |
|
logs/application.db
CHANGED
|
Binary files a/logs/application.db and b/logs/application.db differ
|
|
|
src/analysis/__pycache__/fibonacci_analysis.cpython-313.pyc
ADDED
|
Binary file (21.7 kB). View file
|
|
|
src/core/__pycache__/advanced_market_processing.cpython-313.pyc
ADDED
|
Binary file (22.9 kB). View file
|
|
|
src/core/__pycache__/log_parser.cpython-313.pyc
ADDED
|
Binary file (20.5 kB). View file
|
|
|
src/core/__pycache__/performance_monitor.cpython-313.pyc
ADDED
|
Binary file (20.6 kB). View file
|
|
|
src/integrations/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (148 Bytes). View file
|
|
|
src/integrations/__pycache__/real_time_integration.cpython-313.pyc
ADDED
|
Binary file (18.9 kB). View file
|
|
|
src/ui/__pycache__/dark_theme_components.cpython-313.pyc
ADDED
|
Binary file (23 kB). View file
|
|
|
src/ui/__pycache__/gradio_interface.cpython-313.pyc
CHANGED
|
Binary files a/src/ui/__pycache__/gradio_interface.cpython-313.pyc and b/src/ui/__pycache__/gradio_interface.cpython-313.pyc differ
|
|
|
src/ui/__pycache__/log_viewer.cpython-313.pyc
ADDED
|
Binary file (20.8 kB). View file
|
|
|
src/ui/__pycache__/theme_manager.cpython-313.pyc
CHANGED
|
Binary files a/src/ui/__pycache__/theme_manager.cpython-313.pyc and b/src/ui/__pycache__/theme_manager.cpython-313.pyc differ
|
|
|
src/ui/gradio_interface.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import gradio as gr
|
| 4 |
from typing import Dict, Any, Optional, Tuple
|
| 5 |
|
| 6 |
-
from config.config import UIConfig, AppConfig
|
| 7 |
from src.utils.utils import (
|
| 8 |
DateTimeUtils,
|
| 9 |
NumberUtils,
|
|
@@ -93,7 +93,7 @@ class UIComponents:
|
|
| 93 |
with gr.Tab("🤖 Log do Bot"):
|
| 94 |
market_input = gr.Textbox(
|
| 95 |
label="Log do Bot de Trading",
|
| 96 |
-
placeholder=
|
| 97 |
lines=8,
|
| 98 |
max_lines=15
|
| 99 |
)
|
|
@@ -193,13 +193,13 @@ class ResultFormatter:
|
|
| 193 |
</div>
|
| 194 |
|
| 195 |
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
|
| 196 |
-
<div style="text-align: center; padding: 15px; background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
|
| 197 |
<div style="font-size: 0.9em; color: #6c757d; margin-bottom: 5px;">PREÇO ATUAL</div>
|
| 198 |
<div style="font-size: 1.8em; font-weight: bold; color: #495057;">{formatted_price}</div>
|
| 199 |
<div style="font-size: 1.1em; color: {variation_color}; font-weight: 600;">{formatted_variation}</div>
|
| 200 |
</div>
|
| 201 |
|
| 202 |
-
<div style="text-align: center; padding: 15px; background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
|
| 203 |
<div style="font-size: 0.9em; color: #6c757d; margin-bottom: 5px;">CONFIANÇA</div>
|
| 204 |
<div style="font-size: 1.8em; font-weight: bold; color: #495057;">{confidence}%</div>
|
| 205 |
<div style="font-size: 0.9em; color: #6c757d;">{confidence_level}</div>
|
|
@@ -226,17 +226,17 @@ class ResultFormatter:
|
|
| 226 |
signals_list = FormatUtils.format_signal_list(signals)
|
| 227 |
|
| 228 |
return f"""
|
| 229 |
-
<div style="background: white; border-radius: 8px; padding: 20px; border: 1px solid #dee2e6;">
|
| 230 |
<h3 style="color: #495057; margin-top: 0; border-bottom: 2px solid #007bff; padding-bottom: 10px;">
|
| 231 |
📊 Indicadores Técnicos
|
| 232 |
</h3>
|
| 233 |
|
| 234 |
-
<div style="background: #f8f9fa; padding: 15px; border-radius: 6px; margin-bottom: 20px;">
|
| 235 |
{market_summary}
|
| 236 |
</div>
|
| 237 |
|
| 238 |
<h4 style="color: #495057; margin-bottom: 15px;">🎯 Sinais Detectados</h4>
|
| 239 |
-
<div style="background: #f8f9fa; padding: 15px; border-radius: 6px; font-family: monospace; white-space: pre-line;">
|
| 240 |
{signals_list}
|
| 241 |
</div>
|
| 242 |
</div>
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from typing import Dict, Any, Optional, Tuple
|
| 5 |
|
| 6 |
+
from config.config import UIConfig, AppConfig, ExampleData
|
| 7 |
from src.utils.utils import (
|
| 8 |
DateTimeUtils,
|
| 9 |
NumberUtils,
|
|
|
|
| 93 |
with gr.Tab("🤖 Log do Bot"):
|
| 94 |
market_input = gr.Textbox(
|
| 95 |
label="Log do Bot de Trading",
|
| 96 |
+
placeholder=ExampleData.SAMPLE_MARKET_DATA['bullish'],
|
| 97 |
lines=8,
|
| 98 |
max_lines=15
|
| 99 |
)
|
|
|
|
| 193 |
</div>
|
| 194 |
|
| 195 |
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
|
| 196 |
+
<div style="text-align: center; padding: 15px; background: var(--bg, white); border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
|
| 197 |
<div style="font-size: 0.9em; color: #6c757d; margin-bottom: 5px;">PREÇO ATUAL</div>
|
| 198 |
<div style="font-size: 1.8em; font-weight: bold; color: #495057;">{formatted_price}</div>
|
| 199 |
<div style="font-size: 1.1em; color: {variation_color}; font-weight: 600;">{formatted_variation}</div>
|
| 200 |
</div>
|
| 201 |
|
| 202 |
+
<div style="text-align: center; padding: 15px; background: var(--bg, white); border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
|
| 203 |
<div style="font-size: 0.9em; color: #6c757d; margin-bottom: 5px;">CONFIANÇA</div>
|
| 204 |
<div style="font-size: 1.8em; font-weight: bold; color: #495057;">{confidence}%</div>
|
| 205 |
<div style="font-size: 0.9em; color: #6c757d;">{confidence_level}</div>
|
|
|
|
| 226 |
signals_list = FormatUtils.format_signal_list(signals)
|
| 227 |
|
| 228 |
return f"""
|
| 229 |
+
<div style="background: var(--bg, white); border-radius: 8px; padding: 20px; border: 1px solid #dee2e6;">
|
| 230 |
<h3 style="color: #495057; margin-top: 0; border-bottom: 2px solid #007bff; padding-bottom: 10px;">
|
| 231 |
📊 Indicadores Técnicos
|
| 232 |
</h3>
|
| 233 |
|
| 234 |
+
<div style="background: var(--surface, #f8f9fa); padding: 15px; border-radius: 6px; margin-bottom: 20px;">
|
| 235 |
{market_summary}
|
| 236 |
</div>
|
| 237 |
|
| 238 |
<h4 style="color: #495057; margin-bottom: 15px;">🎯 Sinais Detectados</h4>
|
| 239 |
+
<div style="background: var(--surface, #f8f9fa); padding: 15px; border-radius: 6px; font-family: monospace; white-space: pre-line;">
|
| 240 |
{signals_list}
|
| 241 |
</div>
|
| 242 |
</div>
|
src/ui/theme_manager.py
CHANGED
|
@@ -87,6 +87,8 @@ class ThemeManager:
|
|
| 87 |
'css_variables': {
|
| 88 |
'--bg-primary': '#ffffff',
|
| 89 |
'--bg-secondary': '#f8f9fa',
|
|
|
|
|
|
|
| 90 |
'--text-primary': '#495057',
|
| 91 |
'--text-secondary': '#6c757d',
|
| 92 |
'--border-color': '#dee2e6',
|
|
@@ -131,6 +133,8 @@ class ThemeManager:
|
|
| 131 |
'css_variables': {
|
| 132 |
'--bg-primary': '#0f172a',
|
| 133 |
'--bg-secondary': '#1e293b',
|
|
|
|
|
|
|
| 134 |
'--text-primary': '#f1f5f9',
|
| 135 |
'--text-secondary': '#cbd5e1',
|
| 136 |
'--border-color': '#475569',
|
|
|
|
| 87 |
'css_variables': {
|
| 88 |
'--bg-primary': '#ffffff',
|
| 89 |
'--bg-secondary': '#f8f9fa',
|
| 90 |
+
'--bg': '#ffffff',
|
| 91 |
+
'--surface': '#f8f9fa',
|
| 92 |
'--text-primary': '#495057',
|
| 93 |
'--text-secondary': '#6c757d',
|
| 94 |
'--border-color': '#dee2e6',
|
|
|
|
| 133 |
'css_variables': {
|
| 134 |
'--bg-primary': '#0f172a',
|
| 135 |
'--bg-secondary': '#1e293b',
|
| 136 |
+
'--bg': '#0f172a',
|
| 137 |
+
'--surface': '#1e293b',
|
| 138 |
'--text-primary': '#f1f5f9',
|
| 139 |
'--text-secondary': '#cbd5e1',
|
| 140 |
'--border-color': '#475569',
|
src/utils/__pycache__/utils.cpython-313.pyc
CHANGED
|
Binary files a/src/utils/__pycache__/utils.cpython-313.pyc and b/src/utils/__pycache__/utils.cpython-313.pyc differ
|
|
|
src/utils/utils.py
CHANGED
|
@@ -94,6 +94,77 @@ class ActionUtils:
|
|
| 94 |
'main': '⚪',
|
| 95 |
'action': '❓'
|
| 96 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
@staticmethod
|
| 99 |
def get_action_color(action: str) -> str:
|
|
|
|
| 94 |
'main': '⚪',
|
| 95 |
'action': '❓'
|
| 96 |
})
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def calculate_rsi(prices: list, period: int = 14) -> float:
|
| 100 |
+
"""Calcula o RSI (Relative Strength Index)."""
|
| 101 |
+
if len(prices) < period + 1:
|
| 102 |
+
return 50.0 # Valor neutro se não há dados suficientes
|
| 103 |
+
|
| 104 |
+
gains = []
|
| 105 |
+
losses = []
|
| 106 |
+
|
| 107 |
+
for i in range(1, len(prices)):
|
| 108 |
+
change = prices[i] - prices[i-1]
|
| 109 |
+
if change > 0:
|
| 110 |
+
gains.append(change)
|
| 111 |
+
losses.append(0)
|
| 112 |
+
else:
|
| 113 |
+
gains.append(0)
|
| 114 |
+
losses.append(abs(change))
|
| 115 |
+
|
| 116 |
+
if len(gains) < period:
|
| 117 |
+
return 50.0
|
| 118 |
+
|
| 119 |
+
avg_gain = sum(gains[-period:]) / period
|
| 120 |
+
avg_loss = sum(losses[-period:]) / period
|
| 121 |
+
|
| 122 |
+
if avg_loss == 0:
|
| 123 |
+
return 100.0
|
| 124 |
+
|
| 125 |
+
rs = avg_gain / avg_loss
|
| 126 |
+
rsi = 100 - (100 / (1 + rs))
|
| 127 |
+
return rsi
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def calculate_bollinger_bands(prices: list, period: int = 20, std_dev: float = 2.0) -> dict:
|
| 131 |
+
"""Calcula as Bandas de Bollinger."""
|
| 132 |
+
if len(prices) < period:
|
| 133 |
+
return {'upper': 0, 'middle': 0, 'lower': 0}
|
| 134 |
+
|
| 135 |
+
recent_prices = prices[-period:]
|
| 136 |
+
sma = sum(recent_prices) / period
|
| 137 |
+
|
| 138 |
+
variance = sum((price - sma) ** 2 for price in recent_prices) / period
|
| 139 |
+
std = variance ** 0.5
|
| 140 |
+
|
| 141 |
+
upper_band = sma + (std_dev * std)
|
| 142 |
+
lower_band = sma - (std_dev * std)
|
| 143 |
+
|
| 144 |
+
return {
|
| 145 |
+
'upper': upper_band,
|
| 146 |
+
'middle': sma,
|
| 147 |
+
'lower': lower_band
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def calculate_ema(prices: list, period: int = 9) -> float:
|
| 152 |
+
"""Calcula a EMA (Exponential Moving Average)."""
|
| 153 |
+
if len(prices) < period:
|
| 154 |
+
return sum(prices) / len(prices) if prices else 0
|
| 155 |
+
|
| 156 |
+
multiplier = 2 / (period + 1)
|
| 157 |
+
ema = sum(prices[:period]) / period # SMA inicial
|
| 158 |
+
|
| 159 |
+
for price in prices[period:]:
|
| 160 |
+
ema = (price * multiplier) + (ema * (1 - multiplier))
|
| 161 |
+
|
| 162 |
+
return ema
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def format_number(value: float, decimals: int = 2) -> str:
|
| 166 |
+
"""Formata número com casas decimais especificadas."""
|
| 167 |
+
return f"{value:.{decimals}f}"
|
| 168 |
|
| 169 |
@staticmethod
|
| 170 |
def get_action_color(action: str) -> str:
|