feat: Add debug print statements to trading journal page for trade entry tracking

This commit is contained in:
Bobby (aider) 2025-02-13 10:52:36 -08:00
parent 417747be86
commit 814a7db5de

View File

@ -202,8 +202,10 @@ def trading_journal_page():
with tab2: with tab2:
st.subheader("Add New Trade") st.subheader("Add New Trade")
print("\n--- Add Trade Tab ---") # Debug
ticker = st.text_input("Ticker Symbol").upper() ticker = st.text_input("Ticker Symbol").upper()
print(f"Ticker entered: {ticker}") # Debug
# Add direction selection # Add direction selection
direction = st.selectbox( direction = st.selectbox(
@ -211,31 +213,40 @@ def trading_journal_page():
["Buy", "Sell"], ["Buy", "Sell"],
key="trade_direction" key="trade_direction"
) )
print(f"Direction selected: {direction}") # Debug
if ticker: if ticker:
# Show existing positions for this ticker FIRST print(f"\nProcessing ticker {ticker}") # Debug
existing_positions = get_position_summary(ticker) existing_positions = get_position_summary(ticker)
print(f"Found existing positions: {existing_positions}") # Debug
# Handle position selection based on direction # Handle position selection based on direction
if direction == "Buy": if direction == "Buy":
if existing_positions: if existing_positions:
print(f"Processing existing positions for {ticker}") # Debug
st.write(f"Existing {ticker} Positions:") st.write(f"Existing {ticker} Positions:")
for pos in existing_positions: for pos in existing_positions:
print(f"Position details: {pos}") # Debug
st.write(f"Position ID: {pos['position_id']}") st.write(f"Position ID: {pos['position_id']}")
st.write(f"Total Shares: {pos['total_shares']}") st.write(f"Total Shares: {pos['total_shares']}")
st.write(f"Average Entry: ${pos['avg_entry_price']:.2f}") st.write(f"Average Entry: ${pos['avg_entry_price']:.2f}")
add_to_existing = st.checkbox("Add to existing position") add_to_existing = st.checkbox("Add to existing position")
print(f"Add to existing selected: {add_to_existing}") # Debug
if add_to_existing: if add_to_existing:
position_id = st.selectbox( position_id = st.selectbox(
"Select Position ID", "Select Position ID",
options=[pos['position_id'] for pos in existing_positions], options=[pos['position_id'] for pos in existing_positions],
key="position_select" key="position_select"
) )
print(f"Selected position ID: {position_id}") # Debug
else: else:
position_id = None # Will be generated later position_id = None
print("Creating new position") # Debug
else: else:
position_id = None # Will be generated later position_id = None
print("No existing positions found, creating new position") # Debug
else: # Sell else: # Sell
if not existing_positions: if not existing_positions:
st.error("No existing positions found for this ticker") st.error("No existing positions found for this ticker")
@ -288,8 +299,10 @@ def trading_journal_page():
if st.button("Add Trade"): if st.button("Add Trade"):
try: try:
print("\n--- Processing Add Trade ---") # Debug
entry_datetime = datetime.combine(entry_date, entry_time) entry_datetime = datetime.combine(entry_date, entry_time)
entry_datetime = pytz.timezone('US/Pacific').localize(entry_datetime) entry_datetime = pytz.timezone('US/Pacific').localize(entry_datetime)
print(f"Entry datetime: {entry_datetime}") # Debug
trade = TradeEntry( trade = TradeEntry(
ticker=ticker, ticker=ticker,
@ -308,10 +321,14 @@ def trading_journal_page():
direction=direction.lower() direction=direction.lower()
) )
print(f"Trade object created: {trade.__dict__}") # Debug
add_trade(trade) add_trade(trade)
print("Trade added successfully") # Debug
st.success("Trade added successfully!") st.success("Trade added successfully!")
st.query_params(rerun=True) st.query_params(rerun=True)
except Exception as e: except Exception as e:
print(f"Error adding trade: {str(e)}") # Debug
st.error(f"Error adding trade: {str(e)}") st.error(f"Error adding trade: {str(e)}")
with tab3: with tab3: