From 483fcf7ba9b7b31315ce38c759e6887ef544ad0d Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Tue, 11 Feb 2025 07:06:17 -0800 Subject: [PATCH] refactor: Update TradeEntry to support buy and sell orders with optional fields --- src/trading/journal.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/trading/journal.py b/src/trading/journal.py index d8bf2be..5791aa1 100644 --- a/src/trading/journal.py +++ b/src/trading/journal.py @@ -155,25 +155,30 @@ class TradeEntry: entry_date: datetime shares: int entry_price: float - target_price: float - stop_loss: float - strategy: str - order_type: str # New field for Market/Limit + target_price: Optional[float] # Made optional since sell orders don't need it + stop_loss: Optional[float] # Made optional since sell orders don't need it + strategy: Optional[str] # Made optional since sell orders might not need it + order_type: str # Market/Limit + direction: str # 'buy' or 'sell' followed_rules: Optional[bool] = None entry_reason: Optional[str] = None exit_price: Optional[float] = None exit_date: Optional[datetime] = None exit_reason: Optional[str] = None notes: Optional[str] = None - position_id: Optional[str] = None # New field to group related orders + position_id: Optional[str] = None @property - def expected_profit_loss(self) -> float: - return (self.target_price - self.entry_price) * self.shares + def expected_profit_loss(self) -> Optional[float]: + if self.direction == 'buy' and self.target_price: + return (self.target_price - self.entry_price) * self.shares + return None @property - def max_loss(self) -> float: - return (self.stop_loss - self.entry_price) * self.shares + def max_loss(self) -> Optional[float]: + if self.direction == 'buy' and self.stop_loss: + return (self.stop_loss - self.entry_price) * self.shares + return None @property def actual_profit_loss(self) -> Optional[float]: