feat: Enhance trade entry form to support buy and sell order workflows
This commit is contained in:
parent
c238bf45ed
commit
b9116a55a2
@ -166,34 +166,53 @@ def trading_journal_page():
|
||||
st.write(f"Total Shares: {pos['total_shares']}")
|
||||
st.write(f"Average Entry: ${pos['avg_entry_price']:.2f}")
|
||||
|
||||
add_to_existing = st.checkbox("Add to existing position")
|
||||
if add_to_existing:
|
||||
if direction == "Sell":
|
||||
position_id = st.selectbox(
|
||||
"Select Position ID",
|
||||
"Select Position to Exit",
|
||||
options=[pos['position_id'] for pos in existing_positions],
|
||||
key="position_select"
|
||||
)
|
||||
else:
|
||||
position_id = generate_position_id(ticker)
|
||||
else: # Buy
|
||||
add_to_existing = st.checkbox("Add to existing position")
|
||||
if add_to_existing:
|
||||
position_id = st.selectbox(
|
||||
"Select Position ID",
|
||||
options=[pos['position_id'] for pos in existing_positions],
|
||||
key="position_select"
|
||||
)
|
||||
else:
|
||||
position_id = generate_position_id(ticker)
|
||||
else:
|
||||
if direction == "Sell":
|
||||
st.error("No existing positions found for this ticker")
|
||||
st.stop()
|
||||
position_id = generate_position_id(ticker)
|
||||
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
shares = st.number_input("Number of Shares", min_value=1, step=1)
|
||||
entry_price = st.number_input("Entry Price", min_value=0.01, step=0.01)
|
||||
target_price = st.number_input("Target Price", min_value=0.01, step=0.01)
|
||||
if direction == "Buy":
|
||||
entry_price = st.number_input("Entry Price", min_value=0.01, step=0.01)
|
||||
else:
|
||||
entry_price = st.number_input("Exit Price", min_value=0.01, step=0.01)
|
||||
|
||||
with col2:
|
||||
stop_loss = st.number_input("Stop Loss", min_value=0.01, step=0.01)
|
||||
strategy = st.text_input("Strategy")
|
||||
if direction == "Buy":
|
||||
target_price = st.number_input("Target Price", min_value=0.01, step=0.01)
|
||||
stop_loss = st.number_input("Stop Loss", min_value=0.01, step=0.01)
|
||||
strategy = st.text_input("Strategy")
|
||||
else:
|
||||
exit_reason = st.text_area("Exit Reason", key="exit_reason")
|
||||
|
||||
order_type = st.selectbox("Order Type", ["Market", "Limit"], key="add_trade_order_type")
|
||||
|
||||
entry_date = st.date_input("Entry Date")
|
||||
entry_time = st.time_input("Entry Time")
|
||||
|
||||
followed_rules = st.checkbox("Followed Trading Rules")
|
||||
entry_reason = st.text_area("Entry Reason", key="add_trade_reason")
|
||||
if direction == "Buy":
|
||||
followed_rules = st.checkbox("Followed Trading Rules")
|
||||
entry_reason = st.text_area("Entry Reason", key="add_trade_reason")
|
||||
|
||||
notes = st.text_area("Notes", key="add_trade_notes")
|
||||
|
||||
if st.button("Add Trade"):
|
||||
@ -206,15 +225,16 @@ def trading_journal_page():
|
||||
entry_date=entry_datetime,
|
||||
shares=shares,
|
||||
entry_price=entry_price,
|
||||
target_price=target_price,
|
||||
stop_loss=stop_loss,
|
||||
strategy=strategy,
|
||||
target_price=target_price if direction == "Buy" else None,
|
||||
stop_loss=stop_loss if direction == "Buy" else None,
|
||||
strategy=strategy if direction == "Buy" else None,
|
||||
order_type=order_type,
|
||||
position_id=position_id,
|
||||
followed_rules=followed_rules,
|
||||
entry_reason=entry_reason,
|
||||
followed_rules=followed_rules if direction == "Buy" else None,
|
||||
entry_reason=entry_reason if direction == "Buy" else None,
|
||||
exit_reason=exit_reason if direction == "Sell" else None,
|
||||
notes=notes,
|
||||
direction=direction.lower() # Add direction parameter
|
||||
direction=direction.lower()
|
||||
)
|
||||
|
||||
add_trade(trade)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user