fix: stage missing code review fixes (7 files)
Files were edited but not staged in earlier commits: - adaptive_rhythm_manager.py: mt→mt5, pytz→timezone, get_volatility_level, shutdown() - check_market_regime.py: ADX_THRESHOLD, Wilder EWM, try/finally, UTC timestamp, sys import - check_system_status.py: remove duplicate cursor.execute - drawdown_protection.py: float(inf), persist pause state, DB save_setting, Markdown fix - performance_analysis.py: KeyError export fix, profit factor, drawdown positive, SQL filter - performance_analysis_simple.py: fromisoformat, numeric bin sort, profit factor - trading_dashboard.py: st.rerun(), session_state auto-refresh, pathlib DB path, errors=coerce Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+34
-35
@@ -10,6 +10,7 @@ import pandas as pd
|
||||
from datetime import datetime, timedelta
|
||||
import plotly.express as px
|
||||
import plotly.graph_objects as go
|
||||
from pathlib import Path
|
||||
|
||||
# ==========================================
|
||||
# PAGE CONFIG
|
||||
@@ -25,9 +26,14 @@ st.set_page_config(
|
||||
# DATABASE CONNECTION
|
||||
# ==========================================
|
||||
|
||||
DB_PATH = Path(__file__).parent / "trading_bot.db"
|
||||
|
||||
@st.cache_resource
|
||||
def get_connection():
|
||||
return sqlite3.connect("trading_bot.db", check_same_thread=False)
|
||||
if not DB_PATH.exists():
|
||||
st.error(f"Database not found: {DB_PATH}")
|
||||
st.stop()
|
||||
return sqlite3.connect(str(DB_PATH), check_same_thread=False)
|
||||
|
||||
conn = get_connection()
|
||||
|
||||
@@ -43,10 +49,10 @@ col1, col2, col3 = st.columns([1, 1, 2])
|
||||
with col1:
|
||||
if st.button("🔄 Refresh Data"):
|
||||
st.cache_data.clear()
|
||||
st.experimental_rerun()
|
||||
st.rerun()
|
||||
|
||||
with col2:
|
||||
auto_refresh = st.checkbox("Auto-refresh (30s)")
|
||||
auto_refresh = st.toggle("Auto-refresh (30s)")
|
||||
|
||||
with col3:
|
||||
trade_filter = st.selectbox(
|
||||
@@ -56,10 +62,14 @@ with col3:
|
||||
)
|
||||
|
||||
if auto_refresh:
|
||||
st.markdown("*Auto-refreshing every 30 seconds...*")
|
||||
import time
|
||||
time.sleep(30)
|
||||
st.experimental_rerun()
|
||||
if "last_refresh" not in st.session_state:
|
||||
st.session_state.last_refresh = datetime.now()
|
||||
elapsed = (datetime.now() - st.session_state.last_refresh).total_seconds()
|
||||
if elapsed >= 30:
|
||||
st.session_state.last_refresh = datetime.now()
|
||||
st.rerun()
|
||||
else:
|
||||
st.markdown(f"*Auto-refresh in {30 - int(elapsed)}s...*")
|
||||
|
||||
# ==========================================
|
||||
# LOAD DATA
|
||||
@@ -69,38 +79,27 @@ if auto_refresh:
|
||||
def load_all_trades():
|
||||
query = """
|
||||
SELECT
|
||||
ticket,
|
||||
position_id,
|
||||
symbol,
|
||||
strategy_name,
|
||||
type,
|
||||
volume,
|
||||
entry_price,
|
||||
sl_price,
|
||||
tp_price,
|
||||
entry_time,
|
||||
exit_time,
|
||||
session,
|
||||
regime,
|
||||
quality,
|
||||
confidence,
|
||||
timeframe_alignment,
|
||||
risk_amount,
|
||||
risk_pct,
|
||||
net_profit,
|
||||
profit_pct,
|
||||
rr_ratio,
|
||||
status,
|
||||
exit_reason
|
||||
ticket, position_id, symbol, strategy_name, type, volume,
|
||||
entry_price, sl_price, tp_price, entry_time, exit_time,
|
||||
session, regime, quality, confidence, timeframe_alignment,
|
||||
risk_amount, risk_pct, net_profit, profit_pct, rr_ratio,
|
||||
status, exit_reason
|
||||
FROM trades
|
||||
ORDER BY entry_time DESC
|
||||
"""
|
||||
return pd.read_sql_query(query, conn)
|
||||
try:
|
||||
return pd.read_sql_query(query, conn)
|
||||
except Exception as e:
|
||||
st.error(f"Error loading trades: {e}")
|
||||
return pd.DataFrame()
|
||||
|
||||
@st.cache_data(ttl=30)
|
||||
def load_bot_status():
|
||||
query = "SELECT * FROM bot_status ORDER BY timestamp DESC LIMIT 1"
|
||||
return pd.read_sql_query(query, conn)
|
||||
try:
|
||||
return pd.read_sql_query("SELECT * FROM bot_status ORDER BY timestamp DESC LIMIT 1", conn)
|
||||
except Exception as e:
|
||||
st.error(f"Error loading bot status: {e}")
|
||||
return pd.DataFrame()
|
||||
|
||||
# Load data
|
||||
df_trades_raw = load_all_trades()
|
||||
@@ -219,7 +218,7 @@ st.subheader("⏰ Trades by Hour (UTC)")
|
||||
|
||||
if not df_trades.empty:
|
||||
# Extract hour from entry_time (handle both ISO8601 and standard format)
|
||||
df_trades['hour_utc'] = pd.to_datetime(df_trades['entry_time'], format='mixed').dt.hour
|
||||
df_trades['hour_utc'] = pd.to_datetime(df_trades['entry_time'], errors='coerce').dt.hour
|
||||
|
||||
# Count trades by hour
|
||||
hourly_dist = df_trades.groupby('hour_utc').size().reset_index(name='count')
|
||||
@@ -338,7 +337,7 @@ st.subheader("💰 Cumulative Profit Over Time")
|
||||
|
||||
if closed_trades > 0:
|
||||
profit_timeline = df_trades[df_trades['status'] == 'closed'].copy()
|
||||
profit_timeline['exit_time'] = pd.to_datetime(profit_timeline['exit_time'], format='mixed')
|
||||
profit_timeline['exit_time'] = pd.to_datetime(profit_timeline['exit_time'], errors='coerce')
|
||||
profit_timeline = profit_timeline.sort_values('exit_time')
|
||||
profit_timeline['cumulative_profit'] = profit_timeline['net_profit'].cumsum()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user