refactor: Update TradeEntry to support buy and sell orders with optional fields
This commit is contained in:
parent
77a067a22e
commit
483fcf7ba9
@ -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]:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user