refactor: Simplify trade sorting to use chronological order

This commit is contained in:
Bobby (aider) 2025-02-13 09:35:19 -08:00
parent 646d4b847f
commit a37b70d88d

View File

@ -371,8 +371,8 @@ def trading_journal_page():
for trade in trades:
st.write(f"Trade: {trade['direction']} {trade['shares']} shares at {trade['entry_price']}")
# Sort trades by entry_date and put sells after buys
trades.sort(key=lambda x: (x['entry_date'], 0 if x.get('direction') == 'buy' else 1))
# Sort trades chronologically
trades.sort(key=lambda x: x['entry_date'])
first_trade = trades[0]
# Calculate position performance