#!/usr/bin/env python3 """ FastAPI Client Test - Test the scalping bot API endpoints """ import requests import time import json BASE_URL = "http://localhost:8000" def test_endpoint(method, endpoint, data=None, params=None): """Test an API endpoint""" try: url = f"{BASE_URL}{endpoint}" if method == "GET": response = requests.get(url, params=params) elif method == "POST": response = requests.post(url, json=data, params=params) else: print(f"❌ Unsupported method: {method}") return None print(f"\n{method} {endpoint}") print(f"Status: {response.status_code}") if response.status_code == 200: try: result = response.json() print("✅ Success") return result except: print(f"Response: {response.text[:200]}...") return response.text else: print(f"❌ Error: {response.text}") return None except Exception as e: print(f"❌ Connection Error: {e}") return None def main(): print("🧪 FastAPI Client Test") print("=" * 40) # Test 1: Get status print("\n1️⃣ Testing /status endpoint...") status = test_endpoint("GET", "/status") if status: print(f" Bot running: {status.get('is_running', 'Unknown')}") print(f" Active sessions: {len(status.get('active_sessions', []))}") # Test 2: Get root print("\n2️⃣ Testing / root endpoint...") root = test_endpoint("GET", "/") # Test 3: Try to start BTC trading (will fail if server not running) print("\n3️⃣ Testing /start/BTCUSDT endpoint...") start_result = test_endpoint("POST", "/start/BTCUSDT", params={"duration_hours": 1}) if start_result: print(" BTC trading session started!") else: print(" (Expected to fail if API server not running)") # Test 4: Get sessions print("\n4️⃣ Testing /sessions endpoint...") sessions = test_endpoint("GET", "/sessions") print("\n" + "=" * 40) print("📊 Test Complete") print("\nTo run the API server:") print(" python3 api_server.py") print("\nTo start trading:") print(" curl -X POST http://localhost:8000/start/BTCUSDT") print("\nTo check status:") print(" curl http://localhost:8000/status") if __name__ == "__main__": main()