feat: add USD/BRL and XAU/USD pipeline agents (Brief+Decio) with /api/usd/brief and /api/xau/brief routes

This commit is contained in:
2026-06-15 17:22:16 +00:00
parent 1e3f2e7199
commit 1defb34d47
6 changed files with 602 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
"""
BrainSteel Fin — USD Décio Agent
Estrategista para câmbio USD/BRL
"""
import os, json, requests
from datetime import datetime
class USDDecioAgent:
def __init__(self, brief_data):
self.name = "USDDecio"
self.brief_data = brief_data
self.openrouter_key = os.getenv("DECIO_API_KEY", os.getenv("OPENROUTER_API_KEY", ""))
self.openrouter_url = "https://openrouter.ai/api/v1/chat/completions"
self.model = "deepseek/deepseek-v4-flash:free"
def _calc_levels(self, price, action):
"""Stop Loss 1%, Take Profit 2% para câmbio."""
if action == "BUY":
return round(price * 0.99, 4), round(price * 1.02, 4)
elif action == "SELL":
return round(price * 1.01, 4), round(price * 0.98, 4)
return 0, 0
def run(self):
signal = self.brief_data.get("signal", "NEUTRO")
confidence = self.brief_data.get("confidence", 50)
price = self.brief_data.get("price", 0)
ptax = self.brief_data.get("ptax", 0)
selic = self.brief_data.get("selic", 0)
dxy = self.brief_data.get("dxy", 0)
change_24h = self.brief_data.get("change_24h", 0)
# Regra: confiança < 70% = HOLD
if confidence < 70 or signal == "NEUTRO":
return {
"decision": "HOLD",
"confidence": confidence,
"stop_loss": 0,
"take_profit": 0,
"justification": "Confiança abaixo de 70% ou sinal neutro",
}
# Decisão
action = "HOLD"
sl, tp = 0, 0
if signal == "ALTA":
action = "BUY"
sl, tp = self._calc_levels(price, action)
elif signal == "BAIXA":
action = "SELL"
sl, tp = self._calc_levels(price, action)
justification = f"""Dólar {signal}. PTAX R$ {ptax:.4f}. Selic {selic:.2f}%. DXY {dxy:.2f}. Variação 24h {change_24h:+.2f}%. Confiança {confidence}%."""
return {
"decision": action,
"confidence": confidence,
"stop_loss": sl,
"take_profit": tp,
"justification": justification,
}