# file: agent_system/test_auth.py import ccxt import os from dotenv import load_dotenv load_dotenv() def test_alpaca_auth(): api_key = os.getenv("ALPACA_API_KEY") secret = os.getenv("ALPACA_SECRET") print(f"Key: {api_key[:5]}...") exchange = ccxt.alpaca({ 'apiKey': api_key, 'secret': secret, }) # Alpaca CCXT specific: setting sandbox mode changes the base URL if api_key.startswith("PK"): exchange.set_sandbox_mode(True) print(">>> Sandbox Mode Active (Paper Trading)") print(f"URLs: {exchange.urls['api']}") try: balance = exchange.fetch_balance() print("✅ Auth Successful!") print(f"Total Cash: ${balance['total'].get('USD', 0)}") except Exception as e: print(f"❌ Auth Failed: {e}") if __name__ == "__main__": test_alpaca_auth()