all changes done over the last 2 weeks

This commit is contained in:
2025-12-16 22:02:15 +01:00
parent 596718e30b
commit cbd6584db5
54 changed files with 25684 additions and 116 deletions
+29 -6
View File
@@ -38,8 +38,8 @@ conn = get_connection()
st.title("📊 Trading Bot Dashboard V1.8")
st.markdown("---")
# Refresh button
col1, col2, col3 = st.columns([1, 1, 4])
# Controls
col1, col2, col3 = st.columns([1, 1, 2])
with col1:
if st.button("🔄 Refresh Data"):
st.cache_data.clear()
@@ -48,6 +48,13 @@ with col1:
with col2:
auto_refresh = st.checkbox("Auto-refresh (30s)")
with col3:
trade_filter = st.selectbox(
"📊 Filter Trades:",
["All Trades", "Live Trades Only", "Historical Only"],
index=1 # Default to "Live Trades Only"
)
if auto_refresh:
st.markdown("*Auto-refreshing every 30 seconds...*")
import time
@@ -96,9 +103,25 @@ def load_bot_status():
return pd.read_sql_query(query, conn)
# Load data
df_trades = load_all_trades()
df_trades_raw = load_all_trades()
df_status = load_bot_status()
# ==========================================
# APPLY TRADE FILTER
# ==========================================
if trade_filter == "Live Trades Only":
df_trades = df_trades_raw[df_trades_raw['status'] != 'historical'].copy()
st.info(f"📊 Showing **Live Trades Only** (excluding {(df_trades_raw['status'] == 'historical').sum()} historical imports)")
elif trade_filter == "Historical Only":
df_trades = df_trades_raw[df_trades_raw['status'] == 'historical'].copy()
st.info(f"📚 Showing **Historical Trades Only** ({len(df_trades)} trades)")
else: # All Trades
df_trades = df_trades_raw.copy()
live_count = (df_trades['status'] != 'historical').sum()
hist_count = (df_trades['status'] == 'historical').sum()
st.info(f"📊 Showing **All Trades** ({live_count} live + {hist_count} historical)")
# ==========================================
# TOP METRICS
# ==========================================
@@ -195,8 +218,8 @@ st.markdown("---")
st.subheader("⏰ Trades by Hour (UTC)")
if not df_trades.empty:
# Extract hour from entry_time
df_trades['hour_utc'] = pd.to_datetime(df_trades['entry_time']).dt.hour
# 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
# Count trades by hour
hourly_dist = df_trades.groupby('hour_utc').size().reset_index(name='count')
@@ -315,7 +338,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'])
profit_timeline['exit_time'] = pd.to_datetime(profit_timeline['exit_time'], format='mixed')
profit_timeline = profit_timeline.sort_values('exit_time')
profit_timeline['cumulative_profit'] = profit_timeline['net_profit'].cumsum()