feat: Add CSV report viewing functionality to technical scanner page
This commit is contained in:
parent
e001d2e766
commit
099c8b353e
@ -18,6 +18,30 @@ def init_session_state():
|
||||
if 'page' not in st.session_state:
|
||||
st.session_state.page = 'Trading Journal'
|
||||
|
||||
def load_scanner_reports():
|
||||
"""Load and return available scanner reports"""
|
||||
import os
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
|
||||
reports = []
|
||||
reports_dir = "scanner_results"
|
||||
|
||||
if os.path.exists(reports_dir):
|
||||
for file in os.listdir(reports_dir):
|
||||
if file.endswith(".csv"):
|
||||
file_path = os.path.join(reports_dir, file)
|
||||
# Get file creation time
|
||||
created = datetime.fromtimestamp(os.path.getctime(file_path))
|
||||
reports.append({
|
||||
'name': file,
|
||||
'path': file_path,
|
||||
'created': created
|
||||
})
|
||||
|
||||
# Sort by creation time, newest first
|
||||
return sorted(reports, key=lambda x: x['created'], reverse=True)
|
||||
|
||||
def format_datetime(dt):
|
||||
"""Format datetime for display"""
|
||||
if dt:
|
||||
@ -269,41 +293,78 @@ def trading_journal_page():
|
||||
def technical_scanner_page():
|
||||
st.header("Technical Scanner")
|
||||
|
||||
scanner_type = st.selectbox(
|
||||
"Select Scanner",
|
||||
["SunnyBands", "ATR-EMA", "ATR-EMA v2"]
|
||||
)
|
||||
# Create tabs for scanner and reports
|
||||
scanner_tab, reports_tab = st.tabs(["Run Scanner", "View Reports"])
|
||||
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
min_price = st.number_input("Minimum Price", value=5.0, step=0.1)
|
||||
max_price = st.number_input("Maximum Price", value=100.0, step=0.1)
|
||||
with scanner_tab:
|
||||
scanner_type = st.selectbox(
|
||||
"Select Scanner",
|
||||
["SunnyBands", "ATR-EMA", "ATR-EMA v2"]
|
||||
)
|
||||
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
min_price = st.number_input("Minimum Price", value=5.0, step=0.1)
|
||||
max_price = st.number_input("Maximum Price", value=100.0, step=0.1)
|
||||
|
||||
with col2:
|
||||
min_volume = st.number_input("Minimum Volume", value=500000, step=100000)
|
||||
portfolio_size = st.number_input("Portfolio Size", value=100000.0, step=1000.0)
|
||||
|
||||
if st.button("Run Scanner"):
|
||||
with st.spinner("Running scanner..."):
|
||||
try:
|
||||
signals = run_technical_scanner(scanner_type.lower().replace(" ", "_"))
|
||||
if signals:
|
||||
st.success(f"Found {len(signals)} signals")
|
||||
for signal in signals:
|
||||
with st.expander(f"{signal['ticker']} - ${signal['entry_price']:.2f}"):
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
st.metric("Entry Price", f"${signal['entry_price']:.2f}")
|
||||
st.metric("Target", f"${signal['target_price']:.2f}")
|
||||
st.metric("Stop Loss", f"${signal['stop_loss']:.2f}")
|
||||
with col2:
|
||||
st.metric("Shares", signal['shares'])
|
||||
st.metric("Position Size", f"${signal['position_size']:.2f}")
|
||||
st.metric("Risk Amount", f"${abs(signal['risk_amount']):.2f}")
|
||||
else:
|
||||
st.info("No signals found")
|
||||
except Exception as e:
|
||||
st.error(f"Error running scanner: {str(e)}")
|
||||
|
||||
with col2:
|
||||
min_volume = st.number_input("Minimum Volume", value=500000, step=100000)
|
||||
portfolio_size = st.number_input("Portfolio Size", value=100000.0, step=1000.0)
|
||||
|
||||
if st.button("Run Scanner"):
|
||||
with st.spinner("Running scanner..."):
|
||||
try:
|
||||
signals = run_technical_scanner(scanner_type.lower().replace(" ", "_"))
|
||||
if signals:
|
||||
st.success(f"Found {len(signals)} signals")
|
||||
for signal in signals:
|
||||
with st.expander(f"{signal['ticker']} - ${signal['entry_price']:.2f}"):
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
st.metric("Entry Price", f"${signal['entry_price']:.2f}")
|
||||
st.metric("Target", f"${signal['target_price']:.2f}")
|
||||
st.metric("Stop Loss", f"${signal['stop_loss']:.2f}")
|
||||
with col2:
|
||||
st.metric("Shares", signal['shares'])
|
||||
st.metric("Position Size", f"${signal['position_size']:.2f}")
|
||||
st.metric("Risk Amount", f"${abs(signal['risk_amount']):.2f}")
|
||||
else:
|
||||
st.info("No signals found")
|
||||
except Exception as e:
|
||||
st.error(f"Error running scanner: {str(e)}")
|
||||
with reports_tab:
|
||||
st.subheader("Scanner Reports")
|
||||
|
||||
reports = load_scanner_reports()
|
||||
if reports:
|
||||
# Create a selectbox to choose the report
|
||||
selected_report = st.selectbox(
|
||||
"Select Report",
|
||||
options=reports,
|
||||
format_func=lambda x: f"{x['name']} ({x['created'].strftime('%Y-%m-%d %H:%M')})"
|
||||
)
|
||||
|
||||
if selected_report:
|
||||
try:
|
||||
# Load and display the CSV
|
||||
df = pd.read_csv(selected_report['path'])
|
||||
|
||||
# Add download button
|
||||
st.download_button(
|
||||
label="Download Report",
|
||||
data=df.to_csv(index=False),
|
||||
file_name=selected_report['name'],
|
||||
mime='text/csv'
|
||||
)
|
||||
|
||||
# Display the dataframe
|
||||
st.dataframe(df)
|
||||
|
||||
except Exception as e:
|
||||
st.error(f"Error loading report: {str(e)}")
|
||||
else:
|
||||
st.info("No scanner reports found")
|
||||
|
||||
def main():
|
||||
st.set_page_config(page_title="Trading System", layout="wide")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user