#!/usr/bin/env python3 """ Test the Fixed Scalping Dashboard This script tests if the scalping dashboard is now returning proper JSON data instead of HTTP 204 No Content responses. """ import requests import json import time def test_scalping_dashboard_response(): """Test if scalping dashboard returns proper JSON data""" base_url = "http://127.0.0.1:8051" print("Testing Scalping Dashboard Response...") print(f"Base URL: {base_url}") try: # Test main dashboard page print("\n1. Testing main dashboard page...") response = requests.get(base_url, timeout=10) print(f" Status: {response.status_code}") print(f" Content Type: {response.headers.get('content-type', 'Unknown')}") print(f" Response Size: {len(response.content)} bytes") if response.status_code == 200: print(" ✅ Main page loads successfully") else: print(f" ❌ Main page failed with status {response.status_code}") # Test callback endpoint (simulating what the frontend does) print("\n2. Testing dashboard callback endpoint...") callback_url = f"{base_url}/_dash-update-component" # Dash callback payload (this is what the frontend sends) callback_data = { "output": [ {"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": "model-training-status", "property": "children"}, {"id": "orchestrator-status", "property": "children"}, {"id": "training-events-log", "property": "children"}, {"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"] } headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } # Wait a moment for the dashboard to initialize print(" Waiting 3 seconds for dashboard initialization...") time.sleep(3) response = requests.post(callback_url, json=callback_data, headers=headers, timeout=15) print(f" Status: {response.status_code}") print(f" Content Type: {response.headers.get('content-type', 'Unknown')}") print(f" Response Size: {len(response.content)} bytes") if response.status_code == 200: print(" ✅ Callback returns HTTP 200 (Success!)") try: response_json = response.json() print(f" ✅ Response contains JSON data") print(f" 📊 Number of data elements: {len(response_json.get('response', {}))}") # Check if we have chart data if 'response' in response_json: resp_data = response_json['response'] # Count chart objects (they should be dictionaries with 'data' and 'layout') chart_count = 0 for key, value in resp_data.items(): if isinstance(value, dict) and 'data' in value and 'layout' in value: chart_count += 1 print(f" 📈 Chart objects found: {chart_count}") if chart_count >= 5: # Should have 5 charts print(" ✅ All expected charts are present!") else: print(f" ⚠️ Expected 5 charts, found {chart_count}") else: print(" ⚠️ No 'response' key in JSON data") except json.JSONDecodeError: print(" ❌ Response is not valid JSON") print(f" Raw response: {response.text[:200]}...") elif response.status_code == 204: print(" ❌ Still returning HTTP 204 (No Content) - Issue not fixed") else: print(f" ❌ Unexpected status code: {response.status_code}") except requests.exceptions.ConnectionError: print(" ❌ Cannot connect to dashboard - is it running?") except requests.exceptions.Timeout: print(" ❌ Request timed out") except Exception as e: print(f" ❌ Error: {e}") if __name__ == "__main__": test_scalping_dashboard_response()