refactor: Optimize position handling logic in trading journal page
This commit is contained in:
parent
46c37e2f63
commit
417747be86
@ -213,23 +213,10 @@ def trading_journal_page():
|
|||||||
)
|
)
|
||||||
|
|
||||||
if ticker:
|
if ticker:
|
||||||
# Show existing positions for this ticker
|
# Show existing positions for this ticker FIRST
|
||||||
existing_positions = get_position_summary(ticker)
|
|
||||||
# Get entry date/time first
|
|
||||||
entry_date = st.date_input("Entry Date")
|
|
||||||
entry_time_str = st.text_input("Entry Time (HH:MM)", "09:30")
|
|
||||||
try:
|
|
||||||
entry_time = datetime.strptime(entry_time_str, "%H:%M").time()
|
|
||||||
entry_datetime = datetime.combine(entry_date, entry_time)
|
|
||||||
entry_datetime = pytz.timezone('US/Pacific').localize(entry_datetime)
|
|
||||||
except ValueError:
|
|
||||||
st.error("Please enter time in HH:MM format (e.g. 09:30)")
|
|
||||||
st.stop()
|
|
||||||
|
|
||||||
# Show existing positions for this ticker
|
|
||||||
existing_positions = get_position_summary(ticker)
|
existing_positions = get_position_summary(ticker)
|
||||||
|
|
||||||
# Always show the "Add to existing position" option for buys
|
# Handle position selection based on direction
|
||||||
if direction == "Buy":
|
if direction == "Buy":
|
||||||
if existing_positions:
|
if existing_positions:
|
||||||
st.write(f"Existing {ticker} Positions:")
|
st.write(f"Existing {ticker} Positions:")
|
||||||
@ -246,9 +233,9 @@ def trading_journal_page():
|
|||||||
key="position_select"
|
key="position_select"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
position_id = generate_position_id(ticker, entry_datetime)
|
position_id = None # Will be generated later
|
||||||
else:
|
else:
|
||||||
position_id = generate_position_id(ticker, entry_datetime)
|
position_id = None # Will be generated later
|
||||||
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")
|
||||||
@ -259,6 +246,21 @@ def trading_journal_page():
|
|||||||
key="position_select"
|
key="position_select"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Get entry date/time
|
||||||
|
entry_date = st.date_input("Entry Date")
|
||||||
|
entry_time_str = st.text_input("Entry Time (HH:MM)", "09:30")
|
||||||
|
try:
|
||||||
|
entry_time = datetime.strptime(entry_time_str, "%H:%M").time()
|
||||||
|
entry_datetime = datetime.combine(entry_date, entry_time)
|
||||||
|
entry_datetime = pytz.timezone('US/Pacific').localize(entry_datetime)
|
||||||
|
except ValueError:
|
||||||
|
st.error("Please enter time in HH:MM format (e.g. 09:30)")
|
||||||
|
st.stop()
|
||||||
|
|
||||||
|
# Generate position_id if needed
|
||||||
|
if position_id is None:
|
||||||
|
position_id = generate_position_id(ticker, entry_datetime)
|
||||||
|
|
||||||
col1, col2 = st.columns(2)
|
col1, col2 = st.columns(2)
|
||||||
with col1:
|
with col1:
|
||||||
shares = st.number_input("Number of Shares", min_value=1, step=1)
|
shares = st.number_input("Number of Shares", min_value=1, step=1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user