feat: Add comprehensive debug statements to trading journal page and data retrieval functions
This commit is contained in:
parent
7f1077a951
commit
dbb1393c08
@ -116,24 +116,34 @@ def plot_trade_history(trades):
|
|||||||
|
|
||||||
def trading_journal_page():
|
def trading_journal_page():
|
||||||
st.header("Trading Journal")
|
st.header("Trading Journal")
|
||||||
|
print("\n=== Starting Trading Journal Page ===") # Debug
|
||||||
|
|
||||||
# Tabs for different journal functions
|
# Tabs for different journal functions
|
||||||
tab1, tab2, tab3, tab4 = st.tabs(["Open Positions", "Add Trade", "Update Trade", "Trade History"])
|
tab1, tab2, tab3, tab4 = st.tabs(["Open Positions", "Add Trade", "Update Trade", "Trade History"])
|
||||||
|
|
||||||
with tab1:
|
with tab1:
|
||||||
st.subheader("Open Positions")
|
st.subheader("Open Positions")
|
||||||
|
print("\n--- Fetching Open Positions ---") # Debug
|
||||||
open_trades = get_open_trades()
|
open_trades = get_open_trades()
|
||||||
|
print(f"Retrieved {len(open_trades) if open_trades else 0} open trades") # Debug
|
||||||
|
print(f"Open trades {open_trades}") # Debug
|
||||||
|
|
||||||
open_summary = get_open_trades_summary()
|
open_summary = get_open_trades_summary()
|
||||||
|
print(f"Retrieved {len(open_summary) if open_summary else 0} position summaries") # Debug
|
||||||
|
print(f"Open summary {open_summary}") # Debug
|
||||||
|
|
||||||
if open_summary:
|
if open_summary:
|
||||||
# Get current prices
|
# Get current prices
|
||||||
unique_tickers = list(set(summary['ticker'] for summary in open_summary))
|
unique_tickers = list(set(summary['ticker'] for summary in open_summary))
|
||||||
|
print(f"Fetching prices for tickers: {unique_tickers}") # Debug
|
||||||
current_prices = get_current_prices(unique_tickers)
|
current_prices = get_current_prices(unique_tickers)
|
||||||
|
print(f"Retrieved current prices: {current_prices}") # Debug
|
||||||
|
|
||||||
total_portfolio_value = 0
|
total_portfolio_value = 0
|
||||||
total_paper_pl = 0
|
total_paper_pl = 0
|
||||||
|
|
||||||
for summary in open_summary:
|
for summary in open_summary:
|
||||||
|
print(f"\nProcessing summary for {summary['ticker']}") # Debug
|
||||||
with st.expander(f"{summary['ticker']} Summary"):
|
with st.expander(f"{summary['ticker']} Summary"):
|
||||||
ticker = summary['ticker']
|
ticker = summary['ticker']
|
||||||
avg_entry = summary['avg_entry_price']
|
avg_entry = summary['avg_entry_price']
|
||||||
@ -141,6 +151,12 @@ def trading_journal_page():
|
|||||||
total_shares = summary['total_shares']
|
total_shares = summary['total_shares']
|
||||||
position_value = avg_entry * total_shares
|
position_value = avg_entry * total_shares
|
||||||
|
|
||||||
|
print(f"Position details for {ticker}:") # Debug
|
||||||
|
print(f"- Shares: {total_shares}") # Debug
|
||||||
|
print(f"- Avg Entry: {avg_entry}") # Debug
|
||||||
|
print(f"- Current Price: {current_price}") # Debug
|
||||||
|
print(f"- Position Value: {position_value}") # Debug
|
||||||
|
|
||||||
col1, col2 = st.columns(2)
|
col1, col2 = st.columns(2)
|
||||||
with col1:
|
with col1:
|
||||||
st.metric("Total Shares", f"{total_shares:,}")
|
st.metric("Total Shares", f"{total_shares:,}")
|
||||||
@ -279,7 +295,10 @@ def trading_journal_page():
|
|||||||
|
|
||||||
with tab3:
|
with tab3:
|
||||||
st.subheader("Update Trade")
|
st.subheader("Update Trade")
|
||||||
|
print("\n--- Update Trade Tab ---") # Debug
|
||||||
open_trades = get_open_trades()
|
open_trades = get_open_trades()
|
||||||
|
print(f"Retrieved {len(open_trades) if open_trades else 0} trades for update tab") # Debug
|
||||||
|
print(f"Update tab trades {open_trades}") # Debug
|
||||||
|
|
||||||
if open_trades:
|
if open_trades:
|
||||||
trade_id = st.selectbox(
|
trade_id = st.selectbox(
|
||||||
@ -290,6 +309,7 @@ def trading_journal_page():
|
|||||||
)
|
)
|
||||||
|
|
||||||
trade = next(t for t in open_trades if t['id'] == trade_id)
|
trade = next(t for t in open_trades if t['id'] == trade_id)
|
||||||
|
print(f"\nSelected trade for update: {trade}") # Debug
|
||||||
|
|
||||||
col1, col2 = st.columns(2)
|
col1, col2 = st.columns(2)
|
||||||
with col1:
|
with col1:
|
||||||
@ -342,9 +362,20 @@ def trading_journal_page():
|
|||||||
'notes': new_notes
|
'notes': new_notes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print("\n--- Processing Trade Update ---") # Debug
|
||||||
|
print(f"Update data being sent: {updates}") # Debug
|
||||||
|
|
||||||
update_trade(trade_id, updates)
|
update_trade(trade_id, updates)
|
||||||
|
print("Trade update completed") # Debug
|
||||||
|
|
||||||
st.success("Trade updated successfully!")
|
st.success("Trade updated successfully!")
|
||||||
st.experimental_rerun()
|
print("Clearing session state and triggering rerun") # Debug
|
||||||
|
|
||||||
|
# Clear session state
|
||||||
|
for key in st.session_state.keys():
|
||||||
|
del st.session_state[key]
|
||||||
|
|
||||||
|
st.rerun()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.error(f"Error updating trade: {str(e)}")
|
st.error(f"Error updating trade: {str(e)}")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user