The XAUUSD Trading Bot requires API credentials to function. This page covers the required environment variables and best practices for managing them securely.
Always add secrets files to .gitignore to prevent accidental commits:
.gitignore
# Secrets and environment files.env.streamlit/secrets.toml*.keycredentials.json
Show Use Secrets Management Services
For production deployments, consider using dedicated secrets management:
Streamlit Cloud: Built-in secrets management in app settings
AWS: AWS Secrets Manager or Parameter Store
Google Cloud: Secret Manager
Azure: Key Vault
HashiCorp: Vault
Show Rotate Keys Regularly
Change API keys periodically (e.g., every 90 days)
Immediately rotate keys if you suspect they’ve been compromised
Keep track of key rotation dates
Show Limit Key Permissions
Use API keys with minimum required permissions
Create separate keys for development and production
Monitor API key usage for unusual activity
Show Validate Before Use
Always validate that required environment variables are set:
import osdef get_api_key(): api_key = os.getenv("GROQ_API_KEY") if not api_key: raise ValueError( "GROQ_API_KEY is not set. " "Please configure it in your environment or secrets." ) return api_keybot = XAUUSDTradingBot(api_key=get_api_key())
# Error: KeyError: 'GROQ_API_KEY'# Solution: Verify the key is setimport streamlit as stif "GROQ_API_KEY" not in st.secrets: st.error("GROQ_API_KEY not found in secrets. Please configure it.") st.stop()bot = XAUUSDTradingBot(api_key=st.secrets["GROQ_API_KEY"])
# Error: Authentication failed# Solution: Verify key is correct and activetry: bot = XAUUSDTradingBot(api_key=st.secrets["GROQ_API_KEY"]) result = bot.run_analysis()except Exception as e: if "authentication" in str(e).lower(): st.error("Invalid API key. Please check your GROQ_API_KEY.") else: st.error(f"Error: {str(e)}")