feat: Update position ID generation to use trade entry datetime

This commit is contained in:
Bobby (aider) 2025-02-13 10:09:53 -08:00
parent b3ac7c1705
commit ef762d2132
2 changed files with 16 additions and 5 deletions

View File

@ -206,12 +206,12 @@ def trading_journal_page():
key="position_select" key="position_select"
) )
else: else:
position_id = generate_position_id(ticker) position_id = generate_position_id(ticker, entry_datetime)
else: else:
if direction == "Sell": if direction == "Sell":
st.error("No existing positions found for this ticker") st.error("No existing positions found for this ticker")
st.stop() st.stop()
position_id = generate_position_id(ticker) position_id = generate_position_id(ticker, entry_datetime)
col1, col2 = st.columns(2) col1, col2 = st.columns(2)
with col1: with col1:

View File

@ -298,9 +298,20 @@ def generate_id() -> int:
"""Generate a unique ID for the trade""" """Generate a unique ID for the trade"""
return int(datetime.now().timestamp() * 1000) return int(datetime.now().timestamp() * 1000)
def generate_position_id(ticker: str) -> str: def generate_position_id(ticker: str, entry_date: datetime = None) -> str:
"""Generate a unique position ID for grouping related trades""" """
timestamp = datetime.now().strftime("%Y%m%d%H%M%S") Generate a unique position ID for grouping related trades
Args:
ticker (str): Stock ticker symbol
entry_date (datetime, optional): Entry date for the trade
Returns:
str: Position ID in format TICKER_YYYYMMDDHHMMSS
"""
if entry_date is None:
entry_date = datetime.now()
timestamp = entry_date.strftime("%Y%m%d%H%M%S")
return f"{ticker}_{timestamp}" return f"{ticker}_{timestamp}"
def get_position_summary(ticker: str) -> dict: def get_position_summary(ticker: str) -> dict: