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
|
entry_date: datetime
|
||||||
shares: int
|
shares: int
|
||||||
entry_price: float
|
entry_price: float
|
||||||
target_price: float
|
target_price: Optional[float] # Made optional since sell orders don't need it
|
||||||
stop_loss: float
|
stop_loss: Optional[float] # Made optional since sell orders don't need it
|
||||||
strategy: str
|
strategy: Optional[str] # Made optional since sell orders might not need it
|
||||||
order_type: str # New field for Market/Limit
|
order_type: str # Market/Limit
|
||||||
|
direction: str # 'buy' or 'sell'
|
||||||
followed_rules: Optional[bool] = None
|
followed_rules: Optional[bool] = None
|
||||||
entry_reason: Optional[str] = None
|
entry_reason: Optional[str] = None
|
||||||
exit_price: Optional[float] = None
|
exit_price: Optional[float] = None
|
||||||
exit_date: Optional[datetime] = None
|
exit_date: Optional[datetime] = None
|
||||||
exit_reason: Optional[str] = None
|
exit_reason: Optional[str] = None
|
||||||
notes: Optional[str] = None
|
notes: Optional[str] = None
|
||||||
position_id: Optional[str] = None # New field to group related orders
|
position_id: Optional[str] = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def expected_profit_loss(self) -> float:
|
def expected_profit_loss(self) -> Optional[float]:
|
||||||
return (self.target_price - self.entry_price) * self.shares
|
if self.direction == 'buy' and self.target_price:
|
||||||
|
return (self.target_price - self.entry_price) * self.shares
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_loss(self) -> float:
|
def max_loss(self) -> Optional[float]:
|
||||||
return (self.stop_loss - self.entry_price) * self.shares
|
if self.direction == 'buy' and self.stop_loss:
|
||||||
|
return (self.stop_loss - self.entry_price) * self.shares
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def actual_profit_loss(self) -> Optional[float]:
|
def actual_profit_loss(self) -> Optional[float]:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user