Remove deprecated app_new.py and consolidate main application logic into main.py
- Deleted `app_new.py`, which was previously the main entry point for the dashboard application, to streamline the codebase. - Consolidated the application initialization and callback registration logic into `main.py`, enhancing modularity and maintainability. - Updated the logging and error handling practices in `main.py` to ensure consistent application behavior and improved debugging capabilities. These changes simplify the application structure, aligning with project standards for modularity and maintainability.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from datetime import datetime
|
||||
from typing import List, Optional, Dict, Any
|
||||
import pandas as pd
|
||||
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
@@ -136,4 +137,62 @@ class MarketDataRepository(BaseRepository):
|
||||
|
||||
except Exception as e:
|
||||
self.log_error(f"Error retrieving latest candle for {symbol} {timeframe}: {e}")
|
||||
raise DatabaseOperationError(f"Failed to retrieve latest candle: {e}")
|
||||
raise DatabaseOperationError(f"Failed to retrieve latest candle: {e}")
|
||||
|
||||
def get_candles_df(self,
|
||||
symbol: str,
|
||||
timeframe: str,
|
||||
start_time: datetime,
|
||||
end_time: datetime,
|
||||
exchange: str = "okx") -> pd.DataFrame:
|
||||
"""
|
||||
Retrieve candles from the database as a Pandas DataFrame using the ORM.
|
||||
|
||||
Args:
|
||||
symbol: The trading symbol (e.g., 'BTC-USDT').
|
||||
timeframe: The timeframe of the candles (e.g., '1h').
|
||||
start_time: The start datetime for the data.
|
||||
end_time: The end datetime for the data.
|
||||
exchange: The exchange name (default: 'okx').
|
||||
|
||||
Returns:
|
||||
A Pandas DataFrame containing the fetched candles, or an empty DataFrame if no data is found.
|
||||
"""
|
||||
try:
|
||||
with self.get_session() as session:
|
||||
query = (
|
||||
session.query(MarketData)
|
||||
.filter(
|
||||
MarketData.exchange == exchange,
|
||||
MarketData.symbol == symbol,
|
||||
MarketData.timeframe == timeframe,
|
||||
MarketData.timestamp >= start_time,
|
||||
MarketData.timestamp <= end_time
|
||||
)
|
||||
.order_by(MarketData.timestamp.asc())
|
||||
)
|
||||
|
||||
# Convert query results to a list of dictionaries, then to DataFrame
|
||||
results = [
|
||||
{
|
||||
"timestamp": r.timestamp,
|
||||
"open": float(r.open),
|
||||
"high": float(r.high),
|
||||
"low": float(r.low),
|
||||
"close": float(r.close),
|
||||
"volume": float(r.volume),
|
||||
"trades_count": int(r.trades_count) if r.trades_count else 0
|
||||
} for r in query.all()
|
||||
]
|
||||
|
||||
df = pd.DataFrame(results)
|
||||
if not df.empty:
|
||||
df['timestamp'] = pd.to_datetime(df['timestamp'])
|
||||
df = df.set_index('timestamp')
|
||||
|
||||
self.log_debug(f"Retrieved {len(df)} candles as DataFrame for {symbol} {timeframe}")
|
||||
return df
|
||||
|
||||
except Exception as e:
|
||||
self.log_error(f"Error retrieving candles as DataFrame: {e}")
|
||||
raise DatabaseOperationError(f"Failed to retrieve candles as DataFrame: {e}")
|
||||
Reference in New Issue
Block a user