File size: 2,454 Bytes
96e0cc2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/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()