145 lines
4.8 KiB
Python
145 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Data Stream Checker - Connects to Running Dashboard
|
|
Checks stream status and generates snapshots from the running dashboard.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import requests
|
|
import json
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
def check_dashboard_status():
|
|
"""Check if dashboard is running and get basic info."""
|
|
try:
|
|
response = requests.get("http://127.0.0.1:8050", timeout=5)
|
|
return response.status_code == 200
|
|
except:
|
|
return False
|
|
|
|
def get_stream_status_from_dashboard():
|
|
"""Get stream status from the running dashboard via HTTP."""
|
|
try:
|
|
# Try to get status from dashboard API endpoint
|
|
response = requests.get("http://127.0.0.1:8050/stream-status", timeout=5)
|
|
if response.status_code == 200:
|
|
return response.json()
|
|
except:
|
|
pass
|
|
|
|
# Fallback: check if dashboard is running and provide guidance
|
|
if check_dashboard_status():
|
|
return {
|
|
"dashboard_running": True,
|
|
"message": "Dashboard is running. Check dashboard console for data stream output.",
|
|
"note": "Data stream is active within the dashboard process."
|
|
}
|
|
else:
|
|
return {
|
|
"dashboard_running": False,
|
|
"message": "Dashboard not running. Start with: python run_clean_dashboard.py"
|
|
}
|
|
|
|
def check_stream():
|
|
"""Check current stream status from running dashboard."""
|
|
print("=" * 60)
|
|
print("DATA STREAM STATUS CHECK")
|
|
print("=" * 60)
|
|
|
|
status = get_stream_status_from_dashboard()
|
|
|
|
if status.get("dashboard_running"):
|
|
print("✅ Dashboard is running")
|
|
if "message" in status:
|
|
print(f"💡 {status['message']}")
|
|
if "note" in status:
|
|
print(f"📝 {status['note']}")
|
|
|
|
# Show what to look for in dashboard console
|
|
print("\n" + "=" * 40)
|
|
print("LOOK FOR IN DASHBOARD CONSOLE:")
|
|
print("=" * 40)
|
|
print("Data stream samples like:")
|
|
print(" OHLCV (1m): ETH/USDT | O:4335.67 H:4338.92 L:4334.21 C:4336.67 V:125.8")
|
|
print(" TICK: ETH/USDT | Price:4336.67 Vol:0.0456 Side:buy")
|
|
print(" DQN Prediction: BUY (conf:0.78)")
|
|
print(" Training Exp: Action:1 Reward:0.0234 Done:False")
|
|
print("\nIf you don't see these, the system may be waiting for market data.")
|
|
else:
|
|
print("❌ Dashboard not running")
|
|
print(f"💡 {status.get('message', 'Unknown error')}")
|
|
|
|
def generate_snapshot():
|
|
"""Generate a snapshot from the running dashboard."""
|
|
print("=" * 60)
|
|
print("GENERATING DATA SNAPSHOT")
|
|
print("=" * 60)
|
|
|
|
if not check_dashboard_status():
|
|
print("❌ Dashboard not running")
|
|
print("💡 Start dashboard first: python run_clean_dashboard.py")
|
|
return
|
|
|
|
try:
|
|
# Try to trigger snapshot via dashboard API
|
|
response = requests.post("http://127.0.0.1:8050/snapshot", timeout=10)
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
print(f"✅ Snapshot saved: {result.get('filepath', 'Unknown')}")
|
|
return
|
|
|
|
# Fallback: create empty snapshot with timestamp
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
filepath = f"data_snapshots/snapshot_{timestamp}.json"
|
|
|
|
os.makedirs("data_snapshots", exist_ok=True)
|
|
|
|
snapshot_data = {
|
|
"timestamp": datetime.now().isoformat(),
|
|
"dashboard_running": True,
|
|
"note": "Empty snapshot - check dashboard console for live data stream",
|
|
"data": {
|
|
"ohlcv_1m": [],
|
|
"ohlcv_5m": [],
|
|
"ohlcv_15m": [],
|
|
"ticks": [],
|
|
"cob_raw": [],
|
|
"cob_aggregated": [],
|
|
"technical_indicators": [],
|
|
"model_states": [],
|
|
"predictions": [],
|
|
"training_experiences": []
|
|
}
|
|
}
|
|
|
|
with open(filepath, 'w') as f:
|
|
json.dump(snapshot_data, f, indent=2)
|
|
|
|
print(f"✅ Snapshot saved: {filepath}")
|
|
print("📝 Note: This is an empty snapshot. Check dashboard console for live data.")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error: {e}")
|
|
|
|
def main():
|
|
if len(sys.argv) < 2:
|
|
print("Usage:")
|
|
print(" python check_stream.py status # Check stream status")
|
|
print(" python check_stream.py snapshot # Generate snapshot")
|
|
return
|
|
|
|
command = sys.argv[1].lower()
|
|
|
|
if command == "status":
|
|
check_stream()
|
|
elif command == "snapshot":
|
|
generate_snapshot()
|
|
else:
|
|
print(f"Unknown command: {command}")
|
|
print("Available commands: status, snapshot")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|