gogo2/test_dashboard_requests.py
2025-05-26 16:02:40 +03:00

110 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""
Test script to make direct requests to the dashboard's callback endpoint
"""
import requests
import json
import time
def test_dashboard_callback():
"""Test the dashboard callback endpoint directly"""
dashboard_url = "http://127.0.0.1:8054"
callback_url = f"{dashboard_url}/_dash-update-component"
print(f"Testing dashboard at {dashboard_url}")
# First, check if dashboard is running
try:
response = requests.get(dashboard_url, timeout=5)
print(f"Dashboard status: {response.status_code}")
if response.status_code != 200:
print("Dashboard not responding properly")
return
except Exception as e:
print(f"Error connecting to dashboard: {e}")
return
# Test callback request for dashboard test
callback_data = {
"output": "current-balance.children",
"outputs": [
{"id": "current-balance", "property": "children"},
{"id": "session-duration", "property": "children"},
{"id": "open-positions", "property": "children"},
{"id": "live-pnl", "property": "children"},
{"id": "win-rate", "property": "children"},
{"id": "total-trades", "property": "children"},
{"id": "last-action", "property": "children"},
{"id": "eth-price", "property": "children"},
{"id": "btc-price", "property": "children"},
{"id": "main-eth-1s-chart", "property": "figure"},
{"id": "eth-1m-chart", "property": "figure"},
{"id": "eth-1h-chart", "property": "figure"},
{"id": "eth-1d-chart", "property": "figure"},
{"id": "btc-1s-chart", "property": "figure"},
{"id": "actions-log", "property": "children"},
{"id": "debug-status", "property": "children"}
],
"inputs": [
{"id": "ultra-fast-interval", "property": "n_intervals", "value": 1}
],
"changedPropIds": ["ultra-fast-interval.n_intervals"],
"state": []
}
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
print("\nTesting callback request...")
try:
response = requests.post(
callback_url,
data=json.dumps(callback_data),
headers=headers,
timeout=10
)
print(f"Callback response status: {response.status_code}")
print(f"Response headers: {dict(response.headers)}")
if response.status_code == 200:
try:
response_data = response.json()
print(f"Response data keys: {list(response_data.keys()) if isinstance(response_data, dict) else 'Not a dict'}")
print(f"Response data type: {type(response_data)}")
if isinstance(response_data, dict) and 'response' in response_data:
print(f"Response contains {len(response_data['response'])} items")
for i, item in enumerate(response_data['response'][:3]): # Show first 3 items
print(f" Item {i}: {type(item)} - {str(item)[:100]}...")
else:
print(f"Full response: {str(response_data)[:500]}...")
except json.JSONDecodeError as e:
print(f"Error parsing JSON response: {e}")
print(f"Raw response: {response.text[:500]}...")
else:
print(f"Error response: {response.text}")
except Exception as e:
print(f"Error making callback request: {e}")
def monitor_dashboard():
"""Monitor dashboard callback requests"""
print("Monitoring dashboard callback requests...")
print("Press Ctrl+C to stop")
try:
for i in range(10): # Test 10 times
print(f"\n--- Test {i+1} ---")
test_dashboard_callback()
time.sleep(2)
except KeyboardInterrupt:
print("\nMonitoring stopped")
if __name__ == "__main__":
monitor_dashboard()