data-xexe/xexe/currency_pair.py

31 lines
868 B
Python
Raw Normal View History

2025-05-26 14:50:21 +02:00
from money.currency import Currency
class CurrencyPair:
"""Two currencies with directionality (from->to)."""
def __init__(
self, from_currency: Currency, to_currency: Currency
) -> "CurrencyPair":
self.from_currency = from_currency
self.to_currency = to_currency
def get_reverse_pair(self) -> "CurrencyPair":
return CurrencyPair(
from_currency=self.to_currency, to_currency=self.from_currency
)
2025-05-26 15:03:08 +02:00
def __str__(self):
return str(self.from_currency) + str(self.to_currency)
def __eq__(self, other: "CurrencyPair") -> bool:
return (self.from_currency == other.from_currency) and (
self.to_currency == other.to_currency
)
2025-05-26 15:14:01 +02:00
def __repr__(self):
return str(self)
def __hash__(self):
return hash((self.from_currency, self.to_currency))