stored
This commit is contained in:
@@ -84,7 +84,29 @@ class AnnotationDashboard:
|
||||
def __init__(self):
|
||||
"""Initialize the dashboard"""
|
||||
# Load configuration
|
||||
self.config = get_config() if get_config else {}
|
||||
try:
|
||||
# Always try YAML loading first since get_config might not work in standalone mode
|
||||
import yaml
|
||||
with open('config.yaml', 'r') as f:
|
||||
self.config = yaml.safe_load(f)
|
||||
logger.info(f"Loaded config via YAML: {len(self.config)} keys")
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not load config via YAML: {e}")
|
||||
try:
|
||||
# Fallback to get_config if available
|
||||
if get_config:
|
||||
self.config = get_config()
|
||||
logger.info(f"Loaded config via get_config: {len(self.config)} keys")
|
||||
else:
|
||||
raise Exception("get_config not available")
|
||||
except Exception as e2:
|
||||
logger.warning(f"Could not load config via get_config: {e2}")
|
||||
# Final fallback config with SOL/USDT
|
||||
self.config = {
|
||||
'symbols': ['ETH/USDT', 'BTC/USDT', 'SOL/USDT'],
|
||||
'timeframes': ['1s', '1m', '1h', '1d']
|
||||
}
|
||||
logger.info("Using fallback config")
|
||||
|
||||
# Initialize Flask app
|
||||
self.server = Flask(
|
||||
@@ -207,10 +229,15 @@ class AnnotationDashboard:
|
||||
|
||||
logger.info(f"Loading dashboard with {len(annotations_data)} existing annotations")
|
||||
|
||||
# Get symbols and timeframes from config
|
||||
symbols = self.config.get('symbols', ['ETH/USDT', 'BTC/USDT'])
|
||||
timeframes = self.config.get('timeframes', ['1s', '1m', '1h', '1d'])
|
||||
|
||||
# Prepare template data
|
||||
template_data = {
|
||||
'current_symbol': 'ETH/USDT',
|
||||
'timeframes': ['1s', '1m', '1h', '1d'],
|
||||
'current_symbol': symbols[0] if symbols else 'ETH/USDT', # Use first symbol as default
|
||||
'symbols': symbols,
|
||||
'timeframes': timeframes,
|
||||
'annotations': annotations_data
|
||||
}
|
||||
|
||||
@@ -328,59 +355,36 @@ class AnnotationDashboard:
|
||||
try:
|
||||
data = request.get_json()
|
||||
|
||||
# Capture market state at entry and exit times
|
||||
# Capture market state at entry and exit times using data provider
|
||||
entry_market_state = {}
|
||||
exit_market_state = {}
|
||||
|
||||
if self.data_loader:
|
||||
if self.data_provider:
|
||||
try:
|
||||
# Parse timestamps
|
||||
entry_time = datetime.fromisoformat(data['entry']['timestamp'].replace('Z', '+00:00'))
|
||||
exit_time = datetime.fromisoformat(data['exit']['timestamp'].replace('Z', '+00:00'))
|
||||
|
||||
# Fetch market data for all timeframes at entry time
|
||||
timeframes = ['1s', '1m', '1h', '1d']
|
||||
for tf in timeframes:
|
||||
df = self.data_loader.get_data(
|
||||
symbol=data['symbol'],
|
||||
timeframe=tf,
|
||||
end_time=entry_time,
|
||||
limit=100
|
||||
)
|
||||
|
||||
if df is not None and not df.empty:
|
||||
entry_market_state[f'ohlcv_{tf}'] = {
|
||||
'timestamps': df.index.strftime('%Y-%m-%d %H:%M:%S').tolist(),
|
||||
'open': df['open'].tolist(),
|
||||
'high': df['high'].tolist(),
|
||||
'low': df['low'].tolist(),
|
||||
'close': df['close'].tolist(),
|
||||
'volume': df['volume'].tolist()
|
||||
}
|
||||
# Use the new data provider method to get market state at entry time
|
||||
entry_market_state = self.data_provider.get_market_state_at_time(
|
||||
symbol=data['symbol'],
|
||||
timestamp=entry_time,
|
||||
context_window_minutes=5
|
||||
)
|
||||
|
||||
# Fetch market data at exit time
|
||||
for tf in timeframes:
|
||||
df = self.data_loader.get_data(
|
||||
symbol=data['symbol'],
|
||||
timeframe=tf,
|
||||
end_time=exit_time,
|
||||
limit=100
|
||||
)
|
||||
|
||||
if df is not None and not df.empty:
|
||||
exit_market_state[f'ohlcv_{tf}'] = {
|
||||
'timestamps': df.index.strftime('%Y-%m-%d %H:%M:%S').tolist(),
|
||||
'open': df['open'].tolist(),
|
||||
'high': df['high'].tolist(),
|
||||
'low': df['low'].tolist(),
|
||||
'close': df['close'].tolist(),
|
||||
'volume': df['volume'].tolist()
|
||||
}
|
||||
# Use the new data provider method to get market state at exit time
|
||||
exit_market_state = self.data_provider.get_market_state_at_time(
|
||||
symbol=data['symbol'],
|
||||
timestamp=exit_time,
|
||||
context_window_minutes=5
|
||||
)
|
||||
|
||||
logger.info(f"Captured market state: {len(entry_market_state)} timeframes at entry, {len(exit_market_state)} at exit")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error capturing market state: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
# Create annotation with market context
|
||||
annotation = self.annotation_manager.create_annotation(
|
||||
@@ -456,6 +460,103 @@ class AnnotationDashboard:
|
||||
}
|
||||
})
|
||||
|
||||
@self.server.route('/api/clear-all-annotations', methods=['POST'])
|
||||
def clear_all_annotations():
|
||||
"""Clear all annotations"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
symbol = data.get('symbol', None)
|
||||
|
||||
# Get current annotations count
|
||||
annotations = self.annotation_manager.get_annotations(symbol=symbol)
|
||||
deleted_count = len(annotations)
|
||||
|
||||
if deleted_count == 0:
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'deleted_count': 0,
|
||||
'message': 'No annotations to clear'
|
||||
})
|
||||
|
||||
# Clear all annotations
|
||||
for annotation in annotations:
|
||||
annotation_id = annotation.annotation_id if hasattr(annotation, 'annotation_id') else annotation.get('annotation_id')
|
||||
self.annotation_manager.delete_annotation(annotation_id)
|
||||
|
||||
logger.info(f"Cleared {deleted_count} annotations")
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'deleted_count': deleted_count,
|
||||
'message': f'Cleared {deleted_count} annotations'
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error clearing all annotations: {e}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': {
|
||||
'code': 'CLEAR_ALL_ANNOTATIONS_ERROR',
|
||||
'message': str(e)
|
||||
}
|
||||
})
|
||||
|
||||
@self.server.route('/api/refresh-data', methods=['POST'])
|
||||
def refresh_data():
|
||||
"""Refresh chart data from data provider"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
symbol = data.get('symbol', 'ETH/USDT')
|
||||
timeframes = data.get('timeframes', ['1s', '1m', '1h', '1d'])
|
||||
|
||||
logger.info(f"Refreshing data for {symbol} with timeframes: {timeframes}")
|
||||
|
||||
# Force refresh data from data provider
|
||||
chart_data = {}
|
||||
|
||||
if self.data_provider:
|
||||
for timeframe in timeframes:
|
||||
try:
|
||||
# Force refresh by setting refresh=True
|
||||
df = self.data_provider.get_historical_data(
|
||||
symbol=symbol,
|
||||
timeframe=timeframe,
|
||||
limit=1000,
|
||||
refresh=True
|
||||
)
|
||||
|
||||
if df is not None and not df.empty:
|
||||
chart_data[timeframe] = {
|
||||
'timestamps': df.index.strftime('%Y-%m-%d %H:%M:%S').tolist(),
|
||||
'open': df['open'].tolist(),
|
||||
'high': df['high'].tolist(),
|
||||
'low': df['low'].tolist(),
|
||||
'close': df['close'].tolist(),
|
||||
'volume': df['volume'].tolist()
|
||||
}
|
||||
logger.info(f"Refreshed {timeframe}: {len(df)} candles")
|
||||
else:
|
||||
logger.warning(f"No data available for {timeframe}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error refreshing {timeframe} data: {e}")
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'chart_data': chart_data,
|
||||
'message': f'Refreshed data for {symbol}'
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error refreshing data: {e}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': {
|
||||
'code': 'REFRESH_DATA_ERROR',
|
||||
'message': str(e)
|
||||
}
|
||||
})
|
||||
|
||||
@self.server.route('/api/generate-test-case', methods=['POST'])
|
||||
def generate_test_case():
|
||||
"""Generate test case from annotation"""
|
||||
|
||||
Reference in New Issue
Block a user