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.

57 lines
1.2 KiB

"""Some orders on the market."""
from dataclasses import dataclass
from .interfaces import Order
@dataclass
class Long(Order):
"""Buy stock."""
10 months ago
stock: str
amount: float
price: float
10 months ago
@property
def amount_usd(self) -> float:
"""The amount in $"""
return self.amount * self.price
9 months ago
def __str__(self) -> str:
10 months ago
return f"{self.__class__.__name__}({self.stock}: {self.amount_usd}$)"
9 months ago
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."""
10 months ago
stock: str
amount: float
price: float
10 months ago
@property
def amount_usd(self) -> float:
"""The amount in $"""
return self.amount * self.price
10 months ago
9 months ago
def __str__(self) -> str:
10 months ago
return f"{self.__class__.__name__}({self.stock}: {self.amount_usd}$)"
9 months ago
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
)