🚀 Auto-deploy: Add background automated scheduler, Kelly allocation, multi-portfolio simulations, and UI improvements
This commit is contained in:
+50
-2
@@ -10,6 +10,52 @@ class AuditAgent:
|
||||
def __init__(self):
|
||||
self.name = "Audit"
|
||||
|
||||
def send_notification(self, audit_result):
|
||||
"""Envia notificação ativa para Telegram/Discord ou grava no log de governança."""
|
||||
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
action = audit_result.get("decio_decision", "HOLD")
|
||||
score = audit_result.get("compliance_score", 0)
|
||||
status = audit_result.get("status", "unknown").upper()
|
||||
pnl_pct = audit_result.get("portfolio_pnl_pct", 0)
|
||||
bal = audit_result.get("portfolio_balance", 0)
|
||||
|
||||
msg = (
|
||||
f"🔔 [BrainSteel Fin Governança] — {now}\n"
|
||||
f"Decisão do Ciclo: {action}\n"
|
||||
f"Veredito do Audit: {status} (Score: {score}%)\n"
|
||||
f"Saldo Virtual: ${bal:,.2f} | PnL Total: {pnl_pct:+.1f}%\n"
|
||||
f"Notas de Qualidade:\n" + "\n".join([f"• {n}" for n in audit_result.get("quality_notes", [])])
|
||||
)
|
||||
|
||||
# 1. Envia Telegram se configurado
|
||||
tg_token = os.getenv("TELEGRAM_BOT_TOKEN", "")
|
||||
tg_chat = os.getenv("TELEGRAM_CHAT_ID", "")
|
||||
if tg_token and tg_chat:
|
||||
try:
|
||||
requests.post(
|
||||
f"https://api.telegram.org/bot{tg_token}/sendMessage",
|
||||
json={"chat_id": tg_chat, "text": msg},
|
||||
timeout=10
|
||||
)
|
||||
except: pass
|
||||
|
||||
# 2. Envia Discord Webhook se configurado
|
||||
discord_url = os.getenv("DISCORD_WEBHOOK_URL", "")
|
||||
if discord_url:
|
||||
try:
|
||||
requests.post(discord_url, json={"content": msg}, timeout=10)
|
||||
except: pass
|
||||
|
||||
# 3. Sempre grava no log de notificações de governança
|
||||
for path in ["/app/logs/notifications.log", "/data/notifications.log"]:
|
||||
try:
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, "a", encoding="utf-8") as f:
|
||||
f.write(msg + "\n" + "-"*40 + "\n")
|
||||
except: pass
|
||||
|
||||
return msg
|
||||
|
||||
def audit_pipeline(self, brief_data, decio_data, papert_data):
|
||||
checks = []
|
||||
|
||||
@@ -105,7 +151,7 @@ class AuditAgent:
|
||||
if decio_action == "HOLD" and brief_data.get("confidence", 0) < 75:
|
||||
quality_notes.append("HOLD correto — confiança baixa preservou capital")
|
||||
|
||||
return {
|
||||
res = {
|
||||
"audit_id": f"AUD-{datetime.now().strftime('%Y%m%d%H%M%S')}",
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
"checks": checks,
|
||||
@@ -117,10 +163,12 @@ class AuditAgent:
|
||||
"brief_summary": brief_data.get("summary", "")[:100],
|
||||
"decio_decision": decio_action,
|
||||
"decio_confidence": decio_conf,
|
||||
"portfolio_balance": portfolio.get("current_balance", 0),
|
||||
"portfolio_balance": portfolio.get("current_balance") or portfolio.get("balance", 0),
|
||||
"portfolio_pnl": portfolio.get("total_pnl", 0),
|
||||
"portfolio_pnl_pct": portfolio.get("total_pnl_pct", 0),
|
||||
}
|
||||
self.send_notification(res)
|
||||
return res
|
||||
|
||||
def generate_llm_report(self, brief_data, decio_data):
|
||||
if not os.getenv("PAPERT_API_KEY") and not os.getenv("OPENROUTER_API_KEY", ""):
|
||||
|
||||
Reference in New Issue
Block a user