3. 7 Enhance chart functionality with time range controls and stability improvements
- Updated `app_new.py` to run the application in debug mode for stability. - Introduced a new time range control panel in `dashboard/components/chart_controls.py`, allowing users to select predefined time ranges and custom date ranges. - Enhanced chart callbacks in `dashboard/callbacks/charts.py` to handle time range inputs, ensuring accurate market statistics and analysis based on user selections. - Implemented logic to preserve chart state during updates, preventing resets of zoom/pan settings. - Updated market statistics display to reflect the selected time range, improving user experience and data relevance. - Added a clear button for custom date ranges to reset selections easily. - Enhanced documentation to reflect the new time range features and usage guidelines.
This commit is contained in:
@@ -260,33 +260,50 @@ def get_supported_timeframes():
|
||||
|
||||
return ['5s', '1m', '15m', '1h'] # Fallback
|
||||
|
||||
def get_market_statistics(symbol: str, timeframe: str = "1h"):
|
||||
"""Calculate market statistics from recent data."""
|
||||
def get_market_statistics(symbol: str, timeframe: str = "1h", days_back: int = 1):
|
||||
"""Calculate market statistics from recent data over a specified period."""
|
||||
builder = ChartBuilder()
|
||||
candles = builder.fetch_market_data(symbol, timeframe, days_back=1)
|
||||
candles = builder.fetch_market_data(symbol, timeframe, days_back=days_back)
|
||||
|
||||
if not candles:
|
||||
return {'Price': 'N/A', '24h Change': 'N/A', '24h Volume': 'N/A', 'High 24h': 'N/A', 'Low 24h': 'N/A'}
|
||||
return {'Price': 'N/A', f'Change ({days_back}d)': 'N/A', f'Volume ({days_back}d)': 'N/A', f'High ({days_back}d)': 'N/A', f'Low ({days_back}d)': 'N/A'}
|
||||
|
||||
import pandas as pd
|
||||
df = pd.DataFrame(candles)
|
||||
latest = df.iloc[-1]
|
||||
current_price = float(latest['close'])
|
||||
|
||||
# Calculate 24h change
|
||||
# Calculate change over the period
|
||||
if len(df) > 1:
|
||||
price_24h_ago = float(df.iloc[0]['open'])
|
||||
change_percent = ((current_price - price_24h_ago) / price_24h_ago) * 100
|
||||
price_period_ago = float(df.iloc[0]['open'])
|
||||
change_percent = ((current_price - price_period_ago) / price_period_ago) * 100
|
||||
else:
|
||||
change_percent = 0
|
||||
|
||||
from .utils import format_price, format_volume
|
||||
|
||||
# Determine label for period (e.g., "24h", "7d", "1h")
|
||||
if days_back == 1/24:
|
||||
period_label = "1h"
|
||||
elif days_back == 4/24:
|
||||
period_label = "4h"
|
||||
elif days_back == 6/24:
|
||||
period_label = "6h"
|
||||
elif days_back == 12/24:
|
||||
period_label = "12h"
|
||||
elif days_back < 1: # For other fractional days, show as hours
|
||||
period_label = f"{int(days_back * 24)}h"
|
||||
elif days_back == 1:
|
||||
period_label = "24h" # Keep 24h for 1 day for clarity
|
||||
else:
|
||||
period_label = f"{days_back}d"
|
||||
|
||||
return {
|
||||
'Price': format_price(current_price, decimals=2),
|
||||
'24h Change': f"{'+' if change_percent >= 0 else ''}{change_percent:.2f}%",
|
||||
'24h Volume': format_volume(df['volume'].sum()),
|
||||
'High 24h': format_price(df['high'].max(), decimals=2),
|
||||
'Low 24h': format_price(df['low'].min(), decimals=2)
|
||||
f'Change ({period_label})': f"{'+' if change_percent >= 0 else ''}{change_percent:.2f}%",
|
||||
f'Volume ({period_label})': format_volume(df['volume'].sum()),
|
||||
f'High ({period_label})': format_price(df['high'].max(), decimals=2),
|
||||
f'Low ({period_label})': format_price(df['low'].min(), decimals=2)
|
||||
}
|
||||
|
||||
def check_data_availability(symbol: str, timeframe: str):
|
||||
@@ -472,4 +489,8 @@ def create_chart_with_indicators(symbol: str, timeframe: str,
|
||||
builder = ChartBuilder()
|
||||
return builder.create_chart_with_indicators(
|
||||
symbol, timeframe, overlay_indicators, subplot_indicators, days_back, **kwargs
|
||||
)
|
||||
)
|
||||
|
||||
def initialize_indicator_manager():
|
||||
# Implementation of initialize_indicator_manager function
|
||||
pass
|
||||
Reference in New Issue
Block a user