221 lines
8.1 KiB
Python
221 lines
8.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test callback registration to identify the issue
|
|
"""
|
|
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add project root to path
|
|
project_root = Path(__file__).parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
import dash
|
|
from dash import dcc, html, Input, Output
|
|
|
|
# Setup logging
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def test_simple_callback():
|
|
"""Test a simple callback registration"""
|
|
logger.info("Testing simple callback registration...")
|
|
|
|
app = dash.Dash(__name__)
|
|
|
|
app.layout = html.Div([
|
|
html.H1("Callback Registration Test"),
|
|
html.Div(id="output", children="Initial"),
|
|
dcc.Interval(id="interval", interval=1000, n_intervals=0)
|
|
])
|
|
|
|
@app.callback(
|
|
Output('output', 'children'),
|
|
Input('interval', 'n_intervals')
|
|
)
|
|
def update_output(n_intervals):
|
|
logger.info(f"Callback triggered: {n_intervals}")
|
|
return f"Update #{n_intervals}"
|
|
|
|
logger.info("Simple callback registered successfully")
|
|
|
|
# Check if callback is in the callback map
|
|
logger.info(f"Callback map keys: {list(app.callback_map.keys())}")
|
|
|
|
return app
|
|
|
|
def test_complex_callback():
|
|
"""Test a complex callback like the dashboard"""
|
|
logger.info("Testing complex callback registration...")
|
|
|
|
app = dash.Dash(__name__)
|
|
|
|
app.layout = html.Div([
|
|
html.H1("Complex Callback Test"),
|
|
html.Div(id="current-balance", children="$100.00"),
|
|
html.Div(id="session-duration", children="00:00:00"),
|
|
html.Div(id="status", children="Starting"),
|
|
dcc.Graph(id="chart"),
|
|
dcc.Interval(id="ultra-fast-interval", interval=1000, n_intervals=0)
|
|
])
|
|
|
|
@app.callback(
|
|
[
|
|
Output('current-balance', 'children'),
|
|
Output('session-duration', 'children'),
|
|
Output('status', 'children'),
|
|
Output('chart', 'figure')
|
|
],
|
|
[Input('ultra-fast-interval', 'n_intervals')]
|
|
)
|
|
def update_dashboard(n_intervals):
|
|
logger.info(f"Complex callback triggered: {n_intervals}")
|
|
|
|
import plotly.graph_objects as go
|
|
fig = go.Figure()
|
|
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3], mode='lines'))
|
|
fig.update_layout(template="plotly_dark")
|
|
|
|
return f"${100 + n_intervals:.2f}", f"00:00:{n_intervals:02d}", "Running", fig
|
|
|
|
logger.info("Complex callback registered successfully")
|
|
|
|
# Check if callback is in the callback map
|
|
logger.info(f"Callback map keys: {list(app.callback_map.keys())}")
|
|
|
|
return app
|
|
|
|
def test_dashboard_callback():
|
|
"""Test the exact dashboard callback structure"""
|
|
logger.info("Testing dashboard callback structure...")
|
|
|
|
try:
|
|
from core.data_provider import DataProvider
|
|
from core.enhanced_orchestrator import EnhancedTradingOrchestrator
|
|
|
|
app = dash.Dash(__name__)
|
|
|
|
# Minimal layout with dashboard elements
|
|
app.layout = html.Div([
|
|
html.H1("Dashboard Callback Test"),
|
|
html.Div(id="current-balance", children="$100.00"),
|
|
html.Div(id="session-duration", children="00:00:00"),
|
|
html.Div(id="open-positions", children="0"),
|
|
html.Div(id="live-pnl", children="$0.00"),
|
|
html.Div(id="win-rate", children="0%"),
|
|
html.Div(id="total-trades", children="0"),
|
|
html.Div(id="last-action", children="WAITING"),
|
|
html.Div(id="eth-price", children="Loading..."),
|
|
html.Div(id="btc-price", children="Loading..."),
|
|
dcc.Graph(id="main-eth-1s-chart"),
|
|
dcc.Graph(id="eth-1m-chart"),
|
|
dcc.Graph(id="eth-1h-chart"),
|
|
dcc.Graph(id="eth-1d-chart"),
|
|
dcc.Graph(id="btc-1s-chart"),
|
|
html.Div(id="actions-log", children="No actions yet"),
|
|
html.Div(id="debug-status", children="Debug info"),
|
|
dcc.Interval(id="ultra-fast-interval", interval=1000, n_intervals=0)
|
|
])
|
|
|
|
@app.callback(
|
|
[
|
|
Output('current-balance', 'children'),
|
|
Output('session-duration', 'children'),
|
|
Output('open-positions', 'children'),
|
|
Output('live-pnl', 'children'),
|
|
Output('win-rate', 'children'),
|
|
Output('total-trades', 'children'),
|
|
Output('last-action', 'children'),
|
|
Output('eth-price', 'children'),
|
|
Output('btc-price', 'children'),
|
|
Output('main-eth-1s-chart', 'figure'),
|
|
Output('eth-1m-chart', 'figure'),
|
|
Output('eth-1h-chart', 'figure'),
|
|
Output('eth-1d-chart', 'figure'),
|
|
Output('btc-1s-chart', 'figure'),
|
|
Output('actions-log', 'children'),
|
|
Output('debug-status', 'children')
|
|
],
|
|
[Input('ultra-fast-interval', 'n_intervals')]
|
|
)
|
|
def update_dashboard_test(n_intervals):
|
|
logger.info(f"Dashboard callback triggered: {n_intervals}")
|
|
|
|
import plotly.graph_objects as go
|
|
from datetime import datetime
|
|
|
|
# Create empty figure
|
|
empty_fig = go.Figure()
|
|
empty_fig.update_layout(template="plotly_dark")
|
|
|
|
debug_status = html.Div([
|
|
html.P(f"Test Callback #{n_intervals} at {datetime.now().strftime('%H:%M:%S')}")
|
|
])
|
|
|
|
return (
|
|
f"${100 + n_intervals:.2f}", # current-balance
|
|
f"00:00:{n_intervals:02d}", # session-duration
|
|
"0", # open-positions
|
|
f"${n_intervals:+.2f}", # live-pnl
|
|
"75%", # win-rate
|
|
str(n_intervals), # total-trades
|
|
"TEST", # last-action
|
|
"$3500.00", # eth-price
|
|
"$65000.00", # btc-price
|
|
empty_fig, # main-eth-1s-chart
|
|
empty_fig, # eth-1m-chart
|
|
empty_fig, # eth-1h-chart
|
|
empty_fig, # eth-1d-chart
|
|
empty_fig, # btc-1s-chart
|
|
f"Test action #{n_intervals}", # actions-log
|
|
debug_status # debug-status
|
|
)
|
|
|
|
logger.info("Dashboard callback registered successfully")
|
|
logger.info(f"Callback map keys: {list(app.callback_map.keys())}")
|
|
|
|
return app
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error testing dashboard callback: {e}")
|
|
import traceback
|
|
logger.error(f"Traceback: {traceback.format_exc()}")
|
|
return None
|
|
|
|
def main():
|
|
"""Main test function"""
|
|
logger.info("Starting callback registration tests...")
|
|
|
|
# Test 1: Simple callback
|
|
try:
|
|
simple_app = test_simple_callback()
|
|
logger.info("✅ Simple callback test passed")
|
|
except Exception as e:
|
|
logger.error(f"❌ Simple callback test failed: {e}")
|
|
|
|
# Test 2: Complex callback
|
|
try:
|
|
complex_app = test_complex_callback()
|
|
logger.info("✅ Complex callback test passed")
|
|
except Exception as e:
|
|
logger.error(f"❌ Complex callback test failed: {e}")
|
|
|
|
# Test 3: Dashboard callback
|
|
try:
|
|
dashboard_app = test_dashboard_callback()
|
|
if dashboard_app:
|
|
logger.info("✅ Dashboard callback test passed")
|
|
|
|
# Run the dashboard test
|
|
logger.info("Starting dashboard test server on port 8054...")
|
|
dashboard_app.run(host='127.0.0.1', port=8054, debug=True)
|
|
else:
|
|
logger.error("❌ Dashboard callback test failed")
|
|
except Exception as e:
|
|
logger.error(f"❌ Dashboard callback test failed: {e}")
|
|
import traceback
|
|
logger.error(f"Traceback: {traceback.format_exc()}")
|
|
|
|
if __name__ == "__main__":
|
|
main() |