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
+60
View File
@@ -0,0 +1,60 @@
"""
BrainSteel Fin — XAU Décio Agent
Estrategista para ouro XAU/USD
"""
import os, json, requests
from datetime import datetime
class XAUDecioAgent:
def __init__(self, brief_data):
self.name = "XAUDecio"
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.5%, Take Profit 3% para ouro."""
if action == "BUY":
return round(price * 0.985, 2), round(price * 1.03, 2)
elif action == "SELL":
return round(price * 1.015, 2), round(price * 0.97, 2)
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)
change_24h = self.brief_data.get("change_24h", 0)
us10y = self.brief_data.get("us10y_yield", 0)
fed_funds = self.brief_data.get("fed_funds", 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",
}
# Ouro é refúgio: sobe com incerteza / yields baixas
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"""Ouro {signal}. US$ {price:,.2f}. Yield 10Y {us10y:.2f}%. Fed {fed_funds:.2f}%. Variação 24h {change_24h:+.2f}%. Confiança {confidence}%."""
return {
"decision": action,
"confidence": confidence,
"stop_loss": sl,
"take_profit": tp,
"justification": justification,
}