You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

56 lines
1.2 KiB

"""Some orders on the market."""
from dataclasses import dataclass
from .interfaces import Order
@dataclass
class Long(Order):
"""Buy stock."""
stock: str
amount: float
price: float
@property
def amount_usd(self) -> float:
"""The amount in $"""
return self.amount * self.price
def __str__(self) -> str:
return f"{self.__class__.__name__}({self.stock}: {self.amount_usd}$)"
def __eq__(self, other) -> bool:
if not isinstance(other, Long):
return False
return (
self.stock == other.stock
and self.amount == other.amount
and self.price == other.price
)
@dataclass
class Short(Order):
"""Buy stock."""
stock: str
amount: float
price: float
@property
def amount_usd(self) -> float:
"""The amount in $"""
return self.amount * self.price
def __str__(self) -> str:
return f"{self.__class__.__name__}({self.stock}: {self.amount_usd}$)"
def __eq__(self, other) -> bool:
if not isinstance(other, Short):
return False
return (
self.stock == other.stock
and self.amount == other.amount
and self.price == other.price
)