Skip to main content

Overview

The XAUUSDTradingBot class is the main interface for performing technical analysis and generating trading signals for the XAUUSD (Gold/USD) market across multiple timeframes.

Class Definition

Constructor

from XAUSD_AI import XAUUSDTradingBot

bot = XAUUSDTradingBot(api_key=st.secrets["GROQ_API_KEY"])
api_key
string
required
The GROQ API key for LLM-powered analysis. Should be stored securely in environment variables or secrets management.

Methods

run_analysis()

Executes a complete market analysis across all supported timeframes and generates trading signals.
result = bot.run_analysis()

Parameters

No parameters required.

Returns

Returns a dictionary containing analysis results with the following structure:
technical_features
string | object
Technical analysis results including indicators, patterns, and market conditions. May contain content attribute if returned as an object.
market_data
dict
Market data organized by timeframe. Keys are timeframe identifiers (e.g., “D1”, “H4”, “H1”, “M30”, “M15”, “M5”).
trading_signal
string | object
Generated trading signal with entry/exit recommendations. May contain content attribute if returned as an object.
current_spread
number
Current bid-ask spread in points for XAUUSD.

Example Usage

import streamlit as st
from XAUSD_AI import XAUUSDTradingBot
from datetime import datetime

# Initialize bot
bot = XAUUSDTradingBot(api_key=st.secrets["GROQ_API_KEY"])

# Run analysis
if st.button("📈 Run New Analysis"):
    with st.spinner("Analyzing market data..."):
        result = bot.run_analysis()
        st.session_state['analysis_result'] = result
        st.session_state['last_update'] = datetime.now()

Response Formatting

When working with signal content that may be returned as objects, use this helper function:
def format_signal(signal_content):
    """Format and display trading signal content"""
    if isinstance(signal_content, str):
        return signal_content
    return signal_content.content if hasattr(signal_content, 'content') else str(signal_content)

Best Practices

Build docs developers (and LLMs) love